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
00039
00040 #include "test/set.hh"
00041
00042 using namespace Gecode;
00043
00044 namespace Test { namespace Set {
00045
00047 namespace Precede {
00048
00049 static IntSet ds(-1,3);
00050
00052 class Single : public SetTest {
00053 private:
00055 int s, t;
00056
00058 bool in(int i, int x) const {
00059 CountableSetRanges xr(ds,x);
00060 Iter::Ranges::Singleton ir(i,i);
00061 return Iter::Ranges::subset(ir,xr);
00062 }
00063
00064 public:
00066 Single(int s0, int t0)
00067 : SetTest("Precede::Single::"+str(s0)+"<"+str(t0),4,ds,false),
00068 s(s0), t(t0) {}
00070 virtual bool solution(const SetAssignment& x) const {
00071 int n = x.size();
00072 for (int i = 0 ; i < n ; i++) {
00073 if (!in(s,x[i]) && in(t,x[i]))
00074 return false;
00075 if (in(s,x[i]) && !in(t,x[i]))
00076 return true;
00077 }
00078 return true;
00079 }
00081 virtual void post(Gecode::Space& home, Gecode::SetVarArray& x,
00082 Gecode::IntVarArray&) {
00083 Gecode::precede(home, x, s, t);
00084 }
00085 };
00086
00088 class Multi : public SetTest {
00089 private:
00091 Gecode::IntArgs c;
00092
00094 bool in(int i, int x) const {
00095 CountableSetRanges xr(ds,x);
00096 Iter::Ranges::Singleton ir(i,i);
00097 return Iter::Ranges::subset(ir,xr);
00098 }
00099 public:
00101 Multi(const Gecode::IntArgs& c0)
00102 : SetTest("Precede::Multi::"+str(c0),4,ds,false), c(c0) {}
00104 virtual bool solution(const SetAssignment& x) const {
00105 for (int j=0; j<c.size()-1; j++)
00106 for (int i=0; i<x.size(); i++) {
00107 if (!in(c[j],x[i]) && in(c[j+1],x[i]))
00108 return false;
00109 if (in(c[j],x[i]) && !in(c[j+1],x[i]))
00110 break;
00111 }
00112 return true;
00113 }
00115 virtual void post(Gecode::Space& home, Gecode::SetVarArray& x,
00116 Gecode::IntVarArray&) {
00117 Gecode::precede(home, x, c);
00118 }
00119 };
00120
00121 Single _a(2, 3);
00122 Single _b(0, 3);
00123
00124 Multi _c(Gecode::IntArgs({1,2,3}));
00125 Multi _d(Gecode::IntArgs({3,2,1}));
00126 Multi _e(Gecode::IntArgs({4,2,3,1}));
00127
00128 }
00129
00130 }}
00131
00132