mm-rel.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 MiniModel {
00042
00048
00049 class IntLex : public Test {
00050 protected:
00052 Gecode::IntRelType irt;
00053 public:
00055 IntLex(Gecode::IntRelType irt0)
00056 : Test("MiniModel::Lex::Int::"+str(irt0),6,-2,2), irt(irt0) {}
00058 virtual bool solution(const Assignment& x) const {
00059 int n=x.size() >> 1;
00060 for (int i=0; i<n; i++)
00061 if (x[i] != x[n+i])
00062 return cmp(x[i],irt,x[n+i]);
00063 return ((irt == Gecode::IRT_LQ) || (irt == Gecode::IRT_GQ) ||
00064 (irt == Gecode::IRT_EQ));
00065 GECODE_NEVER;
00066 return false;
00067 }
00069 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00070 using namespace Gecode;
00071 int n=x.size() >> 1;
00072 IntVarArgs y(n); IntVarArgs z(n);
00073 for (int i=0; i<n; i++) {
00074 y[i]=x[i]; z[i]=x[n+i];
00075 }
00076 lex(home, y, irt, z);
00077 }
00078 };
00079
00081 class BoolLex : public Test {
00082 protected:
00084 Gecode::IntRelType irt;
00085 public:
00087 BoolLex(Gecode::IntRelType irt0)
00088 : Test("MiniModel::Lex::Bool::"+str(irt0),10,0,1), irt(irt0) {}
00090 virtual bool solution(const Assignment& x) const {
00091 int n=x.size() >> 1;
00092 for (int i=0; i<n; i++)
00093 if (x[i] != x[n+i])
00094 return cmp(x[i],irt,x[n+i]);
00095 return ((irt == Gecode::IRT_LQ) || (irt == Gecode::IRT_GQ) ||
00096 (irt == Gecode::IRT_EQ));
00097 GECODE_NEVER;
00098 return false;
00099 }
00101 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00102 using namespace Gecode;
00103 int n=x.size() >> 1;
00104 BoolVarArgs y(n); BoolVarArgs z(n);
00105 for (int i=0; i<n; i++) {
00106 y[i]=channel(home,x[i]); z[i]=channel(home,x[n+i]);
00107 }
00108 lex(home, y, irt, z);
00109 }
00110 };
00111
00113 class Create {
00114 public:
00116 Create(void) {
00117 using namespace Gecode;
00118 for (IntRelTypes irts; irts(); ++irts) {
00119 (void) new IntLex(irts.irt());
00120 (void) new BoolLex(irts.irt());
00121 }
00122 }
00123 };
00124
00125 Create c;
00127
00128 }
00129
00130 }}
00131
00132