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