cardinality.cc
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 #include "test/cpltset.hh"
00038
00039 using namespace Gecode;
00040 using namespace Test::Set;
00041
00042 namespace Test { namespace CpltSet {
00043
00045 namespace Cardinality {
00046
00052
00053 static const int d1r[4][2] = {
00054 {-4,-3},{-1,-1},{1,1},{3,5}
00055 };
00056 static IntSet d1(d1r,4);
00057
00058 static IntSet ds_33(-3,3);
00059 static IntSet ds_4(4,4);
00060 static IntSet ds_13(1,3);
00061
00063 class CpltSetCardMinMax : public CpltSetTest {
00064 public:
00066 CpltSetCardMinMax(const char* t) : CpltSetTest(t,1,d1,false) {}
00068 virtual bool solution(const SetAssignment& x) const {
00069 CountableSetRanges xr1(x.lub, x[0]);
00070
00071 int c = 0;
00072 while (xr1()) {
00073 c += xr1.width();
00074 ++xr1;
00075 }
00076 return (0<= c && c <= 3);
00077 }
00078
00080 virtual void post(Space* home, CpltSetVarArray& x, IntVarArray&) {
00081 Gecode::cardinality(home, x[0], 0, 3);
00082 }
00083 };
00084 CpltSetCardMinMax _cpltsetcardminmax("Card::MinMax");
00085
00087 class CpltSetCardEq : public CpltSetTest {
00088 public:
00090 CpltSetCardEq(const char* t) : CpltSetTest(t,1,d1,false) {}
00092 virtual bool solution(const SetAssignment& x) const {
00093 CountableSetRanges xr1(x.lub, x[0]);
00094
00095 int c = 0;
00096 while (xr1()) {
00097 c += xr1.width();
00098 ++xr1;
00099 }
00100 return (c == 3);
00101 }
00102
00104 virtual void post(Space* home, CpltSetVarArray& x, IntVarArray&) {
00105 Gecode::cardinality(home, x[0], 3, 3);
00106 }
00107 };
00108 CpltSetCardEq _cpltsetcardeq("Card::Eq");
00109
00111 class CpltSetCardMinInf : public CpltSetTest {
00112 public:
00114 CpltSetCardMinInf(const char* t) : CpltSetTest(t,1,d1,false) {}
00116 virtual bool solution(const SetAssignment& x) const {
00117 CountableSetRanges xr1(x.lub, x[0]);
00118
00119 int c = 0;
00120 while (xr1()) {
00121 c += xr1.width();
00122 ++xr1;
00123 }
00124 return (c >= 1);
00125 }
00126
00128 virtual void post(Space* home, CpltSetVarArray& x, IntVarArray&) {
00129 Gecode::cardinality(home, x[0], 1, Gecode::Set::Limits::max);
00130 }
00131 };
00132 CpltSetCardMinInf _cpltsetcardmininf("Card::MinInf");
00133
00135
00136 }}}
00137
00138