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