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 #ifndef __GECODE_TEST_INT_HH__
00037 #define __GECODE_TEST_INT_HH__
00038
00039 #include "test/test.hh"
00040
00041 #include <gecode/int.hh>
00042
00043 namespace Test {
00044
00046 namespace Int {
00047
00058
00059 class Assignment {
00060 protected:
00061 int n;
00062 Gecode::IntSet d;
00063 public:
00065 Assignment(int n0, const Gecode::IntSet& d0);
00067 virtual bool operator()(void) const = 0;
00069 virtual void operator++(void) = 0;
00071 virtual int operator[](int i) const = 0;
00073 int size(void) const;
00075 virtual ~Assignment(void);
00076 };
00077
00079 class CpltAssignment : public Assignment {
00080 protected:
00081 Gecode::IntSetValues* dsv;
00082 public:
00084 CpltAssignment(int n, const Gecode::IntSet& d);
00086 virtual bool operator()(void) const;
00088 virtual void operator++(void);
00090 virtual int operator[](int i) const;
00092 virtual ~CpltAssignment(void);
00093 };
00094
00096 class RandomAssignment : public Assignment {
00097 protected:
00098 int* vals;
00099 int a;
00100
00101 int randval(void);
00102 public:
00104 RandomAssignment(int n, const Gecode::IntSet& d, int a);
00106 virtual bool operator()(void) const;
00108 virtual void operator++(void);
00110 virtual int operator[](int i) const;
00112 virtual ~RandomAssignment(void);
00113 };
00114
00116 class RandomMixAssignment : public Assignment {
00117 protected:
00118 int* vals;
00119 int a;
00120 int _n1;
00121 Gecode::IntSet _d1;
00122
00123 int randval(const Gecode::IntSet& d);
00124 public:
00126 RandomMixAssignment(int n0, const Gecode::IntSet& d0,
00127 int n1, const Gecode::IntSet& d1, int a0);
00129 virtual bool operator()(void) const;
00131 virtual void operator++(void);
00133 virtual int operator[](int i) const;
00135 virtual ~RandomMixAssignment(void);
00136 };
00137
00139 enum ConTestLevel {
00140 CTL_NONE,
00141 CTL_DOMAIN,
00142 CTL_BOUNDS_D,
00143 CTL_BOUNDS_Z,
00144 };
00145
00146 class Test;
00147
00149 class TestSpace : public Gecode::Space {
00150 public:
00152 Gecode::IntSet d;
00154 Gecode::IntVarArray x;
00156 Gecode::Reify r;
00158 Test* test;
00160 bool reified;
00161
00168 TestSpace(int n, Gecode::IntSet& d, Test* t);
00176 TestSpace(int n, Gecode::IntSet& d, Test* t, Gecode::ReifyMode rm);
00178 TestSpace(TestSpace& s);
00180 virtual Gecode::Space* copy(void);
00182 bool assigned(void) const;
00184 void post(void);
00186 bool failed(void);
00188 int rndvar(void);
00190 void rndrel(const Assignment& a, int i, Gecode::IntRelType& irt, int& v);
00192 void rel(int i, Gecode::IntRelType irt, int n);
00194 void rel(bool sol);
00196 void assign(const Assignment& a, bool skip=false);
00198 void bound(void);
00204 void prune(int i, bool bounds_only);
00206 void prune(void);
00208 bool prune(const Assignment& a, bool testfix);
00210 void disable(void);
00212 void enable(void);
00214 bool disabled(const Assignment& a, TestSpace& c, bool testfix);
00216 unsigned int propagators(void);
00217 };
00218
00223 class Test : public Base {
00224 protected:
00226 int arity;
00228 Gecode::IntSet dom;
00230 bool reified;
00232 int rms;
00234 Gecode::IntPropLevel ipl;
00236 ConTestLevel contest;
00238 bool testsearch;
00240 bool testfix;
00242
00243
00244 bool eqv(void) const;
00246 bool imp(void) const;
00248 bool pmi(void) const;
00250 public:
00259 Test(const std::string& p, const std::string& s,
00260 int a, const Gecode::IntSet& d, bool r=false,
00261 Gecode::IntPropLevel i=Gecode::IPL_DEF);
00270 Test(const std::string& s,
00271 int a, const Gecode::IntSet& d, bool r=false,
00272 Gecode::IntPropLevel i=Gecode::IPL_DEF);
00281 Test(const std::string& p, const std::string& s,
00282 int a, int min, int max, bool r=false,
00283 Gecode::IntPropLevel i=Gecode::IPL_DEF);
00292 Test(const std::string& s,
00293 int a, int min, int max, bool r=false,
00294 Gecode::IntPropLevel i=Gecode::IPL_DEF);
00296 virtual Assignment* assignment(void) const;
00298 virtual bool solution(const Assignment&) const = 0;
00300 virtual bool ignore(const Assignment&) const;
00302 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) = 0;
00304 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00305 Gecode::Reify r);
00307 virtual bool run(void);
00309
00310
00311 static std::string str(Gecode::IntPropLevel ipl);
00313 static std::string str(Gecode::IntRelType irl);
00315 static std::string str(Gecode::BoolOpType bot);
00317 static std::string str(bool b);
00319 static std::string str(int i);
00321 static std::string str(const Gecode::IntArgs& i);
00323
00324
00325
00326 template<class T> static bool cmp(T x, Gecode::IntRelType r, T y);
00328 };
00330
00332 class IntPropLevels {
00333 private:
00335 static const Gecode::IntPropLevel ipls[3];
00337 int i;
00338 public:
00340 IntPropLevels(void);
00342 bool operator()(void) const;
00344 void operator++(void);
00346 Gecode::IntPropLevel ipl(void) const;
00347 };
00348
00350 class IntPropBasicAdvanced {
00351 private:
00353 static const Gecode::IntPropLevel ipls[3];
00355 int i;
00356 public:
00358 IntPropBasicAdvanced(void);
00360 bool operator()(void) const;
00362 void operator++(void);
00364 Gecode::IntPropLevel ipl(void) const;
00365 };
00366
00368 class IntRelTypes {
00369 private:
00371 static const Gecode::IntRelType irts[6];
00373 int i;
00374 public:
00376 IntRelTypes(void);
00378 void reset(void);
00380 bool operator()(void) const;
00382 void operator++(void);
00384 Gecode::IntRelType irt(void) const;
00385 };
00386
00388 class BoolOpTypes {
00389 private:
00391 static const Gecode::BoolOpType bots[5];
00393 int i;
00394 public:
00396 BoolOpTypes(void);
00398 bool operator()(void) const;
00400 void operator++(void);
00402 Gecode::BoolOpType bot(void) const;
00403 };
00404
00405 }
00406 }
00407
00412 std::ostream& operator<<(std::ostream& os, const Test::Int::Assignment& a);
00413
00414 #include "test/int.hpp"
00415
00416 #endif
00417
00418
00419