unshare.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 #include "test/int.hh"
00035
00036 #include <gecode/minimodel.hh>
00037
00038 namespace Test { namespace Int {
00039
00041 namespace Unshare {
00042
00048
00049 class Int : public Test {
00050 public:
00052 Int(Gecode::IntPropLevel ipl)
00053 : Test("Unshare::Int::"+str(ipl),9,-1,1,false,ipl) {}
00055 virtual bool solution(const Assignment& x) const {
00056 return ((x[0] == x[3]) &&
00057 (x[1] == x[4]) && (x[1] == x[6]) &&
00058 (x[2] == x[5]) && (x[2] == x[7]) && (x[2] == x[8]));
00059 }
00061 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00062 using namespace Gecode;
00063 IntVarArgs y(6);
00064 y[0]=x[0]; y[1]=y[3]=x[1]; y[2]=y[4]=y[5]=x[2];
00065 unshare(home, y, ipl);
00066 for (int i=0; i<6; i++)
00067 rel(home, y[i], IRT_EQ, x[3+i], IPL_DOM);
00068 }
00069 };
00070
00072 class Bool : public Test {
00073 public:
00075 Bool(void)
00076 : Test("Unshare::Bool",9,0,1,false) {}
00078 virtual bool solution(const Assignment& x) const {
00079 return ((x[0] == x[3]) &&
00080 (x[1] == x[4]) && (x[1] == x[6]) &&
00081 (x[2] == x[5]) && (x[2] == x[7]) && (x[2] == x[8]));
00082 }
00084 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00085 using namespace Gecode;
00086 BoolVarArgs y(6);
00087 y[0]=channel(home,x[0]);
00088 y[1]=y[3]=channel(home,x[1]);
00089 y[2]=y[4]=y[5]=channel(home,x[2]);
00090 unshare(home, y);
00091 for (int i=0; i<6; i++)
00092 rel(home, y[i], IRT_EQ, channel(home,x[3+i]));
00093 }
00094 };
00095
00097 class Failed : public Test {
00098 public:
00100 Failed(void)
00101 : Test("Unshare::Failed",1,-1,1) {}
00103 virtual bool solution(const Assignment& x) const {
00104 (void) x;
00105 return false;
00106 }
00108 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00109 using namespace Gecode;
00110 home.fail();
00111 IntVarArgs y(2);
00112 y[0]=x[0]; y[1]=x[0];
00113 unshare(home, y);
00114 REG r(1);
00115 extensional(home, y, r);
00116 }
00117 };
00118
00119 Int i_bnd(Gecode::IPL_BND);
00120 Int i_dom(Gecode::IPL_DOM);
00121
00122 Bool b;
00123
00124 Failed f;
00126
00127 }
00128 }}
00129
00130