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/int.hh"
00039
00040 #include "gecode/minimodel.hh"
00041
00042 namespace Test { namespace Int {
00043
00045 namespace Channel {
00046
00052
00053 class ChannelFull : public Test {
00054 private:
00055 int xoff;
00056 int yoff;
00057 public:
00059 ChannelFull(Gecode::IntConLevel icl,
00060 unsigned int xoff0 = 0, unsigned int yoff0 = 0)
00061 : Test("Channel::Full::"+str(icl)+"::"+
00062 str(xoff0)+"::"+str(yoff0),8,0,3,false,icl),
00063 xoff(xoff0), yoff(yoff0) {
00064 testdomcon = false;
00065 }
00067 virtual bool solution(const Assignment& x) const {
00068 for (int i=0; i<4; i++)
00069 if (x[4+x[i]] != i)
00070 return false;
00071 return true;
00072 }
00074 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00075 using namespace Gecode;
00076 IntVarArgs xa(4); IntVarArgs ya(4);
00077 for (int i=4; i--; ) {
00078 if (xoff != 0) {
00079 IntVar xo(home, xoff, 3+xoff);
00080 Gecode::post(home, x[i] == xo-xoff);
00081 xa[i] = xo;
00082 } else {
00083 xa[i] = x[i];
00084 }
00085 if (yoff != 0) {
00086 IntVar yo(home, yoff, 3+yoff);
00087 Gecode::post(home, x[4+i] == yo-yoff);
00088 ya[i] = yo;
00089 } else {
00090 ya[i] = x[4+i];
00091 }
00092 }
00093 channel(home, xa, xoff, ya, yoff, icl);
00094 }
00095 };
00096
00098 class ChannelHalf : public Test {
00099 public:
00101 ChannelHalf(Gecode::IntConLevel icl)
00102 : Test("Channel::Half::"+str(icl),6,0,5,false,icl) {
00103 testdomcon = false;
00104 }
00106 virtual bool solution(const Assignment& x) const {
00107 for (int i=0; i<6; i++)
00108 for (int j=i+1; j<6; j++)
00109 if (x[i] == x[j])
00110 return false;
00111 return true;
00112 }
00114 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00115 using namespace Gecode;
00116 Gecode::IntVarArgs y(6);
00117 for (int i=0; i<6; i++)
00118 y[i].init(home,dom);
00119 for (int i=0; i<6; i++)
00120 for (int j=0; j<6; j++) {
00121 Gecode::BoolVar b(home,0,1);
00122 rel(home, x[i], Gecode::IRT_EQ, j, b);
00123 rel(home, y[j], Gecode::IRT_EQ, i, b);
00124 }
00125 channel(home, x, y, icl);
00126 }
00127 };
00128
00130 class ChannelShared : public Test {
00131 public:
00133 ChannelShared(Gecode::IntConLevel icl)
00134 : Test("Channel::Shared::"+str(icl),6,0,5,false,icl) {
00135 testdomcon = false;
00136 }
00138 virtual bool solution(const Assignment& x) const {
00139 for (int i=0; i<6; i++)
00140 if (x[x[i]] != i)
00141 return false;
00142 return true;
00143 }
00145 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00146 using namespace Gecode;
00147 channel(home, x, x, icl);
00148 }
00149 };
00150
00152 class ChannelLinkSingle : public Test {
00153 public:
00155 ChannelLinkSingle(void)
00156 : Test("Channel::Bool::Single",2,-1,2) {
00157 testdomcon = false;
00158 }
00160 virtual bool solution(const Assignment& x) const {
00161 return ((x[0]==0) || (x[0]==1)) && (x[0]==x[1]);
00162 }
00164 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00165 using namespace Gecode;
00166 Gecode::BoolVar b(home,0,1);
00167 channel(home, x[0], b);
00168 channel(home, x[1], b);
00169 }
00170 };
00171
00173 class ChannelLinkMulti : public Test {
00174 private:
00175 int o;
00176 public:
00178 ChannelLinkMulti(const std::string& s, int min, int max, int o0)
00179 : Test("Channel::Bool::Multi::"+s,7,min,max), o(o0) {
00180 testdomcon = false;
00181 }
00183 virtual bool solution(const Assignment& x) const {
00184 int n = x.size()-1;
00185 for (int i=n; i--; )
00186 if ((x[i] != 0) && (x[i] != 1))
00187 return false;
00188 int k=x[n]-o;
00189 if ((k<0) || (k>=n))
00190 return false;
00191 for (int i=0; i<k; i++)
00192 if (x[i] != 0)
00193 return false;
00194 for (int i=k+1; i<n; i++)
00195 if (x[i] != 0)
00196 return false;
00197 return x[k] == 1;
00198 }
00200 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00201 using namespace Gecode;
00202 int n=x.size()-1;
00203 Gecode::BoolVarArgs b(n);
00204 for (int i=n; i--; )
00205 b[i]=channel(home,x[i]);
00206 channel(home, b, x[n], o);
00207 }
00208 };
00209
00210
00211
00212 ChannelFull cfd(Gecode::ICL_DOM);
00213 ChannelFull cfv(Gecode::ICL_VAL);
00214
00215 ChannelFull cfd11(Gecode::ICL_DOM,1,1);
00216 ChannelFull cfv11(Gecode::ICL_VAL,1,1);
00217
00218 ChannelFull cfd35(Gecode::ICL_DOM,3,5);
00219 ChannelFull cfv35(Gecode::ICL_VAL,3,5);
00220
00221 ChannelHalf chd(Gecode::ICL_DOM);
00222 ChannelHalf chv(Gecode::ICL_VAL);
00223
00224 ChannelShared csd(Gecode::ICL_DOM);
00225 ChannelShared csv(Gecode::ICL_VAL);
00226
00227 ChannelLinkSingle cls;
00228
00229 ChannelLinkMulti clma("A", 0, 5, 0);
00230 ChannelLinkMulti clmb("B", 1, 6, 1);
00231 ChannelLinkMulti clmc("C",-1, 4,-1);
00233
00234 }
00235 }}
00236
00237
00238