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 #include <gecode/graph.hh>
00040
00041 namespace Test { namespace Int {
00042
00044 namespace Circuit {
00045
00051
00052 class Circuit : public Test {
00053 public:
00055 Circuit(int n, int min, int max, Gecode::IntConLevel icl)
00056 : Test("Circuit::" + str(icl) + "::" + str(n),
00057 n,min,max,false,icl) {
00058 contest = CTL_NONE;
00059 }
00061 virtual bool solution(const Assignment& x) const {
00062 for (int i=x.size(); i--; )
00063 if ((x[i] < 0) || (x[i] > x.size()-1))
00064 return false;
00065 int reachable = 0;
00066 {
00067 int j=0;
00068 for (int i=x.size(); i--; ) {
00069 j=x[j]; reachable |= (1 << j);
00070 }
00071 }
00072 for (int i=x.size(); i--; )
00073 if (!(reachable & (1 << i)))
00074 return false;
00075 return true;
00076 }
00078 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00079 Gecode::circuit(home, x, icl);
00080 }
00081 };
00082
00084 class CircuitCost : public Test {
00085 public:
00087 CircuitCost(int n, int min, int max, Gecode::IntConLevel icl)
00088 : Test("Circuit::Cost::" + str(icl) + "::" + str(n),
00089 n+1,min,max,false,icl) {
00090 contest = CTL_NONE;
00091 }
00093 virtual bool solution(const Assignment& x) const {
00094 int n=x.size()-1;
00095 for (int i=n; i--; )
00096 if ((x[i] < 0) || (x[i] > n-1))
00097 return false;
00098 int reachable = 0;
00099 {
00100 int j=0;
00101 for (int i=n; i--; ) {
00102 j=x[j]; reachable |= (1 << j);
00103 }
00104 }
00105 for (int i=n; i--; )
00106 if (!(reachable & (1 << i)))
00107 return false;
00108 int c=0;
00109 for (int i=n; i--; )
00110 c += x[i];
00111 return c == x[n];
00112 }
00114 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00115 using namespace Gecode;
00116 int n=x.size()-1;
00117 IntArgs c(n*n);
00118 for (int i=0; i<n; i++)
00119 for (int j=0; j<n; j++)
00120 c[i*n+j]=j;
00121 IntVarArgs y(n);
00122 for (int i=0; i<n; i++)
00123 y[i]=x[i];
00124 circuit(home, c, y, x[n], icl);
00125 }
00126 };
00127
00129 class CircuitFullCost : public Test {
00130 public:
00132 CircuitFullCost(int n, int min, int max, Gecode::IntConLevel icl)
00133 : Test("Circuit::FullCost::" + str(icl) + "::" + str(n),
00134 2*n+1,min,max,false,icl) {
00135 contest = CTL_NONE;
00136 }
00138 virtual bool solution(const Assignment& x) const {
00139 int n=(x.size()-1) / 2;
00140 for (int i=n; i--; )
00141 if ((x[i] < 0) || (x[i] > n-1))
00142 return false;
00143 int reachable = 0;
00144 {
00145 int j=0;
00146 for (int i=n; i--; ) {
00147 j=x[j]; reachable |= (1 << j);
00148 }
00149 }
00150 for (int i=n; i--; )
00151 if (!(reachable & (1 << i)))
00152 return false;
00153 for (int i=n; i--; )
00154 if ((x[i]/2) != x[n+i])
00155 return false;
00156 int c=0;
00157 for (int i=n; i--; )
00158 c += x[n+i];
00159 return c == x[2*n];
00160 }
00162 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00163 using namespace Gecode;
00164 int n=(x.size()-1)/2;
00165 IntArgs c(n*n);
00166 for (int i=0; i<n; i++)
00167 for (int j=0; j<n; j++)
00168 c[i*n+j]=(j/2);
00169 IntVarArgs y(n), z(n);
00170 for (int i=0; i<n; i++) {
00171 y[i]=x[i]; z[i]=x[n+i];
00172 }
00173 circuit(home, c, y, z, x[2*n], icl);
00174 }
00175 };
00176
00178 class Create {
00179 public:
00181 Create(void) {
00182 for (int i=1; i<=6; i++) {
00183 (void) new Circuit(i,0,i-1,Gecode::ICL_VAL);
00184 (void) new Circuit(i,0,i-1,Gecode::ICL_DOM);
00185 }
00186 (void) new CircuitCost(4,0,9,Gecode::ICL_VAL);
00187 (void) new CircuitCost(4,0,9,Gecode::ICL_DOM);
00188 (void) new CircuitFullCost(3,0,3,Gecode::ICL_VAL);
00189 (void) new CircuitFullCost(3,0,3,Gecode::ICL_DOM);
00190 }
00191 };
00192
00193 Create c;
00195
00196 }
00197 }}
00198
00199