sequence.cpp
Go to the documentation of this file.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/set.hh"
00039
00040 using namespace Gecode;
00041
00042 namespace Test { namespace Set {
00043
00045 namespace Sequence {
00046
00052
00053 static IntSet ds_33(-1,2);
00054
00056 class Sequence : public SetTest {
00057 public:
00059 Sequence(const char* t)
00060 : SetTest(t,4,ds_33,false) {}
00062 virtual bool solution(const SetAssignment& x) const {
00063 int max = Gecode::Set::Limits::min - 1;
00064 for (int i=0; i<4; i++) {
00065 CountableSetRanges xir(x.lub, x[i]);
00066 IntSet xi(xir);
00067 if (xi.ranges() > 0) {
00068 int oldMax = max;
00069 max = xi.max();
00070 if (xi.min() <= oldMax)
00071 return false;
00072 }
00073 }
00074 return true;
00075 }
00077 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00078 Gecode::sequence(home, x);
00079 }
00080 };
00081 Sequence _sequence("Sequence::Sequence");
00082
00084 class SeqU : public SetTest {
00085 private:
00086 int n;
00087 public:
00089 SeqU(int n0)
00090 : SetTest("Sequence::SeqU"+str(n0),n0+1,ds_33,false), n(n0) {}
00092 virtual bool solution(const SetAssignment& x) const {
00093 int max = Gecode::Set::Limits::min - 1;
00094 for (int i=0; i<n; i++) {
00095 CountableSetRanges xir(x.lub, x[i]);
00096 IntSet xi(xir);
00097 if (xi.ranges() > 0) {
00098 int oldMax = max;
00099 max = xi.max();
00100 if (xi.min() <= oldMax)
00101 return false;
00102 }
00103 }
00104 CountableSetRanges* isrs = new CountableSetRanges[n];
00105 for (int i=n; i--; )
00106 isrs[i].init(x.lub, x[i]);
00107 FakeSpace* fs = new FakeSpace;
00108 bool ret;
00109 {
00110 Region r(*fs);
00111 Iter::Ranges::NaryUnion u(r, isrs, n);
00112 CountableSetRanges xnr(x.lub, x[n]);
00113 ret = Iter::Ranges::equal(u, xnr);
00114 }
00115 delete[] isrs;
00116 delete fs;
00117 return ret;
00118 }
00120 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00121 SetVarArgs xs(x.size()-1);
00122 for (int i=x.size()-1; i--;)
00123 xs[i]=x[i];
00124 Gecode::sequence(home, xs, x[x.size()-1]);
00125 }
00126 };
00127 SeqU _sequ0(0);
00128 SeqU _sequ1(1);
00129 SeqU _sequ3(3);
00130
00131 }}}
00132
00133