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 #include <gecode/minimodel.hh>
00041 #include <climits>
00042
00043 namespace Test { namespace Int {
00044
00046 namespace Sequence {
00047
00053
00054 class SequenceTest : public Test {
00055 protected:
00056 Gecode::IntSet s;
00057 int q,l,u;
00058 public:
00060 SequenceTest(const std::string& s,
00061 const Gecode::IntSet& s0, int q0, int l0, int u0,
00062 int size, int min, int max)
00063 : Test("Sequence::"+s,size,min,max), s(s0), q(q0), l(l0), u(u0) {
00064 }
00066 virtual bool solution(const Assignment& x) const {
00067 for (int i=0; i< (x.size() - q + 1); i++ ) {
00068 int total = 0;
00069 for (int j=i; j < i + q; j++ ) {
00070 if (s.in(x[j]))
00071 total++;
00072 if (total > u)
00073 return false;
00074 }
00075 if ( total < l )
00076 return false;
00077 }
00078 return true;
00079 }
00080 };
00081
00082
00084 class SequenceBoolTest : public SequenceTest {
00085 public:
00087 SequenceBoolTest(const std::string& s, const Gecode::IntSet& s0,
00088 int q0, int l0, int u0, int size)
00089 : SequenceTest("Bool::"+s,s0,q0,l0,u0,size,0,1) {
00090 }
00091
00093 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00094 Gecode::BoolVarArgs c(x.size());
00095
00096 for (int i=0; i<x.size(); i++) {
00097 c[i]=Gecode::channel(home,x[i]);
00098 }
00099
00100 Gecode::sequence(home,c,s,q,l,u);
00101 }
00102 };
00103
00105 class SequenceIntTest : public SequenceTest {
00106 public:
00108 SequenceIntTest(const std::string& s, const Gecode::IntSet& s0,
00109 int q0, int l0, int u0, int size, int min, int max)
00110 : SequenceTest("Int::"+s,s0,q0,l0,u0,size,min,max) {
00111 }
00112
00114 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00115 Gecode::sequence(home,x,s,q,l,u);
00116 }
00117 };
00118
00120 class Create {
00121 public:
00122
00124 Create(void) {
00125 using namespace Gecode;
00126
00127 IntSet a(0,0);
00128 IntSet b(1,1);
00129 IntSet c(2,2);
00130 IntSet d(0,1);
00131 IntArgs ie(2, 0,2);
00132 IntSet e(ie);
00133
00134 (void) new SequenceBoolTest("A",a,3,2,2,6);
00135 (void) new SequenceBoolTest("B",b,3,2,2,6);
00136 (void) new SequenceBoolTest("C",b,6,2,2,6);
00137 (void) new SequenceBoolTest("D",b,6,0,0,6);
00138 (void) new SequenceBoolTest("E",b,6,6,6,6);
00139
00140
00141 (void) new SequenceIntTest ("A",c,3,2,2,6,2,3);
00142 (void) new SequenceIntTest ("B",c,3,2,2,6,2,4);
00143 (void) new SequenceIntTest ("C",b,3,2,2,6,1,3);
00144 (void) new SequenceIntTest ("D",c,3,0,0,3,1,3);
00145 (void) new SequenceIntTest ("E",c,3,3,3,3,1,3);
00146 (void) new SequenceIntTest ("F",c,3,2,2,10,2,3);
00147
00148 (void) new SequenceIntTest ("G",d,3,2,2,6,0,3);
00149 (void) new SequenceIntTest ("H",d,3,2,2,6,0,4);
00150 (void) new SequenceIntTest ("I",d,3,2,2,6,1,3);
00151 (void) new SequenceIntTest ("J",e,3,0,0,6,0,3);
00152 (void) new SequenceIntTest ("K",e,3,3,3,6,0,3);
00153 (void) new SequenceIntTest ("L",e,3,2,2,6,0,3);
00154
00155 }
00156 };
00157
00158 Create c;
00160
00161 }
00162 }}
00163
00164