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