1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* David Rijsman <David.Rijsman@quintiq.com>
*
* Contributing authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* David Rijsman, 2009
* Christian Schulte, 2009
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "test/int.hh"
#include <gecode/minimodel.hh>
#include <climits>
namespace Test { namespace Int {
/// %Tests for sequence constraints
namespace Sequence {
/**
* \defgroup TaskTestIntSequence Sequence constraints
* \ingroup TaskTestInt
*/
//@{
/// %Base test for sequence
class SequenceTest : public Test {
protected:
Gecode::IntSet s;
int q,l,u;
public:
/// Create and register test
SequenceTest(const std::string& s,
const Gecode::IntSet& s0, int q0, int l0, int u0,
int size, int min, int max)
: Test("Sequence::"+s,size,min,max), s(s0), q(q0), l(l0), u(u0) {
}
/// %Test whether \a x is solutionin
virtual bool solution(const Assignment& x) const {
for (int i=0; i< (x.size() - q + 1); i++ ) {
int total = 0;
for (int j=i; j < i + q; j++ ) {
if (s.in(x[j]))
total++;
if (total > u)
return false;
}
if ( total < l )
return false;
}
return true;
}
};
/// %Test for sequence with boolean variables
class SequenceBoolTest : public SequenceTest {
public:
/// Create and register test
SequenceBoolTest(const std::string& s, const Gecode::IntSet& s0,
int q0, int l0, int u0, int size)
: SequenceTest("Bool::"+s,s0,q0,l0,u0,size,0,1) {
}
/// Post constraint on \a x
virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
Gecode::BoolVarArgs c(x.size());
for (int i=0; i<x.size(); i++) {
c[i]=Gecode::channel(home,x[i]);
}
Gecode::sequence(home,c,s,q,l,u);
}
};
/// %Test for sequence with boolean variables
class SequenceIntTest : public SequenceTest {
public:
/// Create and register test
SequenceIntTest(const std::string& s, const Gecode::IntSet& s0,
int q0, int l0, int u0, int size, int min, int max)
: SequenceTest("Int::"+s,s0,q0,l0,u0,size,min,max) {
}
/// Post constraint on \a x
virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
Gecode::sequence(home,x,s,q,l,u);
}
};
/// Help class to create and register tests
class Create {
public:
/// Perform creation and registration
Create(void) {
using namespace Gecode;
IntSet a(0,0);
IntSet b(1,1);
IntSet c(2,2);
IntSet d(0,1);
IntArgs ie({0,2});
IntSet e(ie);
(void) new SequenceBoolTest("A",a,3,2,2,6);
(void) new SequenceBoolTest("B",b,3,2,2,6);
(void) new SequenceBoolTest("C",b,6,2,2,6);
(void) new SequenceBoolTest("D",b,6,0,0,6);
(void) new SequenceBoolTest("E",b,6,6,6,6);
(void) new SequenceIntTest ("A",c,3,2,2,6,2,3);
(void) new SequenceIntTest ("B",c,3,2,2,6,2,4);
(void) new SequenceIntTest ("C",b,3,2,2,6,1,3);
(void) new SequenceIntTest ("D",c,3,0,0,3,1,3);
(void) new SequenceIntTest ("E",c,3,3,3,3,1,3);
(void) new SequenceIntTest ("F",c,3,2,2,10,2,3);
(void) new SequenceIntTest ("G",d,3,2,2,6,0,3);
(void) new SequenceIntTest ("H",d,3,2,2,6,0,4);
(void) new SequenceIntTest ("I",d,3,2,2,6,1,3);
(void) new SequenceIntTest ("J",e,3,0,0,6,0,3);
(void) new SequenceIntTest ("K",e,3,3,3,6,0,3);
(void) new SequenceIntTest ("L",e,3,2,2,6,0,3);
}
};
Create c;
//@}
}
}}
// STATISTICS: test-int
|