Generated on for Gecode by doxygen 1.18.0
set.hh
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 * Christian Schulte <schulte@gecode.dev>
6 *
7 * Copyright:
8 * Guido Tack, 2005
9 * Christian Schulte, 2005
10 *
11 * This file is part of Gecode, the generic constraint
12 * development environment:
13 * http://www.gecode.dev
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining
16 * a copy of this software and associated documentation files (the
17 * "Software"), to deal in the Software without restriction, including
18 * without limitation the rights to use, copy, modify, merge, publish,
19 * distribute, sublicense, and/or sell copies of the Software, and to
20 * permit persons to whom the Software is furnished to do so, subject to
21 * the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be
24 * included in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 *
34 */
35
36#ifndef GECODE_TEST_SET_HH
37#define GECODE_TEST_SET_HH
38
39#include <gecode/set.hh>
40#include "test/test.hh"
41#include "test/int.hh"
42
43/* Configure linking, as for the Gecode variable libraries. */
44#if !defined(GECODE_STATIC_LIBS) && \
45 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
46#ifdef GECODE_BUILD_TESTSET
47#define GECODE_TESTSET_EXPORT __declspec( dllexport )
48#else
49#define GECODE_TESTSET_EXPORT __declspec( dllimport )
50#endif
51#elif defined(GECODE_GCC_HAS_CLASS_VISIBILITY)
52#define GECODE_TESTSET_EXPORT __attribute__ ((visibility("default")))
53#else
54#define GECODE_TESTSET_EXPORT
55#endif
56
57namespace Test {
58
60 namespace Set {
61
66
72
75 private:
77 int cur;
78 int i;
79 public:
84 : dv(d0), cur(cur0), i(1) {
85 if (! (i & cur))
86 operator++();
87 }
88
89 void init(const Gecode::IntSet& d0, int cur0) {
90 dv = d0;
91 cur = cur0;
92 i = 1;
93 if (! (i & cur))
94 operator++();
95 }
96
97 bool operator()(void) const {
98 return i<=cur;
99 }
100
101 void operator++(void) {
102 do {
103 ++dv;
104 i = i<<1;
105 } while (! (i & cur) && i<cur);
106 }
107
108 int val(void) const { return dv.val(); }
109 };
110
113 : public Gecode::Iter::Values::ToRanges<CountableSetValues> {
114 private:
117 public:
124
125 void init(const Gecode::IntSet& d, int cur) {
126 v.init(d, cur);
128 }
129 };
130
133 private:
137 unsigned int cur;
139 unsigned int lubmax;
140 public:
146 void init(const Gecode::IntSet& s);
148 bool operator()(void) const { return cur<lubmax; }
150 void operator++(void);
152 int val(void) const;
153 };
154
157 private:
159 int n;
161 CountableSet* dsv;
165 bool done;
166 public:
172 SetAssignment(int n, const Gecode::IntSet& d, int i = 0);
174 bool operator()(void) const { return !done; }
178 int operator[](int i) const {
179 assert((i>=0) && (i<n));
180 return dsv[i].val();
181 }
182
183 int intval(void) const { return ir[0]; }
185 const Test::Int::Assignment& ints(void) const { return ir; }
187 int size(void) const { return n; }
189 ~SetAssignment(void) { delete [] dsv; }
190 };
191
192
193 class GECODE_TESTSET_EXPORT SetTest;
194
197 public:
212
222 SetTestSpace(int n, Gecode::IntSet& d0, int i, SetTest* t,
223 bool log=true);
233 SetTestSpace(int n, Gecode::IntSet& d0, int i, SetTest* t,
234 Gecode::ReifyMode rm, bool log=true);
238 virtual Gecode::Space* copy(void);
240 void post(void);
242 bool failed(void);
244 bool subsumed(bool b);
246 void rel(int i, Gecode::SetRelType srt, const Gecode::IntSet& is);
248 void cardinality(int i, int cmin, int cmax);
250 void rel(int i, Gecode::IntRelType irt, int n);
252 void rel(bool sol);
256 bool assigned(void) const;
258 void removeFromLub(int v, int i, const SetAssignment& a);
260 void removeFromLub(int v, int i, const SetAssignment& a,
261 SetTestSpace& c);
263 void addToGlb(int v, int i, const SetAssignment& a);
265 void addToGlb(int v, int i, const SetAssignment& a,
266 SetTestSpace& c);
268 bool fixprob(void);
272 unsigned int propagators(void);
274 void disable(void);
276 void enable(void);
281 };
282
288 private:
290 int arity;
292 Gecode::IntSet lub;
294 bool reified;
296 int withInt;
297
298 protected:
303 public:
312 SetTest(const std::string& s,
313 int a, const Gecode::IntSet& d, bool r=false, int w=0)
314 : SetTest(TestTags::standard(),s,a,d,r,w) {}
315
316 SetTest(TestTags tags, const std::string& s,
317 int a, const Gecode::IntSet& d, bool r=false, int w=0)
318 : Base("Set::"+s, tags), arity(a), lub(d), reified(r), withInt(w),
319 disabled(true), testsubsumed(true) {}
320
321 virtual bool solution(const SetAssignment&) const = 0;
323 virtual void post(Gecode::Space& home, Gecode::SetVarArray& x,
324 Gecode::IntVarArray& y) = 0;
328
329 virtual bool run(void);
330
332
333
334 static std::string str(Gecode::SetRelType srt);
336 static std::string str(Gecode::SetOpType srt);
338 static std::string str(int i);
340 static std::string str(const Gecode::IntArgs& i);
342 };
343
344
347 private:
349 static const Gecode::SetRelType srts[6];
351 int i;
352 public:
354 SetRelTypes(void);
356 bool operator()(void) const;
358 void operator++(void);
360 Gecode::SetRelType srt(void) const;
361 };
362
365 private:
367 static const Gecode::SetOpType sots[4];
369 int i;
370 public:
372 SetOpTypes(void);
374 bool operator()(void) const;
376 void operator++(void);
378 Gecode::SetOpType sot(void) const;
379 };
380
381}}
382
387GECODE_TESTSET_EXPORT std::ostream&
388operator<<(std::ostream&, const Test::Set::SetAssignment& a);
389
390#include "test/set.hpp"
391
392#endif
393
394// STATISTICS: test-set
Passing integer arguments.
Definition int.hh:653
Value iterator for integer sets.
Definition int.hh:352
Integer sets.
Definition int.hh:179
Integer variable array.
Definition int.hh:792
Range iterator from value iterator.
void init(I &i)
Initialize with value iterator i.
Reification specification.
Definition int.hh:1176
Set variable array
Definition set.hh:575
Computation spaces.
Definition core.hpp:1787
Base(std::string s)
Create and register a standard test with name s.
TestTags tags(void) const
Return tags for test.
Definition test.hpp:95
Base class for assignments
Definition int.hh:73
Generate all assignments.
Definition int.hh:93
void init(const Gecode::IntSet &d, int cur)
Initialize with set d0 and bit-pattern cur0.
Definition set.hh:125
CountableSetRanges(const Gecode::IntSet &d, int cur)
Initialize with set d0 and bit-pattern cur0.
Definition set.hh:121
CountableSetRanges(void)
Default constructor.
Definition set.hh:119
Value iterator producing subsets of an IntSet.
Definition set.hh:74
int val(void) const
Return current value.
Definition set.hh:108
void init(const Gecode::IntSet &d0, int cur0)
Initialize with set d0 and bit-pattern cur0.
Definition set.hh:89
bool operator()(void) const
Test if finished.
Definition set.hh:97
CountableSetValues(void)
Default constructor.
Definition set.hh:81
void operator++(void)
Move to next value.
Definition set.hh:101
CountableSetValues(const Gecode::IntSet &d0, int cur0)
Initialize with set d0 and bit-pattern cur0.
Definition set.hh:83
Iterate all subsets of a given set.
Definition set.hh:132
int val(void) const
Return current subset.
CountableSet(void)
Default constructor.
Definition set.hh:144
CountableSet(const Gecode::IntSet &s)
Initialize with set s.
bool operator()(void) const
Check if still subsets left.
Definition set.hh:148
void init(const Gecode::IntSet &s)
Initialize with set s.
void operator++(void)
Move to next subset.
Generate all set assignments.
Definition set.hh:156
int intval(void) const
Return value for first integer variable.
Definition set.hh:183
const Test::Int::Assignment & ints(void) const
Return assignment for integer variables.
Definition set.hh:185
SetAssignment(int n, const Gecode::IntSet &d, int i=0)
Initialize with n set variables, initial bound d and i int variables.
int size(void) const
Return arity.
Definition set.hh:187
void next(Gecode::Support::RandomGenerator &rand)
Move to next assignment.
int operator[](int i) const
Return the set at i as a bit pattern over lub; see CountableSetRanges.
Definition set.hh:178
int withInt
How many integer variables to iterate.
Definition set.hh:170
bool operator()(void) const
Test whether all assignments have been iterated.
Definition set.hh:174
~SetAssignment(void)
Destructor.
Definition set.hh:189
Gecode::IntSet lub
The common superset for all domains.
Definition set.hh:168
SetOpTypes(void)
Initialize iterator.
Definition set.hpp:100
Gecode::SetOpType sot(void) const
Return current operation type.
Definition set.hpp:111
void operator++(void)
Increment to next operation type.
Definition set.hpp:107
bool operator()(void) const
Test whether iterator is done.
Definition set.hpp:103
SetRelTypes(void)
Initialize iterator.
Definition set.hpp:84
void operator++(void)
Increment to next relation type.
Definition set.hpp:91
Gecode::SetRelType srt(void) const
Return current relation type.
Definition set.hpp:95
bool operator()(void) const
Test whether iterator is done.
Definition set.hpp:87
bool subsumed(bool b)
Check for subsumption if b is true.
void post(void)
Post propagator.
SetTest * test
The test currently run.
Definition set.hh:211
Gecode::SetVarArray x
Set variables to be tested.
Definition set.hh:201
bool assigned(void) const
Test whether all variables are assigned.
Gecode::IntSet d
Initial domain.
Definition set.hh:199
virtual Gecode::Space * copy(void)
Copy space during cloning.
void removeFromLub(int v, int i, const SetAssignment &a)
Remove value v from the upper bound of x[i].
bool fixprob(void)
Perform fixpoint computation.
void rel(int i, Gecode::IntRelType irt, int n)
Perform integer tell operation on y[i].
SetTestSpace(int n, Gecode::IntSet &d0, int i, SetTest *t, Gecode::ReifyMode rm, bool log=true)
Create test space with reification.
bool prune(const SetAssignment &a, Gecode::Support::RandomGenerator &rand)
Perform random pruning.
Gecode::Reify r
Reification information.
Definition set.hh:207
void removeFromLub(int v, int i, const SetAssignment &a, SetTestSpace &c)
Remove value v from the upper bound of x[i].
SetTestSpace(int n, Gecode::IntSet &d0, int i, SetTest *t, bool log=true)
Create test space without reification.
Gecode::IntVarArray y
Int variables to be tested.
Definition set.hh:203
bool disabled(const SetAssignment &a, SetTestSpace &c, Gecode::Support::RandomGenerator &rand)
Prune values also in a space c with disabled propagators, but not those in assignment a.
bool failed(void)
Compute a fixpoint and check for failure.
void disable(void)
Disable propagators in space and compute fixpoint (make all idle).
SetTestSpace(SetTestSpace &s)
Constructor for cloning s.
void rel(int i, Gecode::SetRelType srt, const Gecode::IntSet &is)
Perform set tell operation on x[i].
bool reified
Whether the test is for a reified propagator.
Definition set.hh:209
void addToGlb(int v, int i, const SetAssignment &a, SetTestSpace &c)
Remove value v from the lower bound of x[i].
void rel(bool sol)
Perform Boolean tell on b.
void addToGlb(int v, int i, const SetAssignment &a)
Remove value v from the lower bound of x[i].
bool same(SetTestSpace &c)
Check whether propagation is the same as in c.
void cardinality(int i, int cmin, int cmax)
Perform cardinality tell operation on x[i].
void assign(const SetAssignment &a, Gecode::Support::RandomGenerator &rand)
Assign all variables to values in a.
void enable(void)
Enable propagators in space.
unsigned int propagators(void)
Return the number of propagators.
int withInt
How many integer variables are used by the test.
Definition set.hh:205
Base class for tests with set constraints
Definition set.hh:287
virtual void post(Gecode::Space &home, Gecode::SetVarArray &x, Gecode::IntVarArray &y)=0
Post propagator.
SetTest(TestTags tags, const std::string &s, int a, const Gecode::IntSet &d, bool r=false, int w=0)
Construct and register a test with explicitly assigned tags.
Definition set.hh:316
static std::string str(Gecode::SetRelType srt)
Map set relation to string.
Definition set.hpp:46
bool testsubsumed
Whether to check for subsumption.
Definition set.hh:302
virtual bool run(void)
Perform test.
virtual void post(Gecode::Space &, Gecode::SetVarArray &, Gecode::IntVarArray &, Gecode::Reify)
Post reified propagator.
Definition set.hh:326
bool disabled
Whether to perform full tests for disabled propagators.
Definition set.hh:300
virtual bool solution(const SetAssignment &) const =0
Check for solution.
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
LinearCongruentialGenerator< 2147483647, 48271, 44488, 3399 > RandomGenerator
Default values for linear congruential generator.
Definition random.hpp:183
IntRelType
Relation types for integers.
Definition int.hh:1225
ReifyMode
Mode for reification.
Definition int.hh:1148
SetOpType
Common operations for sets.
Definition set.hh:667
SetRelType
Common relation types for sets.
Definition set.hh:650
Testing finite sets.
Definition set.hh:60
General test support.
Definition assign.hh:52
@ standard
Standard test suite.
Definition test.hh:100
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const Dictionary &d)
Print statistics summary.
Definition scowl.hpp:13625
#define GECODE_TESTSET_EXPORT
Definition set.hh:54