member.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 <gecode/minimodel.hh>
00039 #include "test/int.hh"
00040
00041 namespace Test { namespace Int {
00042
00044 namespace Member {
00045
00051
00052 class Int : public Test {
00053 public:
00055 Int(int n) : Test("Member::Int::"+str(n),n+1,0,n,true) {}
00057 virtual bool solution(const Assignment& x) const {
00058 int n = x.size() - 1;
00059 for (int i=n; i--; )
00060 if (x[i] == x[n])
00061 return true;
00062 return false;
00063 }
00065 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00066 using namespace Gecode;
00067 int n = x.size() - 1;
00068 IntVarArgs y(n);
00069 for (int i=n; i--; )
00070 y[i] = x[i];
00071 member(home, y, x[n]);
00072 }
00074 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00075 Gecode::Reify r) {
00076 using namespace Gecode;
00077 int n = x.size() - 1;
00078 IntVarArgs y(n);
00079 for (int i=n; i--; )
00080 y[i] = x[i];
00081 member(home, y, x[n], r);
00082 }
00083 };
00084
00086 class Bool : public Test {
00087 public:
00089 Bool(int n) : Test("Member::Bool::"+str(n),n+1,0,1,true) {}
00091 virtual bool solution(const Assignment& x) const {
00092 int n = x.size() - 1;
00093 for (int i=n; i--; )
00094 if (x[i] == x[n])
00095 return true;
00096 return false;
00097 }
00099 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00100 using namespace Gecode;
00101 int n = x.size() - 1;
00102 BoolVarArgs y(n);
00103 for (int i=n; i--; )
00104 y[i] = channel(home,x[i]);
00105 member(home, y, channel(home,x[n]));
00106 }
00108 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00109 Gecode::Reify r) {
00110 using namespace Gecode;
00111 int n = x.size() - 1;
00112 BoolVarArgs y(n);
00113 for (int i=n; i--; )
00114 y[i] = channel(home,x[i]);
00115 member(home, y, channel(home,x[n]), r);
00116 }
00117 };
00118
00120 class Create {
00121 public:
00123 Create(void) {
00124 for (int i=0; i<=4; i++) {
00125 (void) new Int(i);
00126 (void) new Bool(i);
00127 }
00128 }
00129 };
00130
00131 Create c;
00133
00134 }
00135 }}
00136
00137
00138