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 <gecode/minimodel.hh>
00035 #include "test/int.hh"
00036
00037 namespace Test { namespace Int {
00038
00040 namespace NValues {
00041
00047
00048 class IntInt : public Test {
00049 protected:
00051 Gecode::IntRelType irt;
00053 int m;
00054 public:
00056 IntInt(int n, int m0, Gecode::IntRelType irt0)
00057 : Test("NValues::Int::Int::"+str(irt0)+"::"+str(n)+"::"+str(m0),
00058 n,0,n),
00059 irt(irt0), m(m0) {
00060 testfix = false;
00061 if (arity > 5)
00062 testsearch = false;
00063 }
00065 virtual Assignment* assignment(void) const {
00066 if (arity > 5)
00067 return new RandomAssignment(arity,dom,500);
00068 else
00069 return new CpltAssignment(arity,dom);
00070 }
00072 virtual bool solution(const Assignment& x) const {
00073 int n = x.size();
00074 bool* v = new bool[n+1];
00075 for (int i=n+1; i--; )
00076 v[i] = false;
00077 int k = 0;
00078 for (int i=n; i--; )
00079 if (!v[x[i]]) {
00080 k++;
00081 v[x[i]] = true;
00082 }
00083 delete [] v;
00084 return cmp(k,irt,m);
00085 }
00087 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00088 Gecode::nvalues(home, x, irt, m);
00089 }
00090 };
00091
00093 class IntVar : public Test {
00094 protected:
00096 Gecode::IntRelType irt;
00097 public:
00099 IntVar(int n, Gecode::IntRelType irt0)
00100 : Test("NValues::Int::Var::"+str(irt0)+"::"+str(n),n+1,0,n),
00101 irt(irt0) {
00102 testfix = false;
00103 }
00105 virtual bool solution(const Assignment& x) const {
00106 int n = x.size() - 1;
00107 bool* v = new bool[n+1];
00108 for (int i=n+1; i--; )
00109 v[i] = false;
00110 int k = 0;
00111 for (int i=n; i--; )
00112 if (!v[x[i]]) {
00113 k++;
00114 v[x[i]] = true;
00115 }
00116 delete [] v;
00117 return cmp(k,irt,x[n]);
00118 }
00120 virtual void post(Gecode::Space& home, Gecode::IntVarArray& xy) {
00121 int n = xy.size() - 1;
00122 Gecode::IntVarArgs x(n);
00123 for (int i=n; i--; )
00124 x[i] = xy[i];
00125 Gecode::nvalues(home, x, irt, xy[n]);
00126 }
00127 };
00128
00130 class BoolInt : public Test {
00131 protected:
00133 Gecode::IntRelType irt;
00135 int m;
00136 public:
00138 BoolInt(int n, int m0, Gecode::IntRelType irt0)
00139 : Test("NValues::Bool::Int::"+str(irt0)+"::"+str(n)+"::"+str(m0),
00140 n,0,2),
00141 irt(irt0), m(m0) {}
00143 virtual bool solution(const Assignment& x) const {
00144 int n = x.size();
00145 for (int i=n; i--; )
00146 if (x[i] > 1)
00147 return false;
00148 bool* v = new bool[n+1];
00149 for (int i=n+1; i--; )
00150 v[i] = false;
00151 int k = 0;
00152 for (int i=n; i--; )
00153 if (!v[x[i]]) {
00154 k++;
00155 v[x[i]] = true;
00156 }
00157 delete [] v;
00158 return cmp(k,irt,m);
00159 }
00161 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00162 using namespace Gecode;
00163 BoolVarArgs y(x.size());
00164 for (int i=x.size(); i--; )
00165 y[i] = channel(home, x[i]);
00166 nvalues(home, y, irt, m);
00167 }
00168 };
00169
00171 class BoolVar : public Test {
00172 protected:
00174 Gecode::IntRelType irt;
00175 public:
00177 BoolVar(int n, Gecode::IntRelType irt0)
00178 : Test("NValues::Bool::Var::"+str(irt0)+"::"+str(n),n+1,0,2),
00179 irt(irt0) {}
00181 virtual bool solution(const Assignment& x) const {
00182 int n = x.size() - 1;
00183 for (int i=n; i--; )
00184 if (x[i] > 1)
00185 return false;
00186 bool* v = new bool[n+1];
00187 for (int i=n+1; i--; )
00188 v[i] = false;
00189 int k = 0;
00190 for (int i=n; i--; )
00191 if (!v[x[i]]) {
00192 k++;
00193 v[x[i]] = true;
00194 }
00195 delete [] v;
00196 return cmp(k,irt,x[n]);
00197 }
00199 virtual void post(Gecode::Space& home, Gecode::IntVarArray& xy) {
00200 using namespace Gecode;
00201 int n = xy.size() - 1;
00202 BoolVarArgs x(n);
00203 for (int i=n; i--; )
00204 x[i] = channel(home, xy[i]);
00205 nvalues(home, x, irt, xy[n]);
00206 }
00207 };
00208
00210 class Create {
00211 public:
00213 Create(void) {
00214 for (IntRelTypes irts; irts(); ++irts) {
00215 for (int i=1; i<=7; i += 3) {
00216 for (int m=0; m<=3; m++)
00217 (void) new BoolInt(i, m, irts.irt());
00218 (void) new BoolVar(i, irts.irt());
00219 }
00220 for (int i=1; i<=7; i += 2) {
00221 for (int m=0; m<=i+1; m++)
00222 (void) new IntInt(i, m, irts.irt());
00223 if (i <= 5)
00224 (void) new IntVar(i, irts.irt());
00225 }
00226 }
00227 }
00228 };
00229
00230 Create c;
00232
00233 }
00234 }}
00235
00236
00237