00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <gecode/float/linear.hh>
00041
00042 namespace Gecode {
00043
00044 void
00045 linear(Home home,
00046 const FloatVarArgs& x, FloatRelType frt, FloatVal c) {
00047 using namespace Float;
00048 GECODE_POST;
00049 Region re(home);
00050 Linear::Term* t = re.alloc<Linear::Term>(x.size());
00051 for (int i = x.size(); i--; ) {
00052 t[i].a=1.0; t[i].x=x[i];
00053 }
00054 Linear::post(home,t,x.size(),frt,c);
00055 }
00056
00057 void
00058 linear(Home home,
00059 const FloatVarArgs& x, FloatRelType frt, FloatVal c, Reify r) {
00060 using namespace Float;
00061 GECODE_POST;
00062 Region re(home);
00063 Linear::Term* t = re.alloc<Linear::Term>(x.size());
00064 for (int i = x.size(); i--; ) {
00065 t[i].a=1.0; t[i].x=x[i];
00066 }
00067 Linear::post(home,t,x.size(),frt,c,r);
00068 }
00069
00070 void
00071 linear(Home home,
00072 const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt,
00073 FloatVal c) {
00074 using namespace Float;
00075 if (a.size() != x.size())
00076 throw ArgumentSizeMismatch("Float::linear");
00077 GECODE_POST;
00078 Region re(home);
00079 Linear::Term* t = re.alloc<Linear::Term>(x.size());
00080 for (int i = x.size(); i--; ) {
00081 t[i].a=a[i]; t[i].x=x[i];
00082 }
00083 Linear::post(home,t,x.size(),frt,c);
00084 }
00085
00086 void
00087 linear(Home home,
00088 const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt,
00089 FloatVal c, Reify r) {
00090 using namespace Float;
00091 if (a.size() != x.size())
00092 throw ArgumentSizeMismatch("Float::linear");
00093 GECODE_POST;
00094 Region re(home);
00095 Linear::Term* t = re.alloc<Linear::Term >(x.size());
00096 for (int i = x.size(); i--; ) {
00097 t[i].a=a[i]; t[i].x=x[i];
00098 }
00099 Linear::post(home,t,x.size(),frt,c,r);
00100 }
00101
00102 void
00103 linear(Home home,
00104 const FloatVarArgs& x, FloatRelType frt, FloatVar y) {
00105 using namespace Float;
00106 GECODE_POST;
00107 Region re(home);
00108 Linear::Term* t = re.alloc<Linear::Term>(x.size()+1);
00109 for (int i = x.size(); i--; ) {
00110 t[i].a=1.0; t[i].x=x[i];
00111 }
00112 FloatNum min, max;
00113 estimate(t,x.size(),0.0,min,max);
00114 FloatView v(y);
00115 switch (frt) {
00116 case FRT_EQ:
00117 GECODE_ME_FAIL(v.gq(home,min)); GECODE_ME_FAIL(v.lq(home,max));
00118 break;
00119 case FRT_GQ: case FRT_GR:
00120 GECODE_ME_FAIL(v.lq(home,max));
00121 break;
00122 case FRT_LQ: case FRT_LE:
00123 GECODE_ME_FAIL(v.gq(home,min));
00124 break;
00125 default: ;
00126 }
00127 if (home.failed()) return;
00128 t[x.size()].a=-1.0; t[x.size()].x=y;
00129 Linear::post(home,t,x.size()+1,frt,0.0);
00130 }
00131
00132 void
00133 linear(Home home,
00134 const FloatVarArgs& x, FloatRelType frt, FloatVar y, Reify r) {
00135 using namespace Float;
00136 GECODE_POST;
00137 Region re(home);
00138 Linear::Term* t = re.alloc<Linear::Term>(x.size()+1);
00139 for (int i = x.size(); i--; ) {
00140 t[i].a=1.0; t[i].x=x[i];
00141 }
00142 t[x.size()].a=-1; t[x.size()].x=y;
00143 Linear::post(home,t,x.size()+1,frt,0.0,r);
00144 }
00145
00146 void
00147 linear(Home home,
00148 const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt,
00149 FloatVar y) {
00150 using namespace Float;
00151 if (a.size() != x.size())
00152 throw ArgumentSizeMismatch("Float::linear");
00153 GECODE_POST;
00154 Region re(home);
00155 Linear::Term* t = re.alloc<Linear::Term>(x.size()+1);
00156 for (int i = x.size(); i--; ) {
00157 t[i].a=a[i]; t[i].x=x[i];
00158 }
00159 FloatNum min, max;
00160 estimate(t,x.size(),0.0,min,max);
00161 FloatView v(y);
00162 switch (frt) {
00163 case FRT_EQ:
00164 GECODE_ME_FAIL(v.gq(home,min)); GECODE_ME_FAIL(v.lq(home,max));
00165 break;
00166 case FRT_GQ: case FRT_GR:
00167 GECODE_ME_FAIL(v.lq(home,max));
00168 break;
00169 case FRT_LQ: case FRT_LE:
00170 GECODE_ME_FAIL(v.gq(home,min));
00171 break;
00172 default: ;
00173 }
00174 if (home.failed()) return;
00175 t[x.size()].a=-1.0; t[x.size()].x=y;
00176 Linear::post(home,t,x.size()+1,frt,0.0);
00177 }
00178
00179 void
00180 linear(Home home,
00181 const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt,
00182 FloatVar y, Reify r) {
00183 using namespace Float;
00184 if (a.size() != x.size())
00185 throw ArgumentSizeMismatch("Float::linear");
00186 GECODE_POST;
00187 Region re(home);
00188 Linear::Term* t = re.alloc<Linear::Term>(x.size()+1);
00189 for (int i = x.size(); i--; ) {
00190 t[i].a=a[i]; t[i].x=x[i];
00191 }
00192 t[x.size()].a=-1.0; t[x.size()].x=y;
00193 Linear::post(home,t,x.size()+1,frt,0.0,r);
00194 }
00195
00196 }
00197
00198