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 #include "test/float.hh"
00041
00042 #include <gecode/minimodel.hh>
00043
00044 namespace Test { namespace Float {
00045
00047 namespace Dom {
00048
00054
00055 class Val : public Test {
00056 protected:
00058 Gecode::FloatVal c;
00059 public:
00061 Val(int n, Gecode::FloatVal c0, Gecode::FloatNum st)
00062 : Test("Dom::Val::"+str(n)+"::"+str(c0),
00063 n,-3,3,st,CPLT_ASSIGNMENT,n==1), c(c0) {}
00065 virtual MaybeType solution(const Assignment& x) const {
00066 for (int i=x.size(); i--; )
00067 if ((x[i].max() > c.max()) || (x[i].min() < c.min()))
00068 return MT_FALSE;
00069 return MT_TRUE;
00070 }
00072 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00073 if (x.size() == 1)
00074 Gecode::dom(home, x[0], c);
00075 else
00076 Gecode::dom(home, x, c);
00077 }
00079 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00080 Gecode::Reify r) {
00081 assert(x.size() == 1);
00082 Gecode::dom(home, x[0], c, r);
00083 }
00084 };
00085
00087 class Num : public Test {
00088 protected:
00090 Gecode::FloatNum min;
00092 Gecode::FloatNum max;
00093 public:
00095 Num(int n, Gecode::FloatNum min0, Gecode::FloatNum max0,
00096 Gecode::FloatNum st)
00097 : Test("Dom::Num::"+str(n)+"::"+str(min0)+"::"+str(max0),
00098 n,-3,3,st,CPLT_ASSIGNMENT,n==1), min(min0), max(max0) {}
00100 virtual MaybeType solution(const Assignment& x) const {
00101 if (max < min)
00102 return MT_FALSE;
00103 for (int i=x.size(); i--; )
00104 if ((x[i].max() > max) || (x[i].min() < min))
00105 return MT_FALSE;
00106 return MT_TRUE;
00107 }
00109 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00110 if (x.size() == 1)
00111 Gecode::dom(home, x[0], min, max);
00112 else
00113 Gecode::dom(home, x, min, max);
00114 }
00116 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00117 Gecode::Reify r) {
00118 assert(x.size() == 1);
00119 Gecode::dom(home, x[0], min, max, r);
00120 }
00121 };
00122
00124 class Create {
00125 public:
00127 Create(void) {
00128 using namespace Gecode;
00129 FloatNum step = 0.7;
00130 for (int c=-4; c<=4; c++) {
00131 (void) new Val(1,c,step);
00132 (void) new Val(2,c,step);
00133 for (int d=-3; d<=3; d++) {
00134 (void) new Num(1,c,d,step);
00135 (void) new Num(2,c,d,step);
00136 }
00137 }
00138 }
00139 };
00140
00141 Create c;
00143
00144 }
00145
00146 }}
00147
00148