precede.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 namespace Test { namespace Int {
00041
00043 namespace Precede {
00044
00046 class Single : public Test {
00047 private:
00049 int s, t;
00050 public:
00052 Single(int s0, int t0)
00053 : Test("Precede::Single::"+str(s0)+"<"+str(t0),8,1,4),
00054 s(s0), t(t0) {}
00056 virtual bool solution(const Assignment& x) const {
00057 int n = x.size();
00058 for (int i = 0 ; i < n ; i++) {
00059 if (x[i] == t)
00060 return false;
00061 if (x[i] == s)
00062 return true;
00063 }
00064 return true;
00065 }
00067 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00068 Gecode::precede(home, x, s, t);
00069 }
00070 };
00071
00073 class Multi : public Test {
00074 private:
00076 Gecode::IntArgs c;
00077 public:
00079 Multi(const Gecode::IntArgs& c0)
00080 : Test("Precede::Multi::"+str(c0),6,1,5), c(c0) {
00081 contest = CTL_NONE;
00082 }
00084 virtual bool solution(const Assignment& x) const {
00085 for (int j=0; j<c.size()-1; j++)
00086 for (int i=0; i<x.size(); i++) {
00087 if (x[i] == c[j+1])
00088 return false;
00089 if (x[i] == c[j])
00090 break;
00091 }
00092 return true;
00093 }
00095 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00096 Gecode::precede(home, x, c);
00097 }
00098 };
00099
00100 Single _a(2, 3);
00101 Single _b(1, 4);
00102
00103 Multi _c(Gecode::IntArgs({1,2,3}));
00104 Multi _d(Gecode::IntArgs({3,2,1}));
00105 Multi _e(Gecode::IntArgs({4,2,3,1}));
00106
00107 }
00108
00109 }}
00110
00111