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