Generated on for Gecode by doxygen 1.17.0
int.hpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.dev>
5 * Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
6 *
7 * Copyright:
8 * Christian Schulte, 2005
9 * Mikael Zayenz Lagerkvist, 2006
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
36namespace Test { namespace Int {
37
38 /*
39 * Assignments
40 *
41 */
42 inline
44 : n(n0), d(d0) {}
45 inline int
46 Assignment::size(void) const {
47 return n;
48 }
49 inline
51
52
53 inline
55 : Assignment(n,d),
56 dsv(new Gecode::IntSetValues[static_cast<unsigned int>(n)]) {
57 for (int i=n; i--; )
58 dsv[i].init(d);
59 }
60 inline bool
62 return dsv[0]();
63 }
64 inline int
66 assert((i>=0) && (i<n));
67 return dsv[i].val();
68 }
69 inline
71 delete [] dsv;
72 }
73
74
75 forceinline int
77 unsigned int skip = rand(d.size());
78 for (Gecode::IntSetRanges it(d); true; ++it) {
79 if (it.width() > skip)
80 return it.min() + static_cast<int>(skip);
81 skip -= it.width();
82 }
84 return 0;
85 }
86
87 inline
89 : Assignment(n,d), vals(new int[static_cast<size_t>(n)]), a(a0) {
90 for (int i=n; i--; )
91 vals[i] = randval(rand);
92 }
93
94 inline bool
96 return a>0;
97 }
98 inline int
100 assert((i>=0) && (i<n));
101 return vals[i];
102 }
103 inline
105 delete [] vals;
106 }
107
108 forceinline int
110 unsigned int skip = rand(d.size());
111 for (Gecode::IntSetRanges it(d); true; ++it) {
112 if (it.width() > skip)
113 return it.min() + static_cast<int>(skip);
114 skip -= it.width();
115 }
117 return 0;
118 }
119
120 inline
121 RandomMixAssignment::RandomMixAssignment(int n0, const Gecode::IntSet& d0, int n1, const Gecode::IntSet& d1, int a0,
123 : Assignment(n0+n1,d0),vals(new int[static_cast<size_t>(n0+n1)]),
124 a(a0),_n1(n1),_d1(d1) {
125 for (int i=n0; i--; )
126 vals[i] = randval(d, rand);
127 for (int i=n1; i--; )
128 vals[n0+i] = randval(_d1, rand);
129 }
130
131 inline bool
133 return a>0;
134 }
135
136 inline int
138 assert((i>=0) && (i<n));
139 return vals[i];
140 }
141
142 inline
146
147 /*
148 * Tests with integer constraints
149 *
150 */
151 forceinline bool
152 Test::eqv(void) const {
153 return reified && ((rms & (1 << Gecode::RM_EQV)) != 0);
154 }
155 forceinline bool
156 Test::imp(void) const {
157 return reified && ((rms & (1 << Gecode::RM_IMP)) != 0);
158 }
159 forceinline bool
160 Test::pmi(void) const {
161 return reified && ((rms & (1 << Gecode::RM_PMI)) != 0);
162 }
163 inline
164 Test::Test(TestTags tags, const std::string& p, const std::string& s,
165 int a, const Gecode::IntSet& d, bool r,
167 : Base(p+s, tags), arity(a), dom(d),
168 reified(r), rms((1 << Gecode::RM_EQV) |
169 (1 << Gecode::RM_IMP) |
170 (1 << Gecode::RM_PMI)),
171 ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
172 testsearch(true), testfix(true) {}
173
174 inline
175 Test::Test(const std::string& p, const std::string& s,
176 int a, const Gecode::IntSet& d, bool r,
178 : Test(TestTags::standard(),p,s,a,d,r,i) {}
179
180 inline
181 Test::Test(TestTags tags, const std::string& s,
182 int a, const Gecode::IntSet& d, bool r,
184 : Base("Int::"+s, tags), arity(a), dom(d),
185 reified(r), rms((1 << Gecode::RM_EQV) |
186 (1 << Gecode::RM_IMP) |
187 (1 << Gecode::RM_PMI)),
188 ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
189 testsearch(true), testfix(true) {}
190
191 inline
192 Test::Test(const std::string& s,
193 int a, const Gecode::IntSet& d, bool r,
195 : Test(TestTags::standard(),s,a,d,r,i) {}
196
197 inline
198 Test::Test(TestTags tags, const std::string& p, const std::string& s,
199 int a, int min, int max, bool r,
201 : Base(p+s, tags), arity(a), dom(min,max),
202 reified(r), rms((1 << Gecode::RM_EQV) |
203 (1 << Gecode::RM_IMP) |
204 (1 << Gecode::RM_PMI)),
205 ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
206 testsearch(true), testfix(true) {}
207
208 inline
209 Test::Test(const std::string& p, const std::string& s,
210 int a, int min, int max, bool r,
212 : Test(TestTags::standard(),p,s,a,min,max,r,i) {}
213
214 inline
215 Test::Test(TestTags tags, const std::string& s,
216 int a, int min, int max, bool r, Gecode::IntPropLevel i)
217 : Base("Int::"+s, tags), arity(a), dom(min,max),
218 reified(r), rms((1 << Gecode::RM_EQV) |
219 (1 << Gecode::RM_IMP) |
220 (1 << Gecode::RM_PMI)),
221 ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
222 testsearch(true), testfix(true) {}
223
224 inline
225 Test::Test(const std::string& s,
226 int a, int min, int max, bool r, Gecode::IntPropLevel i)
227 : Test(TestTags::standard(),s,a,min,max,r,i) {}
228
229 inline
230 std::string
232 using namespace Gecode;
233 std::stringstream s;
234 switch (vbd(ipl)) {
235 case IPL_VAL: s << "Val"; break;
236 case IPL_BND: s << "Bnd"; break;
237 case IPL_DOM: s << "Dom"; break;
238 default: s << "Def"; break;
239 }
240 if (ipl & IPL_BASIC) s << "+B";
241 if (ipl & IPL_ADVANCED) s << "+A";
242 return s.str();
243 }
244
245 inline
246 std::string
248 using namespace Gecode;
249 switch (irt) {
250 case IRT_LQ: return "Lq";
251 case IRT_LE: return "Le";
252 case IRT_GQ: return "Gq";
253 case IRT_GR: return "Gr";
254 case IRT_EQ: return "Eq";
255 case IRT_NQ: return "Nq";
256 default: ;
257 }
259 return "NONE";
260 }
261
262 inline std::string
264 using namespace Gecode;
265 switch (bot) {
266 case BOT_AND: return "And";
267 case BOT_OR: return "Or";
268 case BOT_IMP: return "Imp";
269 case BOT_EQV: return "Eqv";
270 case BOT_XOR: return "Xor";
271 default: GECODE_NEVER;
272 }
274 return "NONE";
275 }
276
277 inline std::string
278 Test::str(bool b) {
279 return Base::str(b);
280 }
281
282 inline std::string
283 Test::str(int i) {
284 return Base::str(i);
285 }
286
287 inline std::string
289 return Base::str(x);
290 }
291
292
293
294 template<class T>
295 inline bool
297 using namespace Gecode;
298 switch (r) {
299 case IRT_EQ: return x == y;
300 case IRT_NQ: return x != y;
301 case IRT_LQ: return x <= y;
302 case IRT_LE: return x < y;
303 case IRT_GR: return x > y;
304 case IRT_GQ: return x >= y;
305 default: ;
306 }
307 return false;
308 }
309
310
311
312 inline
314 : i(sizeof(ipls)/sizeof(Gecode::IntPropLevel)-1) {}
315 inline bool
317 return i>=0;
318 }
319 inline void
321 i--;
322 }
324 IntPropLevels::ipl(void) const {
325 return ipls[i];
326 }
327
328
329 inline
331 : i(sizeof(ipls)/sizeof(Gecode::IntPropLevel)-1) {}
332 inline bool
334 return i>=0;
335 }
336 inline void
338 i--;
339 }
342 return ipls[i];
343 }
344
345
346 inline
348 : i(sizeof(irts)/sizeof(Gecode::IntRelType)-1) {}
349 inline void
351 i = sizeof(irts)/sizeof(Gecode::IntRelType)-1;
352 }
353 inline bool
355 return i>=0;
356 }
357 inline void
359 i--;
360 }
361 inline Gecode::IntRelType
362 IntRelTypes::irt(void) const {
363 return irts[i];
364 }
365
366 inline
368 : i(sizeof(bots)/sizeof(Gecode::BoolOpType)-1) {}
369 inline bool
371 return i>=0;
372 }
373 inline void
375 i--;
376 }
377 inline Gecode::BoolOpType
378 BoolOpTypes::bot(void) const {
379 return bots[i];
380 }
381
382}}
383
384// STATISTICS: test-int
Passing integer arguments.
Definition int.hh:653
Range iterator for integer sets.
Definition int.hh:311
Integer sets.
Definition int.hh:179
Base(std::string s)
Create and register a standard test with name s.
Definition test.cpp:125
static std::string str(bool b)
Map bool to string.
Definition test.hpp:121
TestTags tags(void) const
Return tags for test.
Definition test.hpp:95
Gecode::IntSet d
Domain for each variable.
Definition int.hh:76
int n
Number of variables.
Definition int.hh:75
virtual ~Assignment(void)
Destructor.
Definition int.hpp:50
Assignment(int n0, const Gecode::IntSet &d0)
Initialize assignments for n0 variables and values d0.
Definition int.hpp:43
int size(void) const
Return number of variables.
Definition int.hpp:46
BoolOpTypes(void)
Initialize iterator.
Definition int.hpp:367
bool operator()(void) const
Test whether iterator is done.
Definition int.hpp:370
Gecode::BoolOpType bot(void) const
Return current operation type.
Definition int.hpp:378
void operator++(void)
Increment to next operation type.
Definition int.hpp:374
CpltAssignment(int n, const Gecode::IntSet &d)
Initialize assignments for n0 variables and values d0.
Definition int.hpp:54
virtual int operator[](int i) const
Return value for variable i.
Definition int.hpp:65
virtual ~CpltAssignment(void)
Destructor.
Definition int.hpp:70
Gecode::IntSetValues * dsv
Iterator for each variable.
Definition int.hh:95
virtual bool has_more(void) const
Test whether all assignments have been iterated.
Definition int.hpp:61
Gecode::IntPropLevel ipl(void) const
Return current level.
Definition int.hpp:341
bool operator()(void) const
Test whether iterator is done.
Definition int.hpp:333
IntPropBasicAdvanced(void)
Initialize iterator.
Definition int.hpp:330
void operator++(void)
Increment to next level.
Definition int.hpp:337
IntPropLevels(void)
Initialize iterator.
Definition int.hpp:313
Gecode::IntPropLevel ipl(void) const
Return current level.
Definition int.hpp:324
bool operator()(void) const
Test whether iterator is done.
Definition int.hpp:316
void operator++(void)
Increment to next level.
Definition int.hpp:320
void operator++(void)
Increment to next relation type.
Definition int.hpp:358
bool operator()(void) const
Test whether iterator is done.
Definition int.hpp:354
void reset(void)
Reset iterator.
Definition int.hpp:350
IntRelTypes(void)
Initialize iterator.
Definition int.hpp:347
Gecode::IntRelType irt(void) const
Return current relation type.
Definition int.hpp:362
virtual int operator[](int i) const
Return value for variable i.
Definition int.hpp:99
virtual ~RandomAssignment(void)
Destructor.
Definition int.hpp:104
int a
How many assignments still to be generated Generate new value according to domain.
Definition int.hh:113
int * vals
The current values for the variables.
Definition int.hh:112
RandomAssignment(int n, const Gecode::IntSet &d, int a0, Gecode::Support::RandomGenerator &rand)
Initialize for a assignments for n0 variables and values d0.
Definition int.hpp:88
int randval(Gecode::Support::RandomGenerator &rand)
Definition int.hpp:76
virtual bool has_more(void) const
Test whether all assignments have been iterated.
Definition int.hpp:95
int _n1
How many variables in the second set.
Definition int.hh:134
int randval(const Gecode::IntSet &d, Gecode::Support::RandomGenerator &rand)
Definition int.hpp:109
Gecode::IntSet _d1
Domain for second set of variables Generate new value according to domain d.
Definition int.hh:135
virtual int operator[](int i) const
Return value for variable i.
Definition int.hpp:137
virtual bool has_more(void) const
Test whether all assignments have been iterated.
Definition int.hpp:132
RandomMixAssignment(int n0, const Gecode::IntSet &d0, int n1, const Gecode::IntSet &d1, int a0, Gecode::Support::RandomGenerator &rand)
Initialize for a assignments for n0 variables and values d0.
Definition int.hpp:121
virtual ~RandomMixAssignment(void)
Destructor.
Definition int.hpp:143
int a
How many assignments still to be generated.
Definition int.hh:133
int * vals
The current values for the variables.
Definition int.hh:132
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
Definition int.hpp:160
bool reified
Does the constraint also exist as reified constraint.
Definition int.hh:277
bool testsearch
Whether to perform search test.
Definition int.hh:285
static std::string str(bool b)
Map bool to string.
Definition int.hpp:278
bool testfix
Whether to perform fixpoint test.
Definition int.hh:287
int rms
Supported reification modes, encoded as a bit mask of 1 << Gecode::RM_*.
Definition int.hh:279
Test(const std::string &p, const std::string &s, int a, const Gecode::IntSet &d, bool r=false, Gecode::IntPropLevel i=Gecode::IPL_DEF)
Constructor.
Definition int.hpp:175
Gecode::IntPropLevel ipl
Propagation level.
Definition int.hh:281
bool eqv(void) const
Test whether equivalence as reification mode is supported.
Definition int.hpp:152
int arity
Number of variables.
Definition int.hh:273
static bool cmp(T x, Gecode::IntRelType r, T y)
Compare x and y with respect to r.
Definition int.hpp:296
Gecode::IntSet dom
Domain of variables.
Definition int.hh:275
bool imp(void) const
Test whether implication as reification mode is supported.
Definition int.hpp:156
ConTestLevel contest
Whether to test for certain consistency.
Definition int.hh:283
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
BoolOpType
Operation types for Booleans.
Definition int.hh:1250
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:1274
@ IRT_EQ
Equality ( ).
Definition int.hh:1226
@ IRT_NQ
Disequality ( ).
Definition int.hh:1227
@ IRT_GQ
Greater or equal ( ).
Definition int.hh:1230
@ IRT_LE
Less ( ).
Definition int.hh:1229
@ IRT_GR
Greater ( ).
Definition int.hh:1231
@ IRT_LQ
Less or equal ( ).
Definition int.hh:1228
@ RM_IMP
Implication for reification.
Definition int.hh:1162
@ RM_PMI
Inverse implication for reification.
Definition int.hh:1169
@ RM_EQV
Equivalence for reification (default).
Definition int.hh:1155
@ BOT_OR
Disjunction.
Definition int.hh:1252
@ BOT_EQV
Equivalence.
Definition int.hh:1254
@ BOT_IMP
Implication.
Definition int.hh:1253
@ BOT_XOR
Exclusive or.
Definition int.hh:1255
@ BOT_AND
Conjunction.
Definition int.hh:1251
@ IPL_BASIC
Use basic propagation algorithm.
Definition int.hh:1281
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition int.hh:1279
@ IPL_VAL
Value propagation.
Definition int.hh:1277
@ IPL_ADVANCED
Use advanced propagation algorithm.
Definition int.hh:1282
@ IPL_BND
Bounds propagation.
Definition int.hh:1278
Gecode toplevel namespace
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
Definition ipl.hpp:37
Testing finite domain integers.
Definition int.cpp:41
@ CTL_NONE
No consistency-test.
Definition int.hh:154
@ CTL_DOMAIN
Test for domain-consistency.
Definition int.hh:155
General test support.
Definition afc.cpp:41
Region r
Definition region.cpp:65
@ standard
Standard test suite.
Definition test.hh:100
#define forceinline
Definition config.hpp:144
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56