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) {
00065 testsubsumed = false;
00066 }
00068 virtual MaybeType solution(const Assignment& x) const {
00069 if (x.size() == 2) {
00070 return cmp(x[0],frt,x[1]);
00071 } else {
00072 MaybeType r1 = cmp(x[0],frt,x[2]);
00073 MaybeType r2 = cmp(x[1],frt,x[2]);
00074 if ((r1 == MT_TRUE) && (r2 == MT_TRUE)) return MT_TRUE;
00075 else if ((r1 == MT_FALSE) || (r2 == MT_FALSE)) return MT_FALSE;
00076 else return MT_MAYBE;
00077 }
00078 }
00080 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00081 using namespace Gecode;
00082 if (x.size() == 2) {
00083 rel(home, x[0], frt, x[1]);
00084 } else {
00085 FloatVarArgs y(2);
00086 y[0]=x[0]; y[1]=x[1];
00087 rel(home, y, frt, x[2]);
00088 }
00089 }
00091 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00092 Gecode::Reify r) {
00093 assert(x.size() == 2);
00094 Gecode::rel(home, x[0], frt, x[1], r);
00095 }
00096 };
00097
00099 class FloatVarXX : public Test {
00100 protected:
00102 Gecode::FloatRelType frt;
00103 public:
00105 FloatVarXX(Gecode::FloatRelType frt0, Gecode::FloatNum st)
00106 : Test("Rel::Float::Var::XX::"+str(frt0),
00107 1,-3,3,st,CPLT_ASSIGNMENT,true),
00108 frt(frt0) {
00109 testsubsumed = false;
00110 }
00112 virtual MaybeType solution(const Assignment& x) const {
00113 return cmp(x[0],frt,x[0]);
00114 }
00116 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00117 Gecode::rel(home, x[0], frt, x[0]);
00118 }
00120 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00121 Gecode::Reify r) {
00122 Gecode::rel(home, x[0], frt, x[0], r);
00123 }
00124 };
00125
00127 class FloatFloat : public Test {
00128 protected:
00130 Gecode::FloatRelType frt;
00132 Gecode::FloatVal c;
00133 public:
00135 FloatFloat(Gecode::FloatRelType frt0, int n, Gecode::FloatNum c0,
00136 Gecode::FloatNum st)
00137 : Test("Rel::Float::Float::"+str(frt0)+"::"+str(n)+"::"+str(c0),
00138 n,-3,3,st,CPLT_ASSIGNMENT,n==1),
00139 frt(frt0), c(c0) {
00140 testsubsumed = false;
00141 }
00143 virtual MaybeType solution(const Assignment& x) const {
00144 if (x.size() == 1) {
00145 return cmp(x[0],frt,c);
00146 } else {
00147 return cmp(x[0],frt,c) & cmp(x[1],frt,c);
00148 }
00149 }
00151 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00152 using namespace Gecode;
00153 if (x.size() == 1)
00154 rel(home, x[0], frt, c);
00155 else
00156 rel(home, x, frt, c);
00157 }
00159 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00160 Gecode::Reify r) {
00161 assert(x.size() == 1);
00162 Gecode::rel(home, x[0], frt, c, r);
00163 }
00164 };
00165
00167 class Create {
00168 public:
00170 Create(void) {
00171 using namespace Gecode;
00172 Gecode::FloatNum step = 0.7;
00173 for (FloatRelTypes frts; frts(); ++frts) {
00174 (void) new FloatVarXY(frts.frt(),1,step);
00175 (void) new FloatVarXY(frts.frt(),2,step);
00176 (void) new FloatVarXX(frts.frt(),step);
00177 for (int c=-4; c<=4; c++) {
00178 (void) new FloatFloat(frts.frt(),1,c,step);
00179 (void) new FloatFloat(frts.frt(),2,c,step);
00180 }
00181 }
00182 }
00183 };
00184
00185 Create c;
00187
00188 }
00189
00190 }}
00191
00192