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::rel(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::rel(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(home,6,dom);
00116 for (int i=0; i<6; i++)
00117 for (int j=0; j<6; j++) {
00118 Gecode::BoolVar b(home,0,1);
00119 rel(home, x[i], Gecode::IRT_EQ, j, b);
00120 rel(home, y[j], Gecode::IRT_EQ, i, b);
00121 }
00122 channel(home, x, y, icl);
00123 }
00124 };
00125
00127 class ChannelShared : public Test {
00128 public:
00130 ChannelShared(Gecode::IntConLevel icl)
00131 : Test("Channel::Shared::"+str(icl),6,0,5,false,icl) {
00132 contest = CTL_NONE;
00133 }
00135 virtual bool solution(const Assignment& x) const {
00136 for (int i=0; i<6; i++)
00137 if (x[x[i]] != i)
00138 return false;
00139 return true;
00140 }
00142 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00143 using namespace Gecode;
00144 channel(home, x, x, icl);
00145 }
00146 };
00147
00149 class ChannelLinkSingle : public Test {
00150 public:
00152 ChannelLinkSingle(void)
00153 : Test("Channel::Bool::Single",2,-1,2) {
00154 contest = CTL_NONE;
00155 }
00157 virtual bool solution(const Assignment& x) const {
00158 return ((x[0]==0) || (x[0]==1)) && (x[0]==x[1]);
00159 }
00161 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00162 using namespace Gecode;
00163 Gecode::BoolVar b(home,0,1);
00164 channel(home, x[0], b);
00165 channel(home, x[1], b);
00166 }
00167 };
00168
00170 class ChannelLinkMulti : public Test {
00171 private:
00172 int o;
00173 public:
00175 ChannelLinkMulti(const std::string& s, int min, int max, int o0)
00176 : Test("Channel::Bool::Multi::"+s,7,min,max), o(o0) {
00177 }
00179 virtual bool solution(const Assignment& x) const {
00180 int n = x.size()-1;
00181 for (int i=n; i--; )
00182 if ((x[i] != 0) && (x[i] != 1))
00183 return false;
00184 int k=x[n]-o;
00185 if ((k<0) || (k>=n))
00186 return false;
00187 for (int i=0; i<k; i++)
00188 if (x[i] != 0)
00189 return false;
00190 for (int i=k+1; i<n; i++)
00191 if (x[i] != 0)
00192 return false;
00193 return x[k] == 1;
00194 }
00196 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00197 using namespace Gecode;
00198 int n=x.size()-1;
00199 Gecode::BoolVarArgs b(n);
00200 for (int i=n; i--; )
00201 b[i]=channel(home,x[i]);
00202 channel(home, b, x[n], o);
00203 }
00204 };
00205
00206
00207
00208 ChannelFull cfd(0,0,Gecode::ICL_DOM);
00209 ChannelFull cfv(0,0,Gecode::ICL_VAL);
00210
00211 ChannelFull cfd11(1,1,Gecode::ICL_DOM);
00212 ChannelFull cfv11(1,1,Gecode::ICL_VAL);
00213
00214 ChannelFull cfd35(3,5,Gecode::ICL_DOM);
00215 ChannelFull cfv35(3,5,Gecode::ICL_VAL);
00216
00217 ChannelHalf chd(Gecode::ICL_DOM);
00218 ChannelHalf chv(Gecode::ICL_VAL);
00219
00220 ChannelShared csd(Gecode::ICL_DOM);
00221 ChannelShared csv(Gecode::ICL_VAL);
00222
00223 ChannelLinkSingle cls;
00224
00225 ChannelLinkMulti clma("A", 0, 5, 0);
00226 ChannelLinkMulti clmb("B", 1, 6, 1);
00227 ChannelLinkMulti clmc("C",-1, 4,-1);
00229
00230 }
00231 }}
00232
00233
00234