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 {
00044 namespace Unary {}
00045 }}
00046
00047 namespace Test { namespace Int { namespace Unary {
00048
00054
00055 class ManFixPUnary : public Test {
00056 protected:
00058 Gecode::IntArgs p;
00060 static int st(const Gecode::IntArgs& p) {
00061 int t = 0;
00062 for (int i=p.size(); i--; )
00063 t += p[i];
00064 return t;
00065 }
00066 public:
00068 ManFixPUnary(const Gecode::IntArgs& p0, int o, Gecode::IntPropLevel ipl0)
00069 : Test("Unary::Man::Fix::"+str(o)+"::"+str(p0)+"::"+str(ipl0),
00070 p0.size(),o,o+st(p0),false,ipl0),
00071 p(p0) {
00072 testsearch = false;
00073 contest = CTL_NONE;
00074 }
00076 virtual Assignment* assignment(void) const {
00077 return new RandomAssignment(arity,dom,500);
00078 }
00080 virtual bool solution(const Assignment& x) const {
00081 for (int i=0; i<x.size(); i++)
00082 for (int j=i+1; j<x.size(); j++)
00083 if ((x[i]+p[i] > x[j]) && (x[j]+p[j] > x[i]))
00084 return false;
00085 return true;
00086 }
00088 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00089 Gecode::unary(home, x, p, ipl);
00090 }
00091 };
00092
00094 class OptFixPUnary : public Test {
00095 protected:
00097 Gecode::IntArgs p;
00099 int l;
00101 static int st(const Gecode::IntArgs& p) {
00102 int t = 0;
00103 for (int i=p.size(); i--; )
00104 t += p[i];
00105 return t;
00106 }
00107 public:
00109 OptFixPUnary(const Gecode::IntArgs& p0, int o, Gecode::IntPropLevel ipl0)
00110 : Test("Unary::Opt::Fix::"+str(o)+"::"+str(p0)+"::"+str(ipl0),
00111 2*p0.size(),o,o+st(p0),false,ipl0), p(p0), l(o+st(p)/2) {
00112 testsearch = false;
00113 contest = CTL_NONE;
00114 }
00116 virtual Assignment* assignment(void) const {
00117 return new RandomAssignment(arity,dom,500);
00118 }
00120 virtual bool solution(const Assignment& x) const {
00121 int n = x.size() / 2;
00122 for (int i=0; i<n; i++)
00123 if (x[n+i] > l)
00124 for (int j=i+1; j<n; j++)
00125 if(x[n+j] > l)
00126 if ((x[i]+p[i] > x[j]) && (x[j]+p[j] > x[i]))
00127 return false;
00128 return true;
00129 }
00131 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00132 int n=x.size() / 2;
00133 Gecode::IntVarArgs s(n);
00134 Gecode::BoolVarArgs m(n);
00135 for (int i=0; i<n; i++) {
00136 s[i]=x[i];
00137 m[i]=Gecode::expr(home, (x[n+i] > l));
00138 }
00139 Gecode::unary(home, s, p, m, ipl);
00140 }
00141 };
00142
00144 class ManFlexUnary : public Test {
00145 protected:
00147 int _minP;
00149 int _maxP;
00151 int off;
00152 public:
00154 ManFlexUnary(int n, int minP, int maxP, int o, Gecode::IntPropLevel ipl0)
00155 : Test("Unary::Man::Flex::"+str(o)+"::"+str(n)+"::"
00156 +str(minP)+"::"+str(maxP)+"::"+str(ipl0),
00157 2*n,0,n*maxP,false,ipl0), _minP(minP), _maxP(maxP), off(o) {
00158 testsearch = false;
00159 testfix = false;
00160 contest = CTL_NONE;
00161 }
00163 virtual Assignment* assignment(void) const {
00164 return new RandomMixAssignment(arity/2,dom,arity/2,
00165 Gecode::IntSet(_minP,_maxP),500);
00166 }
00168 virtual bool solution(const Assignment& x) const {
00169 int n = x.size()/2;
00170 for (int i=0; i<n; i++)
00171 for (int j=i+1; j<n; j++)
00172 if ((x[i]+x[n+i] > x[j]) && (x[j]+x[n+j] > x[i]))
00173 return false;
00174 return true;
00175 }
00177 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00178 Gecode::IntVarArgs s(x.size()/2);
00179 Gecode::IntVarArgs px(x.slice(x.size()/2));
00180 Gecode::IntVarArgs e(home,x.size()/2,
00181 Gecode::Int::Limits::min,
00182 Gecode::Int::Limits::max);
00183 for (int i=s.size(); i--;) {
00184 s[i] = expr(home, off+x[i]);
00185 rel(home, s[i]+px[i] == e[i]);
00186 rel(home, _minP <= px[i]);
00187 rel(home, _maxP >= px[i]);
00188 }
00189 Gecode::unary(home, s, px, e, ipl);
00190 }
00191 };
00192
00194 class OptFlexUnary : public Test {
00195 protected:
00197 int _minP;
00199 int _maxP;
00201 int off;
00203 int l;
00205 static int st(const Gecode::IntArgs& p) {
00206 int t = 0;
00207 for (int i=p.size(); i--; )
00208 t += p[i];
00209 return t;
00210 }
00211 public:
00213 OptFlexUnary(int n, int minP, int maxP, int o, Gecode::IntPropLevel ipl0)
00214 : Test("Unary::Opt::Flex::"+str(o)+"::"+str(n)+"::"
00215 +str(minP)+"::"+str(maxP)+"::"+str(ipl0),
00216 3*n,0,n*maxP,false,ipl0), _minP(minP), _maxP(maxP), off(o),
00217 l(n*maxP/2) {
00218 testsearch = false;
00219 testfix = false;
00220 contest = CTL_NONE;
00221 }
00223 virtual Assignment* assignment(void) const {
00224 return new RandomMixAssignment(2*(arity/3),dom,arity/3,
00225 Gecode::IntSet(_minP,_maxP),500);
00226 }
00228 virtual bool solution(const Assignment& x) const {
00229 int n = x.size() / 3;
00230 for (int i=0; i<n; i++)
00231 if (x[n+i] > l)
00232 for (int j=i+1; j<n; j++)
00233 if(x[n+j] > l)
00234 if ((x[i]+x[2*n+i] > x[j]) && (x[j]+x[2*n+j] > x[i]))
00235 return false;
00236 return true;
00237 }
00239 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00240 int n=x.size() / 3;
00241
00242 Gecode::IntVarArgs s(n);
00243 Gecode::IntVarArgs px(n);
00244 Gecode::IntVarArgs e(home,n,
00245 Gecode::Int::Limits::min,
00246 Gecode::Int::Limits::max);
00247 for (int i=n; i--;) {
00248 s[i] = expr(home, off+x[i]);
00249 px[i] = x[2*n+i];
00250 rel(home, s[i]+px[i] == e[i]);
00251 rel(home, _minP <= px[i]);
00252 rel(home, _maxP >= px[i]);
00253 }
00254 Gecode::BoolVarArgs m(n);
00255 for (int i=0; i<n; i++)
00256 m[i]=Gecode::expr(home, (x[n+i] > l));
00257 Gecode::unary(home, s, px, e, m, ipl);
00258 }
00259 };
00260
00262 class Create {
00263 public:
00265 Create(void) {
00266 using namespace Gecode;
00267 IntArgs p1(4, 2,2,2,2);
00268 IntArgs p10(5, 2,2,0,2,2);
00269 IntArgs p2(4, 4,3,3,5);
00270 IntArgs p20(6, 4,0,3,3,0,5);
00271 IntArgs p3(6, 4,2,9,3,7,5);
00272 IntArgs p30(8, 4,0,2,9,3,7,5,0);
00273
00274 for (IntPropBasicAdvanced ipba; ipba(); ++ipba) {
00275 (void) new ManFixPUnary(p1,0,ipba.ipl());
00276 (void) new ManFixPUnary(p1,Gecode::Int::Limits::min,ipba.ipl());
00277 (void) new OptFixPUnary(p1,0,ipba.ipl());
00278 (void) new OptFixPUnary(p1,Gecode::Int::Limits::min,ipba.ipl());
00279 (void) new ManFlexUnary(4,0,2,0,ipba.ipl());
00280 (void) new ManFlexUnary(4,0,2,Gecode::Int::Limits::min,ipba.ipl());
00281 (void) new ManFlexUnary(4,1,3,0,ipba.ipl());
00282 (void) new ManFlexUnary(4,1,3,Gecode::Int::Limits::min,ipba.ipl());
00283 (void) new OptFlexUnary(4,0,2,0,ipba.ipl());
00284 (void) new OptFlexUnary(4,0,2,Gecode::Int::Limits::min,ipba.ipl());
00285
00286 (void) new ManFixPUnary(p10,0,ipba.ipl());
00287 (void) new ManFixPUnary(p10,Gecode::Int::Limits::min,ipba.ipl());
00288 (void) new OptFixPUnary(p10,0,ipba.ipl());
00289 (void) new OptFixPUnary(p10,Gecode::Int::Limits::min,ipba.ipl());
00290 (void) new ManFlexUnary(5,0,2,0,ipba.ipl());
00291 (void) new ManFlexUnary(5,0,2,Gecode::Int::Limits::min,ipba.ipl());
00292 (void) new OptFlexUnary(5,0,2,0,ipba.ipl());
00293 (void) new OptFlexUnary(5,0,2,Gecode::Int::Limits::min,ipba.ipl());
00294
00295 (void) new ManFixPUnary(p2,0,ipba.ipl());
00296 (void) new ManFixPUnary(p2,Gecode::Int::Limits::min,ipba.ipl());
00297 (void) new OptFixPUnary(p2,0,ipba.ipl());
00298 (void) new OptFixPUnary(p2,Gecode::Int::Limits::min,ipba.ipl());
00299 (void) new ManFlexUnary(4,3,5,0,ipba.ipl());
00300 (void) new ManFlexUnary(4,3,5,Gecode::Int::Limits::min,ipba.ipl());
00301 (void) new OptFlexUnary(4,3,5,0,ipba.ipl());
00302 (void) new OptFlexUnary(4,3,5,Gecode::Int::Limits::min,ipba.ipl());
00303
00304 (void) new ManFixPUnary(p20,0,ipba.ipl());
00305 (void) new ManFixPUnary(p20,Gecode::Int::Limits::min,ipba.ipl());
00306 (void) new OptFixPUnary(p20,0,ipba.ipl());
00307 (void) new OptFixPUnary(p20,Gecode::Int::Limits::min,ipba.ipl());
00308 (void) new ManFlexUnary(6,0,5,0,ipba.ipl());
00309 (void) new ManFlexUnary(6,0,5,Gecode::Int::Limits::min,ipba.ipl());
00310 (void) new OptFlexUnary(6,0,5,0,ipba.ipl());
00311 (void) new OptFlexUnary(6,0,5,Gecode::Int::Limits::min,ipba.ipl());
00312
00313 (void) new ManFixPUnary(p3,0,ipba.ipl());
00314 (void) new ManFixPUnary(p3,Gecode::Int::Limits::min,ipba.ipl());
00315 (void) new OptFixPUnary(p3,0,ipba.ipl());
00316 (void) new OptFixPUnary(p3,Gecode::Int::Limits::min,ipba.ipl());
00317 (void) new ManFlexUnary(6,2,7,0,ipba.ipl());
00318 (void) new ManFlexUnary(6,2,7,Gecode::Int::Limits::min,ipba.ipl());
00319 (void) new OptFlexUnary(6,2,7,0,ipba.ipl());
00320 (void) new OptFlexUnary(6,2,7,Gecode::Int::Limits::min,ipba.ipl());
00321
00322 (void) new ManFixPUnary(p30,0,ipba.ipl());
00323 (void) new ManFixPUnary(p30,Gecode::Int::Limits::min,ipba.ipl());
00324 (void) new OptFixPUnary(p30,0,ipba.ipl());
00325 (void) new OptFixPUnary(p30,Gecode::Int::Limits::min,ipba.ipl());
00326 (void) new ManFlexUnary(8,0,9,0,ipba.ipl());
00327 (void) new ManFlexUnary(8,0,9,Gecode::Int::Limits::min,ipba.ipl());
00328 (void) new OptFlexUnary(8,0,9,0,ipba.ipl());
00329 (void) new OptFlexUnary(8,0,9,Gecode::Int::Limits::min,ipba.ipl());
00330 }
00331 }
00332 };
00333
00334 Create c;
00336
00337
00338 }}}
00339
00340