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 #include "test/int.hh"
00040 #include <gecode/minimodel.hh>
00041
00042 using namespace Gecode;
00043
00044 namespace Test { namespace Set {
00045
00047 namespace Channel {
00048
00054
00055 static IntSet d1(0,2);
00056 static IntSet d_12(-1,2);
00057
00058 static IntSet d2(-1,3);
00059 static IntSet d3(0,3);
00060
00061 static IntSet d4(0,4);
00062
00063 static IntSet ds_33(-3,3);
00064
00066 class ChannelSorted : public SetTest {
00067 public:
00069 ChannelSorted(const char* t)
00070 : SetTest(t,1,ds_33,false,3) {}
00072 virtual bool solution(const SetAssignment& x) const {
00073 if (x.ints()[0]>=x.ints()[1] ||
00074 x.ints()[1]>=x.ints()[2])
00075 return false;
00076 CountableSetValues xr(x.lub, x[0]);
00077 if (!xr())
00078 return false;
00079 if (xr.val() != x.ints()[0])
00080 return false;
00081 ++xr;
00082 if (!xr())
00083 return false;
00084 if (xr.val() != x.ints()[1])
00085 return false;
00086 ++xr;
00087 if (!xr())
00088 return false;
00089 if (xr.val() != x.ints()[2])
00090 return false;
00091 ++xr;
00092 if (xr())
00093 return false;
00094 return true;
00095 }
00097 virtual void post(Space& home, SetVarArray& x, IntVarArray& y) {
00098 Gecode::channelSorted(home, y, x[0]);
00099 }
00100 };
00101 ChannelSorted _channelSorted("Channel::Sorted");
00102
00104 class ChannelInt : public SetTest {
00105 private:
00106 int ssize, isize;
00107 public:
00109 ChannelInt(const char* t, const IntSet& d, int _ssize, int _isize)
00110 : SetTest(t,_ssize,d,false,_isize), ssize(_ssize), isize(_isize) {}
00112 virtual bool solution(const SetAssignment& x) const {
00113 for (int i=0; i<isize; i++) {
00114 if (x.ints()[i] < 0 || x.ints()[i] >= ssize)
00115 return false;
00116 Iter::Ranges::Singleton single(i,i);
00117 CountableSetRanges csr(x.lub, x[x.ints()[i]]);
00118 if (!Iter::Ranges::subset(single, csr))
00119 return false;
00120 }
00121 for (int i=0; i<ssize; i++) {
00122 int size = 0;
00123 for (CountableSetValues csv(x.lub, x[i]); csv(); ++csv) {
00124 if (csv.val() < 0 || csv.val() >= isize) return false;
00125 if (x.ints()[csv.val()] != i) return false;
00126 size++;
00127 }
00128 }
00129 return true;
00130 }
00132 virtual void post(Space& home, SetVarArray& x, IntVarArray& y) {
00133 Gecode::channel(home, y, x);
00134 }
00135 };
00136
00137 ChannelInt _channelint1("Channel::Int::1", d2, 2, 3);
00138 ChannelInt _channelint2("Channel::Int::2", d3, 3, 3);
00139
00141 class ChannelBool : public SetTest {
00142 private:
00143 int isize;
00144 public:
00146 ChannelBool(const char* t, const IntSet& d, int _isize)
00147 : SetTest(t,1,d,false,_isize), isize(_isize) {}
00149 virtual bool solution(const SetAssignment& x) const {
00150 for (int i=0; i<isize; i++) {
00151 if (x.ints()[i] < 0 || x.ints()[i] > 1)
00152 return false;
00153 }
00154 int cur = 0;
00155 for (CountableSetValues csv(x.lub, x[0]); csv(); ++csv) {
00156 if (csv.val() < 0 || csv.val() >= isize) return false;
00157 if (x.ints()[csv.val()] != 1) return false;
00158 for (; cur<csv.val(); cur++)
00159 if (x.ints()[cur] != 0) return false;
00160 cur = csv.val() + 1;
00161 }
00162 for (; cur<isize; cur++)
00163 if (x.ints()[cur] != 0) return false;
00164 return true;
00165 }
00167 virtual void post(Space& home, SetVarArray& x, IntVarArray& y) {
00168 BoolVarArgs b(y.size());
00169 for (int i=y.size(); i--;)
00170 b[i] = channel(home, y[i]);
00171 Gecode::channel(home, b, x[0]);
00172 }
00173 };
00174
00175 ChannelBool _channelbool1("Channel::Bool::1", d2, 3);
00176 ChannelBool _channelbool2("Channel::Bool::2", d3, 3);
00177 ChannelBool _channelbool3("Channel::Bool::3", d4, 5);
00178
00180 class ChannelSet : public SetTest {
00181 private:
00182 int _x0size, _x1size;
00183 public:
00185 ChannelSet(const char* t, const IntSet& d, int x0size, int x1size)
00186 : SetTest(t,x0size+x1size,d,false), _x0size(x0size), _x1size(x1size) {}
00188 virtual bool solution(const SetAssignment& x) const {
00189 for (int i=0; i<_x0size; i++) {
00190 CountableSetRanges x0ir(x.lub, x[i]);
00191 IntSet x0is(x0ir);
00192 if (x0is.min() < 0 || x0is.max() >= _x1size)
00193 return false;
00194 for (int j=0; j<_x1size; j++) {
00195 CountableSetRanges x1ir(x.lub, x[_x0size+j]);
00196 IntSet x1is(x1ir);
00197 if (x1is.min() < 0 || x1is.max() >= _x0size)
00198 return false;
00199 bool jInI = x0is.in(j);
00200 bool iInJ = x1is.in(i);
00201 if (jInI != iInJ)
00202 return false;
00203 }
00204 }
00205 return true;
00206 }
00208 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00209 SetVarArgs x0(x.slice(0,1,_x0size));
00210 SetVarArgs x1(x.slice(_x0size));
00211 Gecode::channel(home, x0,x1);
00212 }
00213 };
00214
00215 ChannelSet _channelSet12("Channel::Set::1::2", d1, 2,2);
00216 ChannelSet _channelSet13("Channel::Set::1::3", d1, 2,3);
00217 ChannelSet _channelSet22("Channel::Set::2::2", d3, 2,2);
00218 ChannelSet _channelSet23("Channel::Set::2::3", d3, 2,3);
00219 ChannelSet _channelSet32("Channel::Set::3::2", d_12, 2,2);
00220 ChannelSet _channelSet33("Channel::Set::3::3", d_12, 2,3);
00221
00222 }}}
00223
00224