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 #include "test/float.hh"
00037
00038 #include <gecode/minimodel.hh>
00039
00040 namespace Test { namespace Float {
00041
00043 namespace Rel {
00044
00050
00051 class FloatVarXY : public Test {
00052 protected:
00054 Gecode::FloatRelType frt;
00055 public:
00057 FloatVarXY(Gecode::FloatRelType frt0, int n, Gecode::FloatNum st)
00058 : Test("Rel::Float::Var::XY::"+str(frt0)+"::"+str(n),
00059 n+1,-3,3,st,CPLT_ASSIGNMENT,n==1),
00060 frt(frt0) {
00061 testsubsumed = false;
00062 }
00064 virtual MaybeType solution(const Assignment& x) const {
00065 if (x.size() == 2) {
00066 return cmp(x[0],frt,x[1]);
00067 } else {
00068 MaybeType r1 = cmp(x[0],frt,x[2]);
00069 MaybeType r2 = cmp(x[1],frt,x[2]);
00070 if ((r1 == MT_TRUE) && (r2 == MT_TRUE)) return MT_TRUE;
00071 else if ((r1 == MT_FALSE) || (r2 == MT_FALSE)) return MT_FALSE;
00072 else return MT_MAYBE;
00073 }
00074 }
00076 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00077 using namespace Gecode;
00078 if (x.size() == 2) {
00079 rel(home, x[0], frt, x[1]);
00080 } else {
00081 FloatVarArgs y(2);
00082 y[0]=x[0]; y[1]=x[1];
00083 rel(home, y, frt, x[2]);
00084 }
00085 }
00087 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00088 Gecode::Reify r) {
00089 assert(x.size() == 2);
00090 Gecode::rel(home, x[0], frt, x[1], r);
00091 }
00092 };
00093
00095 class FloatVarXX : public Test {
00096 protected:
00098 Gecode::FloatRelType frt;
00099 public:
00101 FloatVarXX(Gecode::FloatRelType frt0, Gecode::FloatNum st)
00102 : Test("Rel::Float::Var::XX::"+str(frt0),
00103 1,-3,3,st,CPLT_ASSIGNMENT,true),
00104 frt(frt0) {
00105 testsubsumed = false;
00106 }
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) {
00136 testsubsumed = false;
00137 }
00139 virtual MaybeType solution(const Assignment& x) const {
00140 if (x.size() == 1) {
00141 return cmp(x[0],frt,c);
00142 } else {
00143 return cmp(x[0],frt,c) & cmp(x[1],frt,c);
00144 }
00145 }
00147 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00148 using namespace Gecode;
00149 if (x.size() == 1)
00150 rel(home, x[0], frt, c);
00151 else
00152 rel(home, x, frt, c);
00153 }
00155 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00156 Gecode::Reify r) {
00157 assert(x.size() == 1);
00158 Gecode::rel(home, x[0], frt, c, r);
00159 }
00160 };
00161
00163 class Create {
00164 public:
00166 Create(void) {
00167 using namespace Gecode;
00168 Gecode::FloatNum step = 0.7;
00169 for (FloatRelTypes frts; frts(); ++frts) {
00170 (void) new FloatVarXY(frts.frt(),1,step);
00171 (void) new FloatVarXY(frts.frt(),2,step);
00172 (void) new FloatVarXX(frts.frt(),step);
00173 for (int c=-4; c<=4; c++) {
00174 (void) new FloatFloat(frts.frt(),1,c,step);
00175 (void) new FloatFloat(frts.frt(),2,c,step);
00176 }
00177 }
00178 }
00179 };
00180
00181 Create c;
00183
00184 }
00185
00186 }}
00187
00188