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) : Test("Dom::Int::"+str(n),n,-4,4,n == 1) {}
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::BoolVar b) {
00072 assert(x.size() == 1);
00073 Gecode::dom(home, x[0], -2, b);
00074 }
00075 };
00076
00077
00079 class DomRange : public Test {
00080 public:
00082 DomRange(int n) : Test("Dom::Range::"+str(n),n,-4,4,n == 1) {}
00084 virtual bool solution(const Assignment& x) const {
00085 for (int i=x.size(); i--; )
00086 if ((x[i] < -2) || (x[i] > 2))
00087 return false;
00088 return true;
00089 }
00091 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00092 if (x.size() == 1)
00093 Gecode::dom(home, x[0], -2, 2);
00094 else
00095 Gecode::dom(home, x, -2, 2);
00096 }
00098 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00099 Gecode::BoolVar b) {
00100 assert(x.size() == 1);
00101 Gecode::dom(home, x[0], -2, 2, b);
00102 }
00103 };
00104
00105
00106 const int r[4][2] = {
00107 {-4,-3},{-1,-1},{1,1},{3,5}
00108 };
00109 Gecode::IntSet d(r,4);
00110
00112 class DomDom : public Test {
00113 public:
00115 DomDom(int n) : Test("Dom::Dom::"+str(n),n,-6,6,n == 1) {}
00117 virtual bool solution(const Assignment& x) const {
00118 for (int i=x.size(); i--; )
00119 if (!(((x[i] >= -4) && (x[i] <= -3)) ||
00120 ((x[i] >= -1) && (x[i] <= -1)) ||
00121 ((x[i] >= 1) && (x[i] <= 1)) ||
00122 ((x[i] >= 3) && (x[i] <= 5))))
00123 return false;
00124 return true;
00125 }
00127 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00128 if (x.size() == 1)
00129 Gecode::dom(home, x[0], d);
00130 else
00131 Gecode::dom(home, x, d);
00132 }
00134 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00135 Gecode::BoolVar b) {
00136 assert(x.size() == 1);
00137 Gecode::dom(home, x[0], d, b);
00138 }
00139 };
00140
00141 DomInt di1(1);
00142 DomInt di3(3);
00143 DomRange dr1(1);
00144 DomRange dr3(3);
00145 DomDom dd1(1);
00146 DomDom dd3(3);
00148
00149 }
00150 }}
00151
00152
00153