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);
00236 };
00237
00242 class Test : public Base {
00243 protected:
00245 int arity;
00247 Gecode::FloatVal dom;
00249 Gecode::FloatNum step;
00251 AssignmentType assigmentType;
00253 bool reified;
00255 int rms;
00257 bool testsearch;
00259 bool testfix;
00261 bool testsubsumed;
00263
00264
00265 bool eqv(void) const;
00267 bool imp(void) const;
00269 bool pmi(void) const;
00271 public:
00279 Test(const std::string& s, int a, const Gecode::FloatVal& d,
00280 Gecode::FloatNum st, AssignmentType at,
00281 bool r);
00289 Test(const std::string& s, int a,
00290 Gecode::FloatNum min, Gecode::FloatNum max,
00291 Gecode::FloatNum st, AssignmentType at,
00292 bool r);
00294 virtual Assignment* assignment(void) const;
00297 virtual bool extendAssignement(Assignment& a) const;
00299 virtual MaybeType solution(const Assignment&) const = 0;
00302 bool subsumed(const TestSpace& ts) const;
00304 virtual bool ignore(const Assignment& a) const;
00306 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) = 0;
00308 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00309 Gecode::Reify r);
00311 virtual bool run(void);
00313
00314
00315 static std::string str(Gecode::FloatRelType frt);
00317 static std::string str(Gecode::FloatNum f);
00319 static std::string str(Gecode::FloatVal f);
00321 static std::string str(const Gecode::FloatValArgs& f);
00323
00324
00325
00326 static MaybeType cmp(Gecode::FloatVal x, Gecode::FloatRelType r,
00327 Gecode::FloatVal y);
00329 static MaybeType eq(Gecode::FloatVal x, Gecode::FloatVal y);
00331 bool flip(void);
00333 };
00335
00337 class FloatRelTypes {
00338 private:
00340 static const Gecode::FloatRelType frts[6];
00342 int i;
00343 public:
00345 FloatRelTypes(void);
00347 void reset(void);
00349 bool operator()(void) const;
00351 void operator++(void);
00353 Gecode::FloatRelType frt(void) const;
00354 };
00355
00356 }
00357 }
00358
00363 std::ostream& operator<<(std::ostream& os, const Test::Float::Assignment& a);
00364
00365 #include "test/float.hpp"
00366
00367 #endif
00368
00369
00370