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/minimodel.hh>
00035
00036 #include "test/int.hh"
00037
00038 namespace Test { namespace Int {
00039
00041 namespace Dom {
00042
00048
00049 class DomInt : public Test {
00050 public:
00052 DomInt(int n)
00053 : Test("Dom::Int::"+str(n),n,-4,4,n == 1,
00054 Gecode::IPL_DOM) {}
00056 virtual bool solution(const Assignment& x) const {
00057 for (int i=x.size(); i--; )
00058 if (x[i] != -2)
00059 return false;
00060 return true;
00061 }
00063 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00064 if (x.size() == 1)
00065 Gecode::dom(home, x[0], -2);
00066 else
00067 Gecode::dom(home, x, -2);
00068 }
00070 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00071 Gecode::Reify r) {
00072 assert(x.size() == 1);
00073 if (Base::rand(2) != 0) {
00074 Gecode::dom(home, x[0], -2, r);
00075 } else {
00076 switch (r.mode()) {
00077 case Gecode::RM_EQV:
00078 Gecode::rel(home, Gecode::dom(x[0], -2) == r.var()); break;
00079 case Gecode::RM_IMP:
00080 Gecode::rel(home, Gecode::dom(x[0], -2) << r.var()); break;
00081 case Gecode::RM_PMI:
00082 Gecode::rel(home, Gecode::dom(x[0], -2) >> r.var()); break;
00083 default: GECODE_NEVER;
00084 }
00085 }
00086 }
00087 };
00088
00089
00091 class DomRange : public Test {
00092 public:
00094 DomRange(int n)
00095 : Test("Dom::Range::"+str(n),n,-4,4,n == 1,
00096 Gecode::IPL_DOM) {}
00098 virtual bool solution(const Assignment& x) const {
00099 for (int i=x.size(); i--; )
00100 if ((x[i] < -2) || (x[i] > 2))
00101 return false;
00102 return true;
00103 }
00105 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00106 if (x.size() == 1)
00107 Gecode::dom(home, x[0], -2, 2);
00108 else
00109 Gecode::dom(home, x, -2, 2);
00110 }
00112 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00113 Gecode::Reify r) {
00114 assert(x.size() == 1);
00115 if (Base::rand(2) != 0) {
00116 Gecode::dom(home, x[0], -2, 2, r);
00117 } else {
00118 switch (r.mode()) {
00119 case Gecode::RM_EQV:
00120 Gecode::rel(home, Gecode::dom(x[0], -2, 2) == r.var()); break;
00121 case Gecode::RM_IMP:
00122 Gecode::rel(home, Gecode::dom(x[0], -2, 2) << r.var()); break;
00123 case Gecode::RM_PMI:
00124 Gecode::rel(home, Gecode::dom(x[0], -2, 2) >> r.var()); break;
00125 default: GECODE_NEVER;
00126 }
00127 }
00128 }
00129 };
00130
00132 class DomRangeEmpty : public Test {
00133 public:
00135 DomRangeEmpty(void) : Test("Dom::Range::Empty",1,-4,4,true) {}
00137 virtual bool solution(const Assignment&) const {
00138 return false;
00139 }
00141 virtual void post(Gecode::Space& home, Gecode::IntVarArray&) {
00142 home.fail();
00143 }
00145 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00146 Gecode::Reify r) {
00147 Gecode::dom(home, x[0], 3, 2, r);
00148 }
00149 };
00150
00151
00152 const int r[4][2] = {
00153 {-4,-3},{-1,-1},{1,1},{3,5}
00154 };
00155 Gecode::IntSet d(r,4);
00156
00158 class DomDom : public Test {
00159 public:
00161 DomDom(int n)
00162 : Test("Dom::Dom::"+str(n),n,-6,6,n == 1,
00163 Gecode::IPL_DOM) {}
00165 virtual bool solution(const Assignment& x) const {
00166 for (int i=x.size(); i--; )
00167 if (!(((x[i] >= -4) && (x[i] <= -3)) ||
00168 ((x[i] >= -1) && (x[i] <= -1)) ||
00169 ((x[i] >= 1) && (x[i] <= 1)) ||
00170 ((x[i] >= 3) && (x[i] <= 5))))
00171 return false;
00172 return true;
00173 }
00175 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00176 if (x.size() == 1)
00177 Gecode::dom(home, x[0], d);
00178 else
00179 Gecode::dom(home, x, d);
00180 }
00182 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00183 Gecode::Reify r) {
00184 assert(x.size() == 1);
00185 if (Base::rand(2) != 0) {
00186 Gecode::dom(home, x[0], d, r);
00187 } else {
00188 switch (r.mode()) {
00189 case Gecode::RM_EQV:
00190 Gecode::rel(home, Gecode::dom(x[0], d) == r.var()); break;
00191 case Gecode::RM_IMP:
00192 Gecode::rel(home, Gecode::dom(x[0], d) << r.var()); break;
00193 case Gecode::RM_PMI:
00194 Gecode::rel(home, Gecode::dom(x[0], d) >> r.var()); break;
00195 default: GECODE_NEVER;
00196 }
00197 }
00198 }
00199 };
00200
00201 DomInt di1(1);
00202 DomInt di3(3);
00203 DomRange dr1(1);
00204 DomRange dr3(3);
00205 DomDom dd1(1);
00206 DomDom dd3(3);
00207 DomRangeEmpty dre;
00209
00210 }
00211 }}
00212
00213
00214