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 Rel {
00048
00054
00055 class FloatVarXY : public Test {
00056 protected:
00058 Gecode::FloatRelType frt;
00059 public:
00061 FloatVarXY(Gecode::FloatRelType frt0, int n, Gecode::FloatNum st)
00062 : Test("Rel::Float::Var::XY::"+str(frt0)+"::"+str(n),
00063 n+1,-3,3,st,CPLT_ASSIGNMENT,n==1),
00064 frt(frt0) {}
00066 virtual MaybeType solution(const Assignment& x) const {
00067 if (x.size() == 2) {
00068 return cmp(x[0],frt,x[1]);
00069 } else {
00070 MaybeType r1 = cmp(x[0],frt,x[2]);
00071 MaybeType r2 = cmp(x[1],frt,x[2]);
00072 if ((r1 == MT_TRUE) && (r2 == MT_TRUE)) return MT_TRUE;
00073 else if ((r1 == MT_FALSE) || (r2 == MT_FALSE)) return MT_FALSE;
00074 else return MT_MAYBE;
00075 }
00076 }
00078 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00079 using namespace Gecode;
00080 if (x.size() == 2) {
00081 rel(home, x[0], frt, x[1]);
00082 } else {
00083 FloatVarArgs y(2);
00084 y[0]=x[0]; y[1]=x[1];
00085 rel(home, y, frt, x[2]);
00086 }
00087 }
00089 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00090 Gecode::Reify r) {
00091 assert(x.size() == 2);
00092 Gecode::rel(home, x[0], frt, x[1], r);
00093 }
00094 };
00095
00097 class FloatVarXX : public Test {
00098 protected:
00100 Gecode::FloatRelType frt;
00101 public:
00103 FloatVarXX(Gecode::FloatRelType frt0, Gecode::FloatNum st)
00104 : Test("Rel::Float::Var::XX::"+str(frt0),
00105 1,-3,3,st,CPLT_ASSIGNMENT,true),
00106 frt(frt0) { }
00108 virtual MaybeType solution(const Assignment& x) const {
00109 return cmp(x[0],frt,x[0]);
00110 }
00112 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00113 Gecode::rel(home, x[0], frt, x[0]);
00114 }
00116 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00117 Gecode::Reify r) {
00118 Gecode::rel(home, x[0], frt, x[0], r);
00119 }
00120 };
00121
00123 class FloatFloat : public Test {
00124 protected:
00126 Gecode::FloatRelType frt;
00128 Gecode::FloatVal c;
00129 public:
00131 FloatFloat(Gecode::FloatRelType frt0, int n, Gecode::FloatNum c0,
00132 Gecode::FloatNum st)
00133 : Test("Rel::Float::Float::"+str(frt0)+"::"+str(n)+"::"+str(c0),
00134 n,-3,3,st,CPLT_ASSIGNMENT,n==1),
00135 frt(frt0), c(c0) {}
00137 virtual MaybeType solution(const Assignment& x) const {
00138 if (x.size() == 1) {
00139 return cmp(x[0],frt,c);
00140 } else {
00141 return cmp(x[0],frt,c) & cmp(x[1],frt,c);
00142 }
00143 }
00145 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00146 using namespace Gecode;
00147 if (x.size() == 1)
00148 rel(home, x[0], frt, c);
00149 else
00150 rel(home, x, frt, c);
00151 }
00153 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00154 Gecode::Reify r) {
00155 assert(x.size() == 1);
00156 Gecode::rel(home, x[0], frt, c, r);
00157 }
00158 };
00159
00161 class Create {
00162 public:
00164 Create(void) {
00165 using namespace Gecode;
00166 Gecode::FloatNum step = 0.7;
00167 for (FloatRelTypes frts; frts(); ++frts) {
00168 (void) new FloatVarXY(frts.frt(),1,step);
00169 (void) new FloatVarXY(frts.frt(),2,step);
00170 (void) new FloatVarXX(frts.frt(),step);
00171 for (int c=-4; c<=4; c++) {
00172 (void) new FloatFloat(frts.frt(),1,c,step);
00173 (void) new FloatFloat(frts.frt(),2,c,step);
00174 }
00175 }
00176 }
00177 };
00178
00179 Create c;
00181
00182 }
00183
00184 }}
00185
00186