Generated on for Gecode by doxygen 1.17.0
sequence.cpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Guido Tack <tack@gecode.dev>
5 *
6 * Copyright:
7 * Guido Tack, 2005
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#include "test/set.hh"
35
36using namespace Gecode;
37
38namespace Test { namespace Set {
39
41 namespace Sequence {
42
48
49 static IntSet ds_33(-1,2);
50
52 class Sequence : public SetTest {
53 public:
55 Sequence(const char* t)
56 : SetTest(t,4,ds_33,false) {}
57
58 virtual bool solution(const SetAssignment& x) const {
60 for (int i=0; i<4; i++) {
61 CountableSetRanges xir(x.lub, x[i]);
62 IntSet xi(xir);
63 if (xi.ranges() > 0) {
64 int oldMax = max;
65 max = xi.max();
66 if (xi.min() <= oldMax)
67 return false;
68 }
69 }
70 return true;
71 }
72
73 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
74 Gecode::sequence(home, x);
75 }
76 };
77 Sequence _sequence("Sequence::Sequence");
78
80 class SeqU : public SetTest {
81 private:
82 int n;
83 public:
85 SeqU(int n0)
86 : SetTest(n0 == 1 ? TestTags::check()
88 "Sequence::SeqU"+str(n0),n0+1,ds_33,false), n(n0) {}
89
90 virtual bool solution(const SetAssignment& x) const {
92 for (int i=0; i<n; i++) {
93 CountableSetRanges xir(x.lub, x[i]);
94 IntSet xi(xir);
95 if (xi.ranges() > 0) {
96 int oldMax = max;
97 max = xi.max();
98 if (xi.min() <= oldMax)
99 return false;
100 }
101 }
103 for (int i=n; i--; )
104 isrs[i].init(x.lub, x[i]);
105 bool ret;
106 {
107 Region r;
108 Iter::Ranges::NaryUnion u(r, isrs, n);
109 CountableSetRanges xnr(x.lub, x[n]);
110 ret = Iter::Ranges::equal(u, xnr);
111 }
112 delete[] isrs;
113 return ret;
114 }
115
116 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
117 SetVarArgs xs(x.size()-1);
118 for (int i=x.size()-1; i--;)
119 xs[i]=x[i];
120 Gecode::sequence(home, xs, x[x.size()-1]);
121 }
122 };
126
127}}}
128
129// STATISTICS: test-set
Integer sets.
Definition int.hh:179
int min(int i) const
Return minimum of range at position i.
int max(int i) const
Return maximum of range at position i.
int ranges(void) const
Return number of ranges of the specification.
Integer variable array.
Definition int.hh:792
Range iterator for union of iterators.
Passing set variables.
Definition set.hh:491
Set variable array
Definition set.hh:575
Computation spaces.
Definition core.hpp:1787
int size(void) const
Return size of array (number of elements).
Definition array.hpp:945
Test for Region memory area
Definition region.cpp:42
Range iterator producing subsets of an IntSet.
Definition set.hh:113
Test for sequential-union constraint
Definition sequence.cpp:80
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition sequence.cpp:90
SeqU(int n0)
Create and register test.
Definition sequence.cpp:85
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition sequence.cpp:116
Test for sequence constraint
Definition sequence.cpp:52
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition sequence.cpp:58
Sequence(const char *t)
Create and register test.
Definition sequence.cpp:55
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition sequence.cpp:73
Generate all set assignments.
Definition set.hh:156
Gecode::IntSet lub
The common superset for all domains.
Definition set.hh:168
static std::string str(Gecode::SetRelType srt)
Map set relation to string.
Definition set.hpp:46
SetTest(const std::string &s, int a, const Gecode::IntSet &d, bool r=false, int w=0)
Constructor.
Definition set.hh:312
Set of test tags.
Definition test.hh:105
bool equal(I &i, J &j)
Check whether range iterators i and j are equal.
const int min
Smallest allowed integer in integer set.
Definition set.hh:99
Gecode toplevel namespace
void sequence(Home home, const IntVarArgs &x, const IntSet &s, int q, int l, int u, IntPropLevel ipl=IPL_DEF)
Post propagator for .
Definition sequence.cpp:47
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Sequence _sequence("Sequence::Sequence")
Testing finite sets.
Definition set.cpp:42
General test support.
Definition afc.cpp:41
Region r
Definition region.cpp:65
@ check
Basic integrity tests.
Definition test.hh:99
@ standard
Standard test suite.
Definition test.hh:100