00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gecode/int/linear.hh"
00023
00024 namespace Gecode {
00025
00026 using namespace Int;
00027
00028
00029
00030
00031
00032
00033 void
00034 linear(Space* home,
00035 const IntVarArgs& x, IntRelType r, int c, IntConLevel icl) {
00036 if (home->failed()) return;
00037 GECODE_AUTOARRAY(Linear::Term, t, x.size());
00038 for (int i = x.size(); i--; ) {
00039 t[i].a=1; t[i].x=x[i];
00040 }
00041 Linear::post(home,t,x.size(),r,c,icl);
00042 }
00043
00044 void
00045 linear(Space* home,
00046 const IntVarArgs& x, IntRelType r, int c, BoolVar b, IntConLevel icl) {
00047 if (home->failed()) return;
00048 GECODE_AUTOARRAY(Linear::Term, t, x.size());
00049 for (int i = x.size(); i--; ) {
00050 t[i].a=1; t[i].x=x[i];
00051 }
00052 Linear::post(home,t,x.size(),r,c,b);
00053 }
00054
00055 void
00056 linear(Space* home,
00057 const IntArgs& a, const IntVarArgs& x, IntRelType r, int c,
00058 IntConLevel icl) {
00059 if (a.size() != x.size())
00060 throw ArgumentSizeMismatch("Int::linear");
00061 if (home->failed()) return;
00062 GECODE_AUTOARRAY(Linear::Term, t, x.size());
00063 for (int i = x.size(); i--; ) {
00064 t[i].a=a[i]; t[i].x=x[i];
00065 }
00066 Linear::post(home,t,x.size(),r,c,icl);
00067 }
00068
00069 void
00070 linear(Space* home,
00071 const IntArgs& a, const IntVarArgs& x, IntRelType r, int c, BoolVar b,
00072 IntConLevel) {
00073 if (a.size() != x.size())
00074 throw ArgumentSizeMismatch("Int::linear");
00075 if (home->failed()) return;
00076 GECODE_AUTOARRAY(Linear::Term, t, x.size());
00077 for (int i = x.size(); i--; ) {
00078 t[i].a=a[i]; t[i].x=x[i];
00079 }
00080 Linear::post(home,t,x.size(),r,c,b);
00081 }
00082
00083 void
00084 linear(Space* home,
00085 const IntVarArgs& x, IntRelType r, IntVar y, IntConLevel icl) {
00086 if (home->failed()) return;
00087 GECODE_AUTOARRAY(Linear::Term, t, x.size()+1);
00088 for (int i = x.size(); i--; ) {
00089 t[i].a=1; t[i].x=x[i];
00090 }
00091 t[x.size()].a=-1; t[x.size()].x=y;
00092 Linear::post(home,t,x.size()+1,r,0,icl);
00093 }
00094
00095 void
00096 linear(Space* home,
00097 const IntVarArgs& x, IntRelType r, IntVar y, BoolVar b,
00098 IntConLevel) {
00099 if (home->failed()) return;
00100 GECODE_AUTOARRAY(Linear::Term, t, x.size()+1);
00101 for (int i = x.size(); i--; ) {
00102 t[i].a=1; t[i].x=x[i];
00103 }
00104 t[x.size()].a=-1; t[x.size()].x=y;
00105 Linear::post(home,t,x.size()+1,r,0,b);
00106 }
00107
00108 void
00109 linear(Space* home,
00110 const IntArgs& a, const IntVarArgs& x, IntRelType r, IntVar y,
00111 IntConLevel icl) {
00112 if (a.size() != x.size())
00113 throw ArgumentSizeMismatch("Int::linear");
00114 if (home->failed()) return;
00115 GECODE_AUTOARRAY(Linear::Term, t, x.size()+1);
00116 for (int i = x.size(); i--; ) {
00117 t[i].a=a[i]; t[i].x=x[i];
00118 }
00119 t[x.size()].a=-1; t[x.size()].x=y;
00120 Linear::post(home,t,x.size()+1,r,0,icl);
00121 }
00122
00123 void
00124 linear(Space* home,
00125 const IntArgs& a, const IntVarArgs& x, IntRelType r, IntVar y,
00126 BoolVar b, IntConLevel) {
00127 if (a.size() != x.size())
00128 throw ArgumentSizeMismatch("Int::linear");
00129 if (home->failed()) return;
00130 GECODE_AUTOARRAY(Linear::Term, t, x.size()+1);
00131 for (int i = x.size(); i--; ) {
00132 t[i].a=a[i]; t[i].x=x[i];
00133 }
00134 t[x.size()].a=-1; t[x.size()].x=y;
00135 Linear::post(home,t,x.size()+1,r,0,b);
00136 }
00137
00138
00139 void
00140 linear(Space* home, const BoolVarArgs& x, IntRelType r, int c,
00141 IntConLevel) {
00142 if (home->failed()) return;
00143 ViewArray<BoolView> xv(home,x);
00144 ConstIntView cv(c);
00145 switch (r) {
00146 case IRT_EQ:
00147 GECODE_ES_FAIL(home,Linear::EqBool<ConstIntView>::post(home,xv,0,cv));
00148 break;
00149 case IRT_NQ:
00150 GECODE_ES_FAIL(home,Linear::NqBool<ConstIntView>::post(home,xv,0,cv));
00151 break;
00152 case IRT_LQ:
00153 GECODE_ES_FAIL(home,Linear::LqBool<ConstIntView>::post(home,xv,0,cv));
00154 break;
00155 case IRT_LE:
00156 GECODE_ES_FAIL(home,Linear::LqBool<ConstIntView>::post(home,xv,-1,cv));
00157 break;
00158 case IRT_GQ:
00159 GECODE_ES_FAIL(home,Linear::GqBool<ConstIntView>::post(home,xv,0,cv));
00160 break;
00161 case IRT_GR:
00162 GECODE_ES_FAIL(home,Linear::GqBool<ConstIntView>::post(home,xv,1,cv));
00163 break;
00164 default:
00165 throw UnknownRelation("Int::linear");
00166 }
00167 }
00168
00169 void
00170 linear(Space* home, const BoolVarArgs& x, IntRelType r, IntVar y,
00171 IntConLevel) {
00172 if (home->failed()) return;
00173 ViewArray<BoolView> xv(home,x);
00174 switch (r) {
00175 case IRT_EQ:
00176 GECODE_ES_FAIL(home,Linear::EqBool<IntView>::post(home,xv,0,y));
00177 break;
00178 case IRT_NQ:
00179 GECODE_ES_FAIL(home,Linear::NqBool<IntView>::post(home,xv,0,y));
00180 break;
00181 case IRT_LQ:
00182 GECODE_ES_FAIL(home,Linear::LqBool<IntView>::post(home,xv,0,y));
00183 break;
00184 case IRT_LE:
00185 GECODE_ES_FAIL(home,Linear::LqBool<IntView>::post(home,xv,-1,y));
00186 break;
00187 case IRT_GQ:
00188 GECODE_ES_FAIL(home,Linear::GqBool<IntView>::post(home,xv,0,y));
00189 break;
00190 case IRT_GR:
00191 GECODE_ES_FAIL(home,Linear::GqBool<IntView>::post(home,xv,1,y));
00192 break;
00193 default:
00194 throw UnknownRelation("Int::linear");
00195 }
00196 }
00197
00198 }
00199
00200
00201