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 #include "test/set.hh"
00035
00036 using namespace Gecode;
00037
00038 namespace Test { namespace Set {
00039
00041 namespace Sequence {
00042
00048
00049 static IntSet ds_33(-1,2);
00050
00052 class Sequence : public SetTest {
00053 public:
00055 Sequence(const char* t)
00056 : SetTest(t,4,ds_33,false) {}
00058 virtual bool solution(const SetAssignment& x) const {
00059 int max = Gecode::Set::Limits::min - 1;
00060 for (int i=0; i<4; i++) {
00061 CountableSetRanges xir(x.lub, x[i]);
00062 IntSet xi(xir);
00063 if (xi.ranges() > 0) {
00064 int oldMax = max;
00065 max = xi.max();
00066 if (xi.min() <= oldMax)
00067 return false;
00068 }
00069 }
00070 return true;
00071 }
00073 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00074 Gecode::sequence(home, x);
00075 }
00076 };
00077 Sequence _sequence("Sequence::Sequence");
00078
00080 class SeqU : public SetTest {
00081 private:
00082 int n;
00083 public:
00085 SeqU(int n0)
00086 : SetTest("Sequence::SeqU"+str(n0),n0+1,ds_33,false), n(n0) {}
00088 virtual bool solution(const SetAssignment& x) const {
00089 int max = Gecode::Set::Limits::min - 1;
00090 for (int i=0; i<n; i++) {
00091 CountableSetRanges xir(x.lub, x[i]);
00092 IntSet xi(xir);
00093 if (xi.ranges() > 0) {
00094 int oldMax = max;
00095 max = xi.max();
00096 if (xi.min() <= oldMax)
00097 return false;
00098 }
00099 }
00100 CountableSetRanges* isrs = new CountableSetRanges[n];
00101 for (int i=n; i--; )
00102 isrs[i].init(x.lub, x[i]);
00103 bool ret;
00104 {
00105 Region r;
00106 Iter::Ranges::NaryUnion u(r, isrs, n);
00107 CountableSetRanges xnr(x.lub, x[n]);
00108 ret = Iter::Ranges::equal(u, xnr);
00109 }
00110 delete[] isrs;
00111 return ret;
00112 }
00114 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00115 SetVarArgs xs(x.size()-1);
00116 for (int i=x.size()-1; i--;)
00117 xs[i]=x[i];
00118 Gecode::sequence(home, xs, x[x.size()-1]);
00119 }
00120 };
00121 SeqU _sequ0(0);
00122 SeqU _sequ1(1);
00123 SeqU _sequ3(3);
00124
00125 }}}
00126
00127