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 #ifndef __GECODE_TEST_FLOAT_HH__
00039 #define __GECODE_TEST_FLOAT_HH__
00040
00041 #include "test/test.hh"
00042
00043 #include <gecode/float.hh>
00044
00045 namespace Test {
00046
00048 namespace Float {
00049
00051 enum MaybeType {
00052 MT_FALSE = 0,
00053 MT_TRUE,
00054 MT_MAYBE
00055 };
00056
00058 MaybeType operator &(MaybeType a, MaybeType b);
00059
00061 enum AssignmentType {
00062 CPLT_ASSIGNMENT = 0,
00063 RANDOM_ASSIGNMENT,
00064 EXTEND_ASSIGNMENT
00065 };
00066
00067 class Test;
00068
00079
00080 class Assignment {
00081 protected:
00082 int n;
00083 Gecode::FloatVal d;
00084 public:
00086 Assignment(int n0, const Gecode::FloatVal& d0);
00088 virtual bool operator()(void) const = 0;
00090 virtual void operator++(void) = 0;
00092 virtual Gecode::FloatVal operator[](int i) const = 0;
00094 virtual void set(int i, const Gecode::FloatVal& val) = 0;
00096 int size(void) const;
00098 virtual ~Assignment(void);
00099 };
00100
00102 class CpltAssignment : public Assignment {
00103 protected:
00104 Gecode::FloatVal* dsv;
00105 Gecode::FloatNum step;
00106 public:
00108 CpltAssignment(int n, const Gecode::FloatVal& d, Gecode::FloatNum s);
00110 virtual bool operator()(void) const;
00112 virtual void operator++(void);
00114 virtual Gecode::FloatVal operator[](int i) const;
00116 virtual void set(int i, const Gecode::FloatVal& val);
00118 virtual ~CpltAssignment(void);
00119 };
00120
00122 class ExtAssignment : public Assignment {
00123 protected:
00124 const Test* curPb;
00125 Gecode::FloatVal* dsv;
00126 Gecode::FloatNum step;
00127 public:
00129 ExtAssignment(int n, const Gecode::FloatVal& d, Gecode::FloatNum s, const Test * pb);
00131 virtual bool operator()(void) const;
00133 virtual void operator++(void);
00135 virtual Gecode::FloatVal operator[](int i) const;
00137 virtual void set(int i, const Gecode::FloatVal& val);
00139 virtual ~ExtAssignment(void);
00140 };
00141
00142
00144 class RandomAssignment : public Assignment {
00145 protected:
00146 Gecode::FloatVal* vals;
00147 int a;
00148
00149 Gecode::FloatNum randval(void);
00150 public:
00152 RandomAssignment(int n, const Gecode::FloatVal& d, int a);
00154 virtual bool operator()(void) const;
00156 virtual void operator++(void);
00158 virtual Gecode::FloatVal operator[](int i) const;
00160 virtual void set(int i, const Gecode::FloatVal& val);
00162 virtual ~RandomAssignment(void);
00163 };
00164
00166 class TestSpace : public Gecode::Space {
00167 public:
00169 Gecode::FloatVal d;
00171 Gecode::FloatNum step;
00173 Gecode::FloatVarArray x;
00175 Gecode::Reify r;
00177 Test* test;
00179 bool reified;
00180
00188 TestSpace(int n, Gecode::FloatVal& d, Gecode::FloatNum s, Test* t);
00196 TestSpace(int n, Gecode::FloatVal& d, Gecode::FloatNum s, Test* t,
00197 Gecode::ReifyMode rm);
00199 TestSpace(TestSpace& s);
00201 virtual Gecode::Space* copy(void);
00203 virtual void dropUntil(const Assignment& a);
00205 bool assigned(void) const;
00207 bool matchAssignment(const Assignment& a) const;
00209 void post(void);
00211 bool failed(void);
00213 void rel(int i, Gecode::FloatRelType frt, Gecode::FloatVal n);
00215 void rel(bool sol);
00219 void assign(const Assignment& a, MaybeType& sol, bool skip=false);
00221 void bound(void);
00225 Gecode::FloatNum cut(int* cutDirections);
00227 void prune(int i);
00229 void prune(void);
00231 bool prune(const Assignment& a, bool testfix);
00233 void disable(void);
00235 void enable(void);
00237 unsigned int propagators(void);
00238 };
00239
00244 class Test : public Base {
00245 protected:
00247 int arity;
00249 Gecode::FloatVal dom;
00251 Gecode::FloatNum step;
00253 AssignmentType assigmentType;
00255 bool reified;
00257 int rms;
00259 bool testsearch;
00261 bool testfix;
00263 bool testsubsumed;
00265
00266
00267 bool eqv(void) const;
00269 bool imp(void) const;
00271 bool pmi(void) const;
00273 public:
00281 Test(const std::string& s, int a, const Gecode::FloatVal& d,
00282 Gecode::FloatNum st, AssignmentType at,
00283 bool r);
00291 Test(const std::string& s, int a,
00292 Gecode::FloatNum min, Gecode::FloatNum max,
00293 Gecode::FloatNum st, AssignmentType at,
00294 bool r);
00296 virtual Assignment* assignment(void) const;
00299 virtual bool extendAssignement(Assignment& a) const;
00301 virtual MaybeType solution(const Assignment&) const = 0;
00304 bool subsumed(const TestSpace& ts) const;
00306 virtual bool ignore(const Assignment& a) const;
00308 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) = 0;
00310 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00311 Gecode::Reify r);
00313 virtual bool run(void);
00315
00316
00317 static std::string str(Gecode::FloatRelType frt);
00319 static std::string str(Gecode::FloatNum f);
00321 static std::string str(Gecode::FloatVal f);
00323 static std::string str(const Gecode::FloatValArgs& f);
00325
00326
00327
00328 static MaybeType cmp(Gecode::FloatVal x, Gecode::FloatRelType r,
00329 Gecode::FloatVal y);
00331 static MaybeType eq(Gecode::FloatVal x, Gecode::FloatVal y);
00333 bool flip(void);
00335 };
00337
00339 class FloatRelTypes {
00340 private:
00342 static const Gecode::FloatRelType frts[6];
00344 int i;
00345 public:
00347 FloatRelTypes(void);
00349 void reset(void);
00351 bool operator()(void) const;
00353 void operator++(void);
00355 Gecode::FloatRelType frt(void) const;
00356 };
00357
00358 }
00359 }
00360
00365 std::ostream& operator<<(std::ostream& os, const Test::Float::Assignment& a);
00366
00367 #include "test/float.hpp"
00368
00369 #endif
00370
00371
00372