set.hh
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
00039
00040 #ifndef __GECODE_TEST_SET_HH__
00041 #define __GECODE_TEST_SET_HH__
00042
00043 #include "gecode/set.hh"
00044 #include "test/test.hh"
00045 #include "test/int.hh"
00046
00047 namespace Test {
00048
00050 namespace Set {
00051
00062
00064 class CountableSetValues {
00065 private:
00066 Gecode::IntSetValues dv;
00067 int cur;
00068 int i;
00069 public:
00071 CountableSetValues(void) {}
00073 CountableSetValues(const Gecode::IntSet& d0, int cur0)
00074 : dv(d0), cur(cur0), i(1) {
00075 if (! (i & cur))
00076 operator++();
00077 }
00079 void init(const Gecode::IntSet& d0, int cur0) {
00080 dv = d0;
00081 cur = cur0;
00082 i = 1;
00083 if (! (i & cur))
00084 operator++();
00085 }
00087 bool operator()(void) const {
00088 return i<=cur;
00089 }
00091 void operator++(void) {
00092 do {
00093 ++dv;
00094 i = i<<1;
00095 } while (! (i & cur) && i<cur);
00096 }
00098 int val(void) const { return dv.val(); }
00099 };
00100
00102 class CountableSetRanges
00103 : public Gecode::Iter::Values::ToRanges<CountableSetValues> {
00104 private:
00106 CountableSetValues v;
00107 public:
00109 CountableSetRanges(void) {}
00111 CountableSetRanges(const Gecode::IntSet& d, int cur) : v(d, cur) {
00112 Gecode::Iter::Values::ToRanges<CountableSetValues>::init(v);
00113 }
00115 void init(const Gecode::IntSet& d, int cur) {
00116 v.init(d, cur);
00117 Gecode::Iter::Values::ToRanges<CountableSetValues>::init(v);
00118 }
00119 };
00120
00122 class CountableSet {
00123 private:
00125 Gecode::IntSet d;
00127 unsigned int cur;
00129 unsigned int lubmax;
00130 public:
00132 CountableSet(const Gecode::IntSet& s);
00134 CountableSet(void) {}
00136 void init(const Gecode::IntSet& s);
00138 bool operator()(void) const { return cur<lubmax; }
00140 void operator++(void);
00142 int val(void) const;
00143 };
00144
00146 class SetAssignment {
00147 private:
00149 int n;
00151 CountableSet* dsv;
00153 Test::Int::CpltAssignment ir;
00155 bool done;
00156 public:
00158 Gecode::IntSet lub;
00160 int withInt;
00162 SetAssignment(int n, const Gecode::IntSet& d, int i = 0);
00164 bool operator()(void) const { return !done; }
00166 void operator++(void);
00168 int operator[](int i) const {
00169 assert((i>=0) && (i<n));
00170 return dsv[i].val();
00171 }
00173 int intval(void) const { return ir[0]; }
00175 const Test::Int::Assignment& ints(void) const { return ir; }
00177 int size(void) const { return n; }
00179 ~SetAssignment(void) { delete [] dsv; }
00180 };
00181
00186 class SetTest : public Base {
00187 private:
00189 int arity;
00191 Gecode::IntSet lub;
00193 bool reified;
00195 int withInt;
00196
00198 void removeFromLub(int v, Gecode::SetVar& x, int i,
00199 const Gecode::IntSet& a);
00201 void addToGlb(int v, Gecode::SetVar& x, int i, const Gecode::IntSet& a);
00202 SetAssignment* make_assignment(void);
00203 public:
00211 SetTest(const std::string& s,
00212 int a, const Gecode::IntSet& d, bool r=false, int w=0)
00213 : Base("Set::"+s), arity(a), lub(d), reified(r), withInt(w) {}
00215 virtual bool solution(const SetAssignment&) const = 0;
00217 virtual void post(Gecode::Space* home, Gecode::SetVarArray& x,
00218 Gecode::IntVarArray& y) = 0;
00220 virtual void post(Gecode::Space*, Gecode::SetVarArray&,
00221 Gecode::IntVarArray&, Gecode::BoolVar) {}
00223 virtual bool run(void);
00224
00226
00227
00228 static std::string str(Gecode::SetRelType srt);
00230 static std::string str(Gecode::SetOpType srt);
00232 static std::string str(int i);
00234 };
00236
00238 class SetRelTypes {
00239 private:
00241 static const Gecode::SetRelType srts[6];
00243 int i;
00244 public:
00246 SetRelTypes(void);
00248 bool operator()(void) const;
00250 void operator++(void);
00252 Gecode::SetRelType srt(void) const;
00253 };
00254
00256 class SetOpTypes {
00257 private:
00259 static const Gecode::SetOpType sots[4];
00261 int i;
00262 public:
00264 SetOpTypes(void);
00266 bool operator()(void) const;
00268 void operator++(void);
00270 Gecode::SetOpType sot(void) const;
00271 };
00272
00273 }}
00274
00279 std::ostream&
00280 operator<<(std::ostream&, const Test::Set::SetAssignment& a);
00281
00282 #include "test/set.icc"
00283
00284 #endif
00285
00286