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