exec.cpp
Go to the documentation of this file.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 {
00043
00045 namespace Exec {
00046
00052
00053 class IntWait : public Test {
00054 public:
00056 IntWait(int n)
00057 : Test("Wait::Int::"+str(n),n,0,n,false) {}
00059 virtual bool solution(const Assignment& x) const {
00060 for (int i=0; i<x.size(); i++)
00061 for (int j=i+1; j<x.size(); j++)
00062 if (x[i] == x[j])
00063 return false;
00064 return true;
00065 }
00067 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00068 if (x.size() > 1)
00069 Gecode::wait(home, x, &c);
00070 else
00071 Gecode::wait(home, x[0], &c);
00072 }
00074 static void c(Gecode::Space& _home) {
00075 TestSpace& home = static_cast<TestSpace&>(_home);
00076 for (int i=0; i<home.x.size(); i++)
00077 for (int j=i+1; j<home.x.size(); j++)
00078 if (home.x[i].val() == home.x[j].val())
00079 home.fail();
00080 }
00081 };
00082
00084 class BoolWait : public Test {
00085 public:
00087 BoolWait(int n)
00088 : Test("Wait::Bool::"+str(n),n,0,1,false) {}
00090 virtual bool solution(const Assignment& x) const {
00091 int t=0;
00092 for (int i=0; i<x.size(); i++)
00093 t += x[i];
00094 return t==2;
00095 }
00097 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00098 Gecode::BoolVarArgs b(x.size());
00099 for (int i=b.size(); i--; )
00100 b[i]=Gecode::channel(home,x[i]);
00101 if (b.size() > 1)
00102 Gecode::wait(home, b, &c);
00103 else
00104 Gecode::wait(home, b[0], &c);
00105 }
00107 static void c(Gecode::Space& _home) {
00108 TestSpace& home = static_cast<TestSpace&>(_home);
00109 int t=0;
00110 for (int i=0; i<home.x.size(); i++)
00111 t += home.x[i].val();
00112 if (t!=2)
00113 home.fail();
00114 }
00115 };
00116
00118 class When : public Test {
00119 public:
00121 When(void) : Test("When",1,0,1,false) {}
00123 virtual bool solution(const Assignment& x) const {
00124 return x[0]==0;
00125 }
00127 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00128 Gecode::when(home, Gecode::channel(home, x[0]), &t, &e);
00129 }
00131 static void t(Gecode::Space& home) {
00132 home.fail();
00133 }
00135 static void e(Gecode::Space& home) {
00136 (void) home;
00137 }
00138 };
00139
00140 IntWait iw1(1), iw2(2), iw3(3), iw4(4);
00141 BoolWait bw1(1), bw2(2), bw3(3), bw4(4);
00142
00143 When when;
00145
00146 }
00147
00148 }}
00149
00150