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 "test/int.hh"
00039
00040 namespace Test { namespace Int {
00041
00043 namespace Dom {
00044
00050
00051 class DomInt : public Test {
00052 public:
00054 DomInt(int n)
00055 : Test("Dom::Int::"+str(n),n,-4,4,n == 1,
00056 Gecode::IPL_DOM) {}
00058 virtual bool solution(const Assignment& x) const {
00059 for (int i=x.size(); i--; )
00060 if (x[i] != -2)
00061 return false;
00062 return true;
00063 }
00065 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00066 if (x.size() == 1)
00067 Gecode::dom(home, x[0], -2);
00068 else
00069 Gecode::dom(home, x, -2);
00070 }
00072 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00073 Gecode::Reify r) {
00074 assert(x.size() == 1);
00075 Gecode::dom(home, x[0], -2, r);
00076 }
00077 };
00078
00079
00081 class DomRange : public Test {
00082 public:
00084 DomRange(int n)
00085 : Test("Dom::Range::"+str(n),n,-4,4,n == 1,
00086 Gecode::IPL_DOM) {}
00088 virtual bool solution(const Assignment& x) const {
00089 for (int i=x.size(); i--; )
00090 if ((x[i] < -2) || (x[i] > 2))
00091 return false;
00092 return true;
00093 }
00095 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00096 if (x.size() == 1)
00097 Gecode::dom(home, x[0], -2, 2);
00098 else
00099 Gecode::dom(home, x, -2, 2);
00100 }
00102 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00103 Gecode::Reify r) {
00104 assert(x.size() == 1);
00105 Gecode::dom(home, x[0], -2, 2, r);
00106 }
00107 };
00108
00110 class DomRangeEmpty : public Test {
00111 public:
00113 DomRangeEmpty(void) : Test("Dom::Range::Empty",1,-4,4,true) {}
00115 virtual bool solution(const Assignment&) const {
00116 return false;
00117 }
00119 virtual void post(Gecode::Space& home, Gecode::IntVarArray&) {
00120 home.fail();
00121 }
00123 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00124 Gecode::Reify r) {
00125 Gecode::dom(home, x[0], 3, 2, r);
00126 }
00127 };
00128
00129
00130 const int r[4][2] = {
00131 {-4,-3},{-1,-1},{1,1},{3,5}
00132 };
00133 Gecode::IntSet d(r,4);
00134
00136 class DomDom : public Test {
00137 public:
00139 DomDom(int n)
00140 : Test("Dom::Dom::"+str(n),n,-6,6,n == 1,
00141 Gecode::IPL_DOM) {}
00143 virtual bool solution(const Assignment& x) const {
00144 for (int i=x.size(); i--; )
00145 if (!(((x[i] >= -4) && (x[i] <= -3)) ||
00146 ((x[i] >= -1) && (x[i] <= -1)) ||
00147 ((x[i] >= 1) && (x[i] <= 1)) ||
00148 ((x[i] >= 3) && (x[i] <= 5))))
00149 return false;
00150 return true;
00151 }
00153 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00154 if (x.size() == 1)
00155 Gecode::dom(home, x[0], d);
00156 else
00157 Gecode::dom(home, x, d);
00158 }
00160 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00161 Gecode::Reify r) {
00162 assert(x.size() == 1);
00163 Gecode::dom(home, x[0], d, r);
00164 }
00165 };
00166
00167 DomInt di1(1);
00168 DomInt di3(3);
00169 DomRange dr1(1);
00170 DomRange dr3(3);
00171 DomDom dd1(1);
00172 DomDom dd3(3);
00173 DomRangeEmpty dre;
00175
00176 }
00177 }}
00178
00179
00180