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_INT_HH__
00041 #define __GECODE_TEST_INT_HH__
00042
00043 #include "test/test.hh"
00044
00045 #include <gecode/int.hh>
00046
00047 namespace Test {
00048
00050 namespace Int {
00051
00062
00063 class Assignment {
00064 protected:
00065 int n;
00066 Gecode::IntSet d;
00067 public:
00069 Assignment(int n0, const Gecode::IntSet& d0);
00071 virtual bool operator()(void) const = 0;
00073 virtual void operator++(void) = 0;
00075 virtual int operator[](int i) const = 0;
00077 int size(void) const;
00079 virtual ~Assignment(void);
00080 };
00081
00083 class CpltAssignment : public Assignment {
00084 protected:
00085 Gecode::IntSetValues* dsv;
00086 public:
00088 CpltAssignment(int n, const Gecode::IntSet& d);
00090 virtual bool operator()(void) const;
00092 virtual void operator++(void);
00094 virtual int operator[](int i) const;
00096 virtual ~CpltAssignment(void);
00097 };
00098
00100 class RandomAssignment : public Assignment {
00101 protected:
00102 int* vals;
00103 int a;
00104
00105 int randval(void);
00106 public:
00108 RandomAssignment(int n, const Gecode::IntSet& d, int a);
00110 virtual bool operator()(void) const;
00112 virtual void operator++(void);
00114 virtual int operator[](int i) const;
00116 virtual ~RandomAssignment(void);
00117 };
00118
00120 class RandomMixAssignment : public Assignment {
00121 protected:
00122 int* vals;
00123 int a;
00124 int _n1;
00125 Gecode::IntSet _d1;
00126
00127 int randval(const Gecode::IntSet& d);
00128 public:
00130 RandomMixAssignment(int n0, const Gecode::IntSet& d0,
00131 int n1, const Gecode::IntSet& d1, int a0);
00133 virtual bool operator()(void) const;
00135 virtual void operator++(void);
00137 virtual int operator[](int i) const;
00139 virtual ~RandomMixAssignment(void);
00140 };
00141
00143 enum ConTestLevel {
00144 CTL_NONE,
00145 CTL_DOMAIN,
00146 CTL_BOUNDS_D,
00147 CTL_BOUNDS_Z,
00148 };
00149
00150 class Test;
00151
00153 class TestSpace : public Gecode::Space {
00154 public:
00156 Gecode::IntSet d;
00158 Gecode::IntVarArray x;
00160 Gecode::Reify r;
00162 Test* test;
00164 bool reified;
00165
00172 TestSpace(int n, Gecode::IntSet& d, Test* t);
00180 TestSpace(int n, Gecode::IntSet& d, Test* t, Gecode::ReifyMode rm);
00182 TestSpace(bool share, TestSpace& s);
00184 virtual Gecode::Space* copy(bool share);
00186 bool assigned(void) const;
00188 void post(void);
00190 bool failed(void);
00192 int rndvar(void);
00194 void rndrel(const Assignment& a, int i, Gecode::IntRelType& irt, int& v);
00196 void rel(int i, Gecode::IntRelType irt, int n);
00198 void rel(bool sol);
00200 void assign(const Assignment& a, bool skip=false);
00202 void bound(void);
00208 void prune(int i, bool bounds_only);
00210 void prune(void);
00212 bool prune(const Assignment& a, bool testfix);
00214 void disable(void);
00216 void enable(void);
00218 bool disabled(const Assignment& a, TestSpace& c, bool testfix);
00220 unsigned int propagators(void);
00221 };
00222
00227 class Test : public Base {
00228 protected:
00230 int arity;
00232 Gecode::IntSet dom;
00234 bool reified;
00236 int rms;
00238 Gecode::IntPropLevel ipl;
00240 ConTestLevel contest;
00242 bool testsearch;
00244 bool testfix;
00246
00247
00248 bool eqv(void) const;
00250 bool imp(void) const;
00252 bool pmi(void) const;
00254 public:
00263 Test(const std::string& p, const std::string& s,
00264 int a, const Gecode::IntSet& d, bool r=false,
00265 Gecode::IntPropLevel i=Gecode::IPL_DEF);
00274 Test(const std::string& s,
00275 int a, const Gecode::IntSet& d, bool r=false,
00276 Gecode::IntPropLevel i=Gecode::IPL_DEF);
00285 Test(const std::string& p, const std::string& s,
00286 int a, int min, int max, bool r=false,
00287 Gecode::IntPropLevel i=Gecode::IPL_DEF);
00296 Test(const std::string& s,
00297 int a, int min, int max, bool r=false,
00298 Gecode::IntPropLevel i=Gecode::IPL_DEF);
00300 virtual Assignment* assignment(void) const;
00302 virtual bool solution(const Assignment&) const = 0;
00304 virtual bool ignore(const Assignment&) const;
00306 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) = 0;
00308 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00309 Gecode::Reify r);
00311 virtual bool run(void);
00313
00314
00315 static std::string str(Gecode::IntPropLevel ipl);
00317 static std::string str(Gecode::IntRelType irl);
00319 static std::string str(Gecode::BoolOpType bot);
00321 static std::string str(int i);
00323 static std::string str(const Gecode::IntArgs& i);
00325
00326
00327
00328 template<class T> static bool cmp(T x, Gecode::IntRelType r, T y);
00330 };
00332
00334 class IntPropLevels {
00335 private:
00337 static const Gecode::IntPropLevel ipls[3];
00339 int i;
00340 public:
00342 IntPropLevels(void);
00344 bool operator()(void) const;
00346 void operator++(void);
00348 Gecode::IntPropLevel ipl(void) const;
00349 };
00350
00352 class IntPropBasicAdvanced {
00353 private:
00355 static const Gecode::IntPropLevel ipls[3];
00357 int i;
00358 public:
00360 IntPropBasicAdvanced(void);
00362 bool operator()(void) const;
00364 void operator++(void);
00366 Gecode::IntPropLevel ipl(void) const;
00367 };
00368
00370 class IntRelTypes {
00371 private:
00373 static const Gecode::IntRelType irts[6];
00375 int i;
00376 public:
00378 IntRelTypes(void);
00380 void reset(void);
00382 bool operator()(void) const;
00384 void operator++(void);
00386 Gecode::IntRelType irt(void) const;
00387 };
00388
00390 class BoolOpTypes {
00391 private:
00393 static const Gecode::BoolOpType bots[5];
00395 int i;
00396 public:
00398 BoolOpTypes(void);
00400 bool operator()(void) const;
00402 void operator++(void);
00404 Gecode::BoolOpType bot(void) const;
00405 };
00406
00407 }
00408 }
00409
00414 std::ostream& operator<<(std::ostream& os, const Test::Int::Assignment& a);
00415
00416 #include "test/int.hpp"
00417
00418 #endif
00419
00420
00421