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 #include "test/set.hh"
00035
00036 using namespace Gecode;
00037
00038 namespace Test { namespace Set {
00039
00041 namespace Convex {
00042
00048
00049 static IntSet ds_33(-4,4);
00050
00052 class Convex : public SetTest {
00053 public:
00055 Convex(const char* t)
00056 : SetTest(t,1,ds_33,false) {}
00058 virtual bool solution(const SetAssignment& x) const {
00059 CountableSetRanges xr0(x.lub, x[0]);
00060 if (!xr0())
00061 return true;
00062 ++xr0;
00063 if (!xr0())
00064 return true;
00065 return false;
00066 }
00068 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00069 Gecode::convex(home, x[0]);
00070 }
00071 };
00072 Convex _convex("Convex::Convex");
00073
00075 class ConvexHull : public SetTest {
00076 public:
00078 ConvexHull(const char* t)
00079 : SetTest(t,2,ds_33,false) {}
00081 virtual bool solution(const SetAssignment& x) const {
00082 CountableSetRanges xr0(x.lub, x[0]);
00083 CountableSetRanges xr1(x.lub, x[1]);
00084
00085 if (!xr0())
00086 return !xr1();
00087
00088 int x0min = xr0.min();
00089 int x0max = xr0.max();
00090 ++xr0;
00091 if (!xr0()) {
00092 if (!xr1()) return false;
00093 if (x0min != xr1.min()) return false;
00094 int x1max = Gecode::Set::Limits::min;
00095 while (xr1()) { x1max = xr1.max(); ++xr1;}
00096 if (x0max != x1max) return false;
00097 return true;
00098 }
00099 return false;
00100 }
00102 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00103 Gecode::convex(home, x[1], x[0]);
00104 }
00105 };
00106 ConvexHull _convexhull("Convex::ConvexHull");
00107
00109 class ConvexHullS : public SetTest {
00110 public:
00112 ConvexHullS(const char* t)
00113 : SetTest(t,1,ds_33,false) {}
00115 virtual bool solution(const SetAssignment& x) const {
00116 CountableSetRanges xr0(x.lub, x[0]);
00117 if (!xr0())
00118 return true;
00119 ++xr0;
00120 if (!xr0())
00121 return true;
00122 return false;
00123 }
00125 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00126 Gecode::convex(home, x[0], x[0]);
00127 }
00128 };
00129 ConvexHullS _convexhulls("Convex::Sharing::ConvexHullS");
00130
00132
00133 }}}
00134
00135