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 public:
00056 ChannelFull(Gecode::IntConLevel icl)
00057 : Test("Channel::Full::"+str(icl),8,0,3,false,icl) {}
00059 virtual bool solution(const Assignment& x) const {
00060 for (int i=0; i<4; i++)
00061 if (x[4+x[i]] != i)
00062 return false;
00063 return true;
00064 }
00066 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00067 using namespace Gecode;
00068 IntVarArgs xa(4); IntVarArgs ya(4);
00069 for (int i=4; i--; ) {
00070 xa[i] = x[i]; ya[i] = x[4+i];
00071 }
00072 channel(home, xa, ya, icl);
00073 }
00074 };
00075
00077 class ChannelHalf : public Test {
00078 public:
00080 ChannelHalf(Gecode::IntConLevel icl)
00081 : Test("Channel::Half::"+str(icl),6,0,5,false,icl) {}
00083 virtual bool solution(const Assignment& x) const {
00084 for (int i=0; i<6; i++)
00085 for (int j=i+1; j<6; j++)
00086 if (x[i] == x[j])
00087 return false;
00088 return true;
00089 }
00091 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00092 using namespace Gecode;
00093 Gecode::IntVarArgs y(6);
00094 for (int i=0; i<6; i++)
00095 y[i].init(home,dom);
00096 for (int i=0; i<6; i++)
00097 for (int j=0; j<6; j++) {
00098 Gecode::BoolVar b(home,0,1);
00099 rel(home, x[i], Gecode::IRT_EQ, j, b);
00100 rel(home, y[j], Gecode::IRT_EQ, i, b);
00101 }
00102 channel(home, x, y, icl);
00103 }
00104 };
00105
00107 class ChannelShared : public Test {
00108 public:
00110 ChannelShared(Gecode::IntConLevel icl)
00111 : Test("Channel::Shared::"+str(icl),6,0,5,false,icl) {
00112 testdomcon = false;
00113 }
00115 virtual bool solution(const Assignment& x) const {
00116 for (int i=0; i<6; i++)
00117 if (x[x[i]] != i)
00118 return false;
00119 return true;
00120 }
00122 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00123 using namespace Gecode;
00124 channel(home, x, x, icl);
00125 }
00126 };
00127
00129 class ChannelLinkSingle : public Test {
00130 public:
00132 ChannelLinkSingle(void)
00133 : Test("Channel::Bool::Single",2,-1,2) {
00134 testdomcon = false;
00135 }
00137 virtual bool solution(const Assignment& x) const {
00138 return ((x[0]==0) || (x[0]==1)) && (x[0]==x[1]);
00139 }
00141 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00142 using namespace Gecode;
00143 Gecode::BoolVar b(home,0,1);
00144 channel(home, x[0], b);
00145 channel(home, x[1], b);
00146 }
00147 };
00148
00150 class ChannelLinkMulti : public Test {
00151 private:
00152 int o;
00153 public:
00155 ChannelLinkMulti(const std::string& s, int min, int max, int o0)
00156 : Test("Channel::Bool::Multi::"+s,7,min,max), o(o0) {
00157 testdomcon = false;
00158 }
00160 virtual bool solution(const Assignment& x) const {
00161 int n = x.size()-1;
00162 for (int i=n; i--; )
00163 if ((x[i] != 0) && (x[i] != 1))
00164 return false;
00165 int k=x[n]-o;
00166 if ((k<0) || (k>=n))
00167 return false;
00168 for (int i=0; i<k; i++)
00169 if (x[i] != 0)
00170 return false;
00171 for (int i=k+1; i<n; i++)
00172 if (x[i] != 0)
00173 return false;
00174 return x[k] == 1;
00175 }
00177 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00178 using namespace Gecode;
00179 int n=x.size()-1;
00180 Gecode::BoolVarArgs b(n);
00181 for (int i=n; i--; )
00182 b[i]=channel(home,x[i]);
00183 channel(home, b, x[n], o);
00184 }
00185 };
00186
00187
00188
00189 ChannelFull cfd(Gecode::ICL_DOM);
00190 ChannelFull cfv(Gecode::ICL_VAL);
00191
00192 ChannelHalf chd(Gecode::ICL_DOM);
00193 ChannelHalf chv(Gecode::ICL_VAL);
00194
00195 ChannelShared csd(Gecode::ICL_DOM);
00196 ChannelShared csv(Gecode::ICL_VAL);
00197
00198 ChannelLinkSingle cls;
00199
00200 ChannelLinkMulti clma("A", 0, 5, 0);
00201 ChannelLinkMulti clmb("B", 1, 6, 1);
00202 ChannelLinkMulti clmc("C",-1, 4,-1);
00204
00205 }
00206 }}
00207
00208
00209