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 <gecode/minimodel.hh>
00039 #include "test/int.hh"
00040
00041 namespace Test { namespace Int {
00042
00044 namespace NValues {
00045
00051
00052 class IntInt : public Test {
00053 protected:
00055 Gecode::IntRelType irt;
00057 int m;
00058 public:
00060 IntInt(int n, int m0, Gecode::IntRelType irt0)
00061 : Test("NValues::Int::Int::"+str(irt0)+"::"+str(n)+"::"+str(m0),
00062 n,0,n),
00063 irt(irt0), m(m0) {
00064 testfix = false;
00065 if (arity > 5)
00066 testsearch = false;
00067 }
00069 virtual Assignment* assignment(void) const {
00070 if (arity > 5)
00071 return new RandomAssignment(arity,dom,500);
00072 else
00073 return new CpltAssignment(arity,dom);
00074 }
00076 virtual bool solution(const Assignment& x) const {
00077 int n = x.size();
00078 bool* v = new bool[n+1];
00079 for (int i=n+1; i--; )
00080 v[i] = false;
00081 int k = 0;
00082 for (int i=n; i--; )
00083 if (!v[x[i]]) {
00084 k++;
00085 v[x[i]] = true;
00086 }
00087 delete [] v;
00088 return cmp(k,irt,m);
00089 }
00091 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00092 Gecode::nvalues(home, x, irt, m);
00093 }
00094 };
00095
00097 class IntVar : public Test {
00098 protected:
00100 Gecode::IntRelType irt;
00101 public:
00103 IntVar(int n, Gecode::IntRelType irt0)
00104 : Test("NValues::Int::Var::"+str(irt0)+"::"+str(n),n+1,0,n),
00105 irt(irt0) {
00106 testfix = false;
00107 }
00109 virtual bool solution(const Assignment& x) const {
00110 int n = x.size() - 1;
00111 bool* v = new bool[n+1];
00112 for (int i=n+1; i--; )
00113 v[i] = false;
00114 int k = 0;
00115 for (int i=n; i--; )
00116 if (!v[x[i]]) {
00117 k++;
00118 v[x[i]] = true;
00119 }
00120 delete [] v;
00121 return cmp(k,irt,x[n]);
00122 }
00124 virtual void post(Gecode::Space& home, Gecode::IntVarArray& xy) {
00125 int n = xy.size() - 1;
00126 Gecode::IntVarArgs x(n);
00127 for (int i=n; i--; )
00128 x[i] = xy[i];
00129 Gecode::nvalues(home, x, irt, xy[n]);
00130 }
00131 };
00132
00134 class BoolInt : public Test {
00135 protected:
00137 Gecode::IntRelType irt;
00139 int m;
00140 public:
00142 BoolInt(int n, int m0, Gecode::IntRelType irt0)
00143 : Test("NValues::Bool::Int::"+str(irt0)+"::"+str(n)+"::"+str(m0),
00144 n,0,2),
00145 irt(irt0), m(m0) {}
00147 virtual bool solution(const Assignment& x) const {
00148 int n = x.size();
00149 for (int i=n; i--; )
00150 if (x[i] > 1)
00151 return false;
00152 bool* v = new bool[n+1];
00153 for (int i=n+1; i--; )
00154 v[i] = false;
00155 int k = 0;
00156 for (int i=n; i--; )
00157 if (!v[x[i]]) {
00158 k++;
00159 v[x[i]] = true;
00160 }
00161 delete [] v;
00162 return cmp(k,irt,m);
00163 }
00165 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00166 using namespace Gecode;
00167 BoolVarArgs y(x.size());
00168 for (int i=x.size(); i--; )
00169 y[i] = channel(home, x[i]);
00170 nvalues(home, y, irt, m);
00171 }
00172 };
00173
00175 class BoolVar : public Test {
00176 protected:
00178 Gecode::IntRelType irt;
00179 public:
00181 BoolVar(int n, Gecode::IntRelType irt0)
00182 : Test("NValues::Bool::Var::"+str(irt0)+"::"+str(n),n+1,0,2),
00183 irt(irt0) {}
00185 virtual bool solution(const Assignment& x) const {
00186 int n = x.size() - 1;
00187 for (int i=n; i--; )
00188 if (x[i] > 1)
00189 return false;
00190 bool* v = new bool[n+1];
00191 for (int i=n+1; i--; )
00192 v[i] = false;
00193 int k = 0;
00194 for (int i=n; i--; )
00195 if (!v[x[i]]) {
00196 k++;
00197 v[x[i]] = true;
00198 }
00199 delete [] v;
00200 return cmp(k,irt,x[n]);
00201 }
00203 virtual void post(Gecode::Space& home, Gecode::IntVarArray& xy) {
00204 using namespace Gecode;
00205 int n = xy.size() - 1;
00206 BoolVarArgs x(n);
00207 for (int i=n; i--; )
00208 x[i] = channel(home, xy[i]);
00209 nvalues(home, x, irt, xy[n]);
00210 }
00211 };
00212
00214 class Create {
00215 public:
00217 Create(void) {
00218 for (IntRelTypes irts; irts(); ++irts) {
00219 for (int i=1; i<=7; i += 3) {
00220 for (int m=0; m<=3; m++)
00221 (void) new BoolInt(i, m, irts.irt());
00222 (void) new BoolVar(i, irts.irt());
00223 }
00224 for (int i=1; i<=7; i += 2) {
00225 for (int m=0; m<=i+1; m++)
00226 (void) new IntInt(i, m, irts.irt());
00227 if (i <= 5)
00228 (void) new IntVar(i, irts.irt());
00229 }
00230 }
00231 }
00232 };
00233
00234 Create c;
00236
00237 }
00238 }}
00239
00240
00241