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 switch (r) {
00144 case IRT_EQ:
00145 {
00146 ViewArray<BoolView> xv(home,x);
00147 GECODE_ES_FAIL(home,Linear::EqBoolInt<BoolView>::post(home,xv,c));
00148 break;
00149 }
00150 case IRT_NQ:
00151 {
00152 ViewArray<BoolView> xv(home,x);
00153 GECODE_ES_FAIL(home,Linear::NqBoolInt<BoolView>::post(home,xv,c));
00154 break;
00155 }
00156 case IRT_GQ:
00157 {
00158 ViewArray<BoolView> xv(home,x);
00159 GECODE_ES_FAIL(home,Linear::GqBoolInt<BoolView>::post(home,xv,c));
00160 break;
00161 }
00162 case IRT_GR:
00163 {
00164 ViewArray<BoolView> xv(home,x);
00165 GECODE_ES_FAIL(home,Linear::GqBoolInt<BoolView>::post(home,xv,c+1));
00166 break;
00167 }
00168 case IRT_LQ:
00169 {
00170 ViewArray<NegBoolView> xv(home,x.size());
00171 for (int i=x.size(); i--; ) {
00172 BoolView y(x[i]); xv[i] = y;
00173 }
00174 GECODE_ES_FAIL(home,Linear::GqBoolInt<NegBoolView>
00175 ::post(home,xv,x.size()-c));
00176 break;
00177 }
00178 case IRT_LE:
00179 {
00180 ViewArray<NegBoolView> xv(home,x.size());
00181 for (int i=x.size(); i--; ) {
00182 BoolView y(x[i]); xv[i] = y;
00183 }
00184 GECODE_ES_FAIL(home,Linear::GqBoolInt<NegBoolView>
00185 ::post(home,xv,x.size()-c+1));
00186 break;
00187 }
00188 default:
00189 throw UnknownRelation("Int::linear");
00190 }
00191 }
00192
00193 void
00194 linear(Space* home, const BoolVarArgs& x, IntRelType r, IntVar y,
00195 IntConLevel) {
00196 if (home->failed()) return;
00197 ViewArray<BoolView> xv(home,x);
00198 switch (r) {
00199 case IRT_EQ:
00200 GECODE_ES_FAIL(home,(Linear::EqBoolView<BoolView,IntView>
00201 ::post(home,xv,y,0)));
00202 break;
00203 case IRT_NQ:
00204 GECODE_ES_FAIL(home,(Linear::NqBoolView<BoolView,IntView>
00205 ::post(home,xv,y,0)));
00206 break;
00207 case IRT_LQ:
00208 {
00209 int n = x.size();
00210 ViewArray<NegBoolView> xv(home,n);
00211 for (int i=n; i--; ) {
00212 BoolView y(x[i]); xv[i]=y;
00213 }
00214 MinusView my(y);
00215 GECODE_ES_FAIL(home,(Linear::GqBoolView<NegBoolView,MinusView>
00216 ::post(home,xv,my,n)));
00217 break;
00218 }
00219 case IRT_LE:
00220 {
00221 int n = x.size();
00222 ViewArray<NegBoolView> xv(home,n);
00223 for (int i=n; i--; ) {
00224 BoolView y(x[i]); xv[i]=y;
00225 }
00226 MinusView my(y);
00227 GECODE_ES_FAIL(home,(Linear::GqBoolView<NegBoolView,MinusView>
00228 ::post(home,xv,my,n+1)));
00229 break;
00230 }
00231 case IRT_GQ:
00232 GECODE_ES_FAIL(home,(Linear::GqBoolView<BoolView,IntView>
00233 ::post(home,xv,y,0)));
00234 break;
00235 case IRT_GR:
00236 GECODE_ES_FAIL(home,(Linear::GqBoolView<BoolView,IntView>
00237 ::post(home,xv,y,1)));
00238 break;
00239 default:
00240 throw UnknownRelation("Int::linear");
00241 }
00242 }
00243
00244 }
00245
00246
00247