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