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
00041
00042 #ifndef __GECODE_TEST_FLOAT_HH__
00043 #define __GECODE_TEST_FLOAT_HH__
00044
00045 #include "test/test.hh"
00046
00047 #include <gecode/float.hh>
00048
00049 namespace Test {
00050
00052 namespace Float {
00053
00055 enum MaybeType {
00056 MT_FALSE = 0,
00057 MT_TRUE,
00058 MT_MAYBE
00059 };
00060
00062 MaybeType operator &(MaybeType a, MaybeType b);
00063
00065 enum AssignmentType {
00066 CPLT_ASSIGNMENT = 0,
00067 RANDOM_ASSIGNMENT,
00068 EXTEND_ASSIGNMENT
00069 };
00070
00071 class Test;
00072
00083
00084 class Assignment {
00085 protected:
00086 int n;
00087 Gecode::FloatVal d;
00088 public:
00090 Assignment(int n0, const Gecode::FloatVal& d0);
00092 virtual bool operator()(void) const = 0;
00094 virtual void operator++(void) = 0;
00096 virtual Gecode::FloatVal operator[](int i) const = 0;
00098 virtual void set(int i, const Gecode::FloatVal& val) = 0;
00100 int size(void) const;
00102 virtual ~Assignment(void);
00103 };
00104
00106 class CpltAssignment : public Assignment {
00107 protected:
00108 Gecode::FloatVal* dsv;
00109 Gecode::FloatNum step;
00110 public:
00112 CpltAssignment(int n, const Gecode::FloatVal& d, Gecode::FloatNum s);
00114 virtual bool operator()(void) const;
00116 virtual void operator++(void);
00118 virtual Gecode::FloatVal operator[](int i) const;
00120 virtual void set(int i, const Gecode::FloatVal& val);
00122 virtual ~CpltAssignment(void);
00123 };
00124
00126 class ExtAssignment : public Assignment {
00127 protected:
00128 const Test* curPb;
00129 Gecode::FloatVal* dsv;
00130 Gecode::FloatNum step;
00131 public:
00133 ExtAssignment(int n, const Gecode::FloatVal& d, Gecode::FloatNum s, const Test * pb);
00135 virtual bool operator()(void) const;
00137 virtual void operator++(void);
00139 virtual Gecode::FloatVal operator[](int i) const;
00141 virtual void set(int i, const Gecode::FloatVal& val);
00143 virtual ~ExtAssignment(void);
00144 };
00145
00146
00148 class RandomAssignment : public Assignment {
00149 protected:
00150 Gecode::FloatVal* vals;
00151 int a;
00152
00153 Gecode::FloatNum randval(void);
00154 public:
00156 RandomAssignment(int n, const Gecode::FloatVal& d, int a);
00158 virtual bool operator()(void) const;
00160 virtual void operator++(void);
00162 virtual Gecode::FloatVal operator[](int i) const;
00164 virtual void set(int i, const Gecode::FloatVal& val);
00166 virtual ~RandomAssignment(void);
00167 };
00168
00170 class TestSpace : public Gecode::Space {
00171 public:
00173 Gecode::FloatVal d;
00175 Gecode::FloatNum step;
00177 Gecode::FloatVarArray x;
00179 Gecode::Reify r;
00181 Test* test;
00183 bool reified;
00184
00192 TestSpace(int n, Gecode::FloatVal& d, Gecode::FloatNum s, Test* t);
00200 TestSpace(int n, Gecode::FloatVal& d, Gecode::FloatNum s, Test* t,
00201 Gecode::ReifyMode rm);
00203 TestSpace(bool share, TestSpace& s);
00205 virtual Gecode::Space* copy(bool share);
00207 virtual void dropUntil(const Assignment& a);
00209 bool assigned(void) const;
00211 bool matchAssignment(const Assignment& a) const;
00213 void post(void);
00215 bool failed(void);
00217 void rel(int i, Gecode::FloatRelType frt, Gecode::FloatVal n);
00219 void rel(bool sol);
00223 void assign(const Assignment& a, MaybeType& sol, bool skip=false);
00225 void bound(void);
00229 Gecode::FloatNum cut(int* cutDirections);
00231 void prune(int i);
00233 void prune(void);
00235 bool prune(const Assignment& a, bool testfix);
00237 void disable(void);
00239 void enable(void);
00241 unsigned int propagators(void);
00242 };
00243
00248 class Test : public Base {
00249 protected:
00251 int arity;
00253 Gecode::FloatVal dom;
00255 Gecode::FloatNum step;
00257 AssignmentType assigmentType;
00259 bool reified;
00261 int rms;
00263 bool testsearch;
00265 bool testfix;
00267 bool testsubsumed;
00269
00270
00271 bool eqv(void) const;
00273 bool imp(void) const;
00275 bool pmi(void) const;
00277 public:
00285 Test(const std::string& s, int a, const Gecode::FloatVal& d,
00286 Gecode::FloatNum st, AssignmentType at,
00287 bool r);
00295 Test(const std::string& s, int a,
00296 Gecode::FloatNum min, Gecode::FloatNum max,
00297 Gecode::FloatNum st, AssignmentType at,
00298 bool r);
00300 virtual Assignment* assignment(void) const;
00303 virtual bool extendAssignement(Assignment& a) const;
00305 virtual MaybeType solution(const Assignment&) const = 0;
00308 bool subsumed(const TestSpace& ts) const;
00310 virtual bool ignore(const Assignment& a) const;
00312 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) = 0;
00314 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00315 Gecode::Reify r);
00317 virtual bool run(void);
00319
00320
00321 static std::string str(Gecode::FloatRelType frt);
00323 static std::string str(Gecode::FloatNum f);
00325 static std::string str(Gecode::FloatVal f);
00327 static std::string str(const Gecode::FloatValArgs& f);
00329
00330
00331
00332 static MaybeType cmp(Gecode::FloatVal x, Gecode::FloatRelType r,
00333 Gecode::FloatVal y);
00335 static MaybeType eq(Gecode::FloatVal x, Gecode::FloatVal y);
00337 bool flip(void);
00339 };
00341
00343 class FloatRelTypes {
00344 private:
00346 static const Gecode::FloatRelType frts[6];
00348 int i;
00349 public:
00351 FloatRelTypes(void);
00353 void reset(void);
00355 bool operator()(void) const;
00357 void operator++(void);
00359 Gecode::FloatRelType frt(void) const;
00360 };
00361
00362 }
00363 }
00364
00369 std::ostream& operator<<(std::ostream& os, const Test::Float::Assignment& a);
00370
00371 #include "test/float.hpp"
00372
00373 #endif
00374
00375
00376