sequence.cc
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.size() > 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.size() > 0) {
00098 int oldMax = max;
00099 max = xi.max();
00100 if (xi.min() <= oldMax)
00101 return false;
00102 }
00103 }
00104 GECODE_AUTOARRAY(CountableSetRanges, isrs, n);
00105 for (int i=n; i--; )
00106 isrs[i].init(x.lub, x[i]);
00107 Iter::Ranges::NaryUnion<CountableSetRanges> u(isrs, n);
00108 CountableSetRanges xnr(x.lub, x[n]);
00109 return Iter::Ranges::equal(u, xnr);
00110 }
00112 virtual void post(Space* home, SetVarArray& x, IntVarArray&) {
00113 SetVarArgs xs(x.size()-1);
00114 for (int i=x.size()-1; i--;)
00115 xs[i]=x[i];
00116 Gecode::sequentialUnion(home, xs, x[x.size()-1]);
00117 }
00118 };
00119 SeqU _sequ0(0);
00120 SeqU _sequ1(1);
00121 SeqU _sequ3(3);
00122
00123 }}}
00124
00125