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 #include <gecode/scheduling.hh>
00042
00043 namespace Test { namespace Int {
00044
00046 namespace Unary {
00047
00053
00054 class ManFixUnary : public Test {
00055 protected:
00057 Gecode::IntArgs p;
00059 static int st(const Gecode::IntArgs& p) {
00060 int t = 0;
00061 for (int i=p.size(); i--; )
00062 t += p[i];
00063 return t;
00064 }
00065 public:
00067 ManFixUnary(const Gecode::IntArgs& p0, int o)
00068 : Test("Scheduling::Unary::Man::Fix::"+str(o)+"::"+str(p0),
00069 p0.size(),o,o+st(p0)),
00070 p(p0) {
00071 testsearch = false;
00072 contest = CTL_NONE;
00073 }
00075 virtual Assignment* assignment(void) const {
00076 return new RandomAssignment(arity,dom,500);
00077 }
00079 virtual bool solution(const Assignment& x) const {
00080 for (int i=0; i<x.size(); i++)
00081 for (int j=i+1; j<x.size(); j++)
00082 if ((x[i]+p[i] > x[j]) && (x[j]+p[j] > x[i]))
00083 return false;
00084 return true;
00085 }
00087 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00088 Gecode::unary(home, x, p);
00089 }
00090 };
00091
00093 class OptFixUnary : public Test {
00094 protected:
00096 Gecode::IntArgs p;
00098 int l;
00100 static int st(const Gecode::IntArgs& p) {
00101 int t = 0;
00102 for (int i=p.size(); i--; )
00103 t += p[i];
00104 return t;
00105 }
00106 public:
00108 OptFixUnary(const Gecode::IntArgs& p0, int o)
00109 : Test("Scheduling::Unary::Opt::Fix::"+str(o)+"::"+str(p0),
00110 2*p0.size(),o,o+st(p0)), p(p0), l(o+st(p)/2) {
00111 testsearch = false;
00112 contest = CTL_NONE;
00113 }
00115 virtual Assignment* assignment(void) const {
00116 return new RandomAssignment(arity,dom,500);
00117 }
00119 virtual bool solution(const Assignment& x) const {
00120 int n = x.size() / 2;
00121 for (int i=0; i<n; i++)
00122 if (x[n+i] > l)
00123 for (int j=i+1; j<n; j++)
00124 if(x[n+j] > l)
00125 if ((x[i]+p[i] > x[j]) && (x[j]+p[j] > x[i]))
00126 return false;
00127 return true;
00128 }
00130 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00131 int n=x.size() / 2;
00132 Gecode::IntVarArgs s(n);
00133 Gecode::BoolVarArgs m(n);
00134 for (int i=0; i<n; i++) {
00135 s[i]=x[i];
00136 m[i]=Gecode::post(home, ~(x[n+i] > l));
00137 }
00138 Gecode::unary(home, s, p, m);
00139 }
00140 };
00141
00142 Gecode::IntArgs p1(4, 2,2,2,2);
00143 ManFixUnary mfu10(p1,0);
00144 ManFixUnary mfu1i(p1,Gecode::Int::Limits::min);
00145 OptFixUnary ofu10(p1,0);
00146 OptFixUnary ofu1i(p1,Gecode::Int::Limits::min);
00147
00148 Gecode::IntArgs p2(4, 4,3,3,5);
00149 ManFixUnary mfu20(p2,0);
00150 ManFixUnary mfu2i(p2,Gecode::Int::Limits::min);
00151 OptFixUnary ofu20(p2,0);
00152 OptFixUnary ofu2i(p2,Gecode::Int::Limits::min);
00153
00154 Gecode::IntArgs p3(6, 4,2,9,3,7,5);
00155 ManFixUnary mfu30(p3,0);
00156 ManFixUnary mfu3i(p3,Gecode::Int::Limits::min);
00157 OptFixUnary ofu30(p3,0);
00158 OptFixUnary ofu3i(p3,Gecode::Int::Limits::min);
00159
00161
00162 }
00163 }}
00164
00165