this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3o * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * Vincent Barichard <Vincent.Barichard@univ-angers.fr> 6 * 7 * Copyright: 8 * Christian Schulte, 2002 9 * Vincent Barichard, 2012 10 * 11 * This file is part of Gecode, the generic constraint 12 * development environment: 13 * http://www.gecode.org 14 * 15 * Permission is hereby granted, free of charge, to any person obtaining 16 * a copy of this software and associated documentation files (the 17 * "Software"), to deal in the Software without restriction, including 18 * without limitation the rights to use, copy, modify, merge, publish, 19 * distribute, sublicense, and/or sell copies of the Software, and to 20 * permit persons to whom the Software is furnished to do so, subject to 21 * the following conditions: 22 * 23 * The above copyright notice and this permission notice shall be 24 * included in all copies or substantial portions of the Software. 25 * 26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 * 34 */ 35 36#include <gecode/float/linear.hh> 37 38namespace Gecode { 39 40 void 41 linear(Home home, 42 const FloatVarArgs& x, FloatRelType frt, FloatVal c) { 43 using namespace Float; 44 GECODE_POST; 45 Region re; 46 Linear::Term* t = re.alloc<Linear::Term>(x.size()); 47 for (int i = x.size(); i--; ) { 48 t[i].a=1.0; t[i].x=x[i]; 49 } 50 Linear::post(home,t,x.size(),frt,c); 51 } 52 53 void 54 linear(Home home, 55 const FloatVarArgs& x, FloatRelType frt, FloatVal c, Reify r) { 56 using namespace Float; 57 GECODE_POST; 58 Region re; 59 Linear::Term* t = re.alloc<Linear::Term>(x.size()); 60 for (int i = x.size(); i--; ) { 61 t[i].a=1.0; t[i].x=x[i]; 62 } 63 Linear::post(home,t,x.size(),frt,c,r); 64 } 65 66 void 67 linear(Home home, 68 const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt, 69 FloatVal c) { 70 using namespace Float; 71 if (a.size() != x.size()) 72 throw ArgumentSizeMismatch("Float::linear"); 73 GECODE_POST; 74 Region re; 75 Linear::Term* t = re.alloc<Linear::Term>(x.size()); 76 for (int i = x.size(); i--; ) { 77 t[i].a=a[i]; t[i].x=x[i]; 78 } 79 Linear::post(home,t,x.size(),frt,c); 80 } 81 82 void 83 linear(Home home, 84 const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt, 85 FloatVal c, Reify r) { 86 using namespace Float; 87 if (a.size() != x.size()) 88 throw ArgumentSizeMismatch("Float::linear"); 89 GECODE_POST; 90 Region re; 91 Linear::Term* t = re.alloc<Linear::Term >(x.size()); 92 for (int i = x.size(); i--; ) { 93 t[i].a=a[i]; t[i].x=x[i]; 94 } 95 Linear::post(home,t,x.size(),frt,c,r); 96 } 97 98 void 99 linear(Home home, 100 const FloatVarArgs& x, FloatRelType frt, FloatVar y) { 101 using namespace Float; 102 GECODE_POST; 103 Region re; 104 Linear::Term* t = re.alloc<Linear::Term>(x.size()+1); 105 for (int i = x.size(); i--; ) { 106 t[i].a=1.0; t[i].x=x[i]; 107 } 108 FloatNum min, max; 109 estimate(t,x.size(),0.0,min,max); 110 FloatView v(y); 111 switch (frt) { 112 case FRT_EQ: 113 GECODE_ME_FAIL(v.gq(home,min)); GECODE_ME_FAIL(v.lq(home,max)); 114 break; 115 case FRT_GQ: case FRT_GR: 116 GECODE_ME_FAIL(v.lq(home,max)); 117 break; 118 case FRT_LQ: case FRT_LE: 119 GECODE_ME_FAIL(v.gq(home,min)); 120 break; 121 default: ; 122 } 123 if (home.failed()) return; 124 t[x.size()].a=-1.0; t[x.size()].x=y; 125 Linear::post(home,t,x.size()+1,frt,0.0); 126 } 127 128 void 129 linear(Home home, 130 const FloatVarArgs& x, FloatRelType frt, FloatVar y, Reify r) { 131 using namespace Float; 132 GECODE_POST; 133 Region re; 134 Linear::Term* t = re.alloc<Linear::Term>(x.size()+1); 135 for (int i = x.size(); i--; ) { 136 t[i].a=1.0; t[i].x=x[i]; 137 } 138 t[x.size()].a=-1; t[x.size()].x=y; 139 Linear::post(home,t,x.size()+1,frt,0.0,r); 140 } 141 142 void 143 linear(Home home, 144 const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt, 145 FloatVar y) { 146 using namespace Float; 147 if (a.size() != x.size()) 148 throw ArgumentSizeMismatch("Float::linear"); 149 GECODE_POST; 150 Region re; 151 Linear::Term* t = re.alloc<Linear::Term>(x.size()+1); 152 for (int i = x.size(); i--; ) { 153 t[i].a=a[i]; t[i].x=x[i]; 154 } 155 FloatNum min, max; 156 estimate(t,x.size(),0.0,min,max); 157 FloatView v(y); 158 switch (frt) { 159 case FRT_EQ: 160 GECODE_ME_FAIL(v.gq(home,min)); GECODE_ME_FAIL(v.lq(home,max)); 161 break; 162 case FRT_GQ: case FRT_GR: 163 GECODE_ME_FAIL(v.lq(home,max)); 164 break; 165 case FRT_LQ: case FRT_LE: 166 GECODE_ME_FAIL(v.gq(home,min)); 167 break; 168 default: ; 169 } 170 if (home.failed()) return; 171 t[x.size()].a=-1.0; t[x.size()].x=y; 172 Linear::post(home,t,x.size()+1,frt,0.0); 173 } 174 175 void 176 linear(Home home, 177 const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt, 178 FloatVar y, Reify r) { 179 using namespace Float; 180 if (a.size() != x.size()) 181 throw ArgumentSizeMismatch("Float::linear"); 182 GECODE_POST; 183 Region re; 184 Linear::Term* t = re.alloc<Linear::Term>(x.size()+1); 185 for (int i = x.size(); i--; ) { 186 t[i].a=a[i]; t[i].x=x[i]; 187 } 188 t[x.size()].a=-1.0; t[x.size()].x=y; 189 Linear::post(home,t,x.size()+1,frt,0.0,r); 190 } 191 192} 193 194// STATISTICS: float-post