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