convex.cpp
Go to the documentation of this file.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 #include "test/set.hh"
00039
00040 using namespace Gecode;
00041
00042 namespace Test { namespace Set {
00043
00045 namespace Convex {
00046
00052
00053 static IntSet ds_33(-4,4);
00054
00056 class Convex : public SetTest {
00057 public:
00059 Convex(const char* t)
00060 : SetTest(t,1,ds_33,false) {}
00062 virtual bool solution(const SetAssignment& x) const {
00063 CountableSetRanges xr0(x.lub, x[0]);
00064 if (!xr0())
00065 return true;
00066 ++xr0;
00067 if (!xr0())
00068 return true;
00069 return false;
00070 }
00072 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00073 Gecode::convex(home, x[0]);
00074 }
00075 };
00076 Convex _convex("Convex::Convex");
00077
00079 class ConvexHull : public SetTest {
00080 public:
00082 ConvexHull(const char* t)
00083 : SetTest(t,2,ds_33,false) {}
00085 virtual bool solution(const SetAssignment& x) const {
00086 CountableSetRanges xr0(x.lub, x[0]);
00087 CountableSetRanges xr1(x.lub, x[1]);
00088
00089 if (!xr0())
00090 return !xr1();
00091
00092 int x0min = xr0.min();
00093 int x0max = xr0.max();
00094 ++xr0;
00095 if (!xr0()) {
00096 if (!xr1()) return false;
00097 if (x0min != xr1.min()) return false;
00098 int x1max = Gecode::Set::Limits::min;
00099 while (xr1()) { x1max = xr1.max(); ++xr1;}
00100 if (x0max != x1max) return false;
00101 return true;
00102 }
00103 return false;
00104 }
00106 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00107 Gecode::convex(home, x[1], x[0]);
00108 }
00109 };
00110 ConvexHull _convexhull("Convex::ConvexHull");
00111
00113 class ConvexHullS : public SetTest {
00114 public:
00116 ConvexHullS(const char* t)
00117 : SetTest(t,1,ds_33,false) {}
00119 virtual bool solution(const SetAssignment& x) const {
00120 CountableSetRanges xr0(x.lub, x[0]);
00121 if (!xr0())
00122 return true;
00123 ++xr0;
00124 if (!xr0())
00125 return true;
00126 return false;
00127 }
00129 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00130 Gecode::convex(home, x[0], x[0]);
00131 }
00132 };
00133 ConvexHullS _convexhulls("Convex::Sharing::ConvexHullS");
00134
00136
00137 }}}
00138
00139