Generated on Wed Jan 1 2020 10:37:59 for Gecode by doxygen 1.8.16
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.org>
5  * Mikael Lagerkvist <lagerkvist@gecode.org>
6  *
7  * Copyright:
8  * Christian Schulte, 2005
9  * Mikael Lagerkvist, 2006
10  *
11  * This file is part of Gecode, the generic constraint
12  * development environment:
13  * http://www.gecode.org
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 namespace 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 = Base::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();
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 = Base::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  }
116  GECODE_NEVER;
117  return 0;
118  }
119 
120  inline
122  int n1, const Gecode::IntSet& d1,
123  int a0)
124  : Assignment(n0+n1,d0),vals(new int[static_cast<size_t>(n0+n1)]),
125  a(a0),_n1(n1),_d1(d1) {
126  for (int i=n0; i--; )
127  vals[i] = randval(d);
128  for (int i=n1; i--; )
129  vals[n0+i] = randval(_d1);
130  }
131 
132  inline bool
134  return a>0;
135  }
136 
137  inline int
139  assert((i>=0) && (i<n));
140  return vals[i];
141  }
142 
143  inline
145  delete [] vals;
146  }
147 
148  /*
149  * Tests with integer constraints
150  *
151  */
152  forceinline bool
153  Test::eqv(void) const {
154  return reified && ((rms & (1 << Gecode::RM_EQV)) != 0);
155  }
156  forceinline bool
157  Test::imp(void) const {
158  return reified && ((rms & (1 << Gecode::RM_IMP)) != 0);
159  }
160  forceinline bool
161  Test::pmi(void) const {
162  return reified && ((rms & (1 << Gecode::RM_PMI)) != 0);
163  }
164  inline
165  Test::Test(const std::string& p, const std::string& s,
166  int a, const Gecode::IntSet& d, bool r,
168  : Base(p+s), arity(a), dom(d),
169  reified(r), rms((1 << Gecode::RM_EQV) |
170  (1 << Gecode::RM_IMP) |
171  (1 << Gecode::RM_PMI)),
172  ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
173  testsearch(true), testfix(true) {}
174 
175  inline
176  Test::Test(const std::string& s,
177  int a, const Gecode::IntSet& d, bool r,
179  : Base("Int::"+s), arity(a), dom(d),
180  reified(r), rms((1 << Gecode::RM_EQV) |
181  (1 << Gecode::RM_IMP) |
182  (1 << Gecode::RM_PMI)),
183  ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
184  testsearch(true), testfix(true) {}
185 
186  inline
187  Test::Test(const std::string& p, const std::string& s,
188  int a, int min, int max, bool r,
190  : Base(p+s), arity(a), dom(min,max),
191  reified(r), rms((1 << Gecode::RM_EQV) |
192  (1 << Gecode::RM_IMP) |
193  (1 << Gecode::RM_PMI)),
194  ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
195  testsearch(true), testfix(true) {}
196 
197  inline
198  Test::Test(const std::string& s,
199  int a, int min, int max, bool r, Gecode::IntPropLevel i)
200  : Base("Int::"+s), arity(a), dom(min,max),
201  reified(r), rms((1 << Gecode::RM_EQV) |
202  (1 << Gecode::RM_IMP) |
203  (1 << Gecode::RM_PMI)),
204  ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
205  testsearch(true), testfix(true) {}
206 
207  inline
208  std::string
210  using namespace Gecode;
211  std::stringstream s;
212  switch (vbd(ipl)) {
213  case IPL_VAL: s << "Val"; break;
214  case IPL_BND: s << "Bnd"; break;
215  case IPL_DOM: s << "Dom"; break;
216  default: s << "Def"; break;
217  }
218  if (ipl & IPL_BASIC) s << "+B";
219  if (ipl & IPL_ADVANCED) s << "+A";
220  return s.str();
221  }
222 
223  inline
224  std::string
226  using namespace Gecode;
227  switch (irt) {
228  case IRT_LQ: return "Lq";
229  case IRT_LE: return "Le";
230  case IRT_GQ: return "Gq";
231  case IRT_GR: return "Gr";
232  case IRT_EQ: return "Eq";
233  case IRT_NQ: return "Nq";
234  default: ;
235  }
236  GECODE_NEVER;
237  return "NONE";
238  }
239 
240  inline std::string
242  using namespace Gecode;
243  switch (bot) {
244  case BOT_AND: return "And";
245  case BOT_OR: return "Or";
246  case BOT_IMP: return "Imp";
247  case BOT_EQV: return "Eqv";
248  case BOT_XOR: return "Xor";
249  default: GECODE_NEVER;
250  }
251  GECODE_NEVER;
252  return "NONE";
253  }
254 
255  inline
256  std::string
257  Test::str(bool b) {
258  std::stringstream s;
259  if (b)
260  s << "+";
261  else
262  s << "-";
263  return s.str();
264  }
265 
266  inline
267  std::string
268  Test::str(int i) {
269  std::stringstream s;
270  s << i;
271  return s.str();
272  }
273 
274  inline
275  std::string
277  std::string s = "";
278  for (int i=0; i<x.size()-1; i++)
279  s += str(x[i]) + ",";
280  return "[" + s + str(x[x.size()-1]) + "]";
281  }
282 
283  template<class T>
284  inline bool
286  using namespace Gecode;
287  switch (r) {
288  case IRT_EQ: return x == y;
289  case IRT_NQ: return x != y;
290  case IRT_LQ: return x <= y;
291  case IRT_LE: return x < y;
292  case IRT_GR: return x > y;
293  case IRT_GQ: return x >= y;
294  default: ;
295  }
296  return false;
297  }
298 
299 
300 
301  inline
303  : i(sizeof(ipls)/sizeof(Gecode::IntPropLevel)-1) {}
304  inline bool
306  return i>=0;
307  }
308  inline void
310  i--;
311  }
312  inline Gecode::IntPropLevel
313  IntPropLevels::ipl(void) const {
314  return ipls[i];
315  }
316 
317 
318  inline
320  : i(sizeof(ipls)/sizeof(Gecode::IntPropLevel)-1) {}
321  inline bool
323  return i>=0;
324  }
325  inline void
327  i--;
328  }
329  inline Gecode::IntPropLevel
331  return ipls[i];
332  }
333 
334 
335  inline
337  : i(sizeof(irts)/sizeof(Gecode::IntRelType)-1) {}
338  inline void
340  i = sizeof(irts)/sizeof(Gecode::IntRelType)-1;
341  }
342  inline bool
344  return i>=0;
345  }
346  inline void
348  i--;
349  }
350  inline Gecode::IntRelType
351  IntRelTypes::irt(void) const {
352  return irts[i];
353  }
354 
355  inline
357  : i(sizeof(bots)/sizeof(Gecode::BoolOpType)-1) {}
358  inline bool
360  return i>=0;
361  }
362  inline void
364  i--;
365  }
366  inline Gecode::BoolOpType
367  BoolOpTypes::bot(void) const {
368  return bots[i];
369  }
370 
371 }}
372 
373 // STATISTICS: test-int
374 
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
IntRelType
Relation types for integers.
Definition: int.hh:925
Region r
Definition: region.cpp:65
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
Conjunction.
Definition: int.hh:951
virtual ~Assignment(void)
Destructor.
Definition: int.hpp:50
void reset(void)
Reset iterator.
Definition: int.hpp:339
Inverse implication for reification.
Definition: int.hh:869
void operator++(void)
Increment to next level.
Definition: int.hpp:309
virtual int operator[](int i) const
Return value for variable i.
Definition: int.hpp:138
virtual int operator[](int i) const
Return value for variable i.
Definition: int.hpp:99
void operator++(void)
Increment to next level.
Definition: int.hpp:326
Greater or equal ( )
Definition: int.hh:930
Gecode::IntPropLevel ipl
Propagation level.
Definition: int.hh:234
void operator++(void)
Increment to next relation type.
Definition: int.hpp:347
Gecode::IntRelType irt(void) const
Return current relation type.
Definition: int.hpp:351
BoolOpTypes(void)
Initialize iterator.
Definition: int.hpp:356
Less ( )
Definition: int.hh:929
Use advanced propagation algorithm.
Definition: int.hh:982
int n
Number of variables.
Definition: int.hh:61
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:322
Test for domain-consistency.
Definition: int.hh:141
int randval(const Gecode::IntSet &d)
Definition: int.hpp:109
No consistency-test.
Definition: int.hh:140
int a
How many assigments still to be generated.
Definition: int.hh:119
Implication for reification.
Definition: int.hh:862
Value propagation.
Definition: int.hh:977
const FloatNum min
Smallest allowed float value.
Definition: float.hh:846
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:974
static Gecode::Support::RandomGenerator rand
Random number generator.
Definition: test.hh:134
static bool cmp(T x, Gecode::IntRelType r, T y)
Compare x and y with respect to r.
Definition: int.hpp:285
int val(void) const
Return current value.
Range iterator for integer sets.
Definition: int.hh:292
unsigned int size(void) const
Return size (cardinality) of set.
Definition: int-set-1.hpp:198
Equivalence.
Definition: int.hh:954
virtual int operator[](int i) const
Return value for variable i.
Definition: int.hpp:65
int size(void) const
Return number of variables.
Definition: int.hpp:46
virtual ~CpltAssignment(void)
Destructor.
Definition: int.hpp:70
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:305
Gecode toplevel namespace
Base class for all tests to be run
Definition: test.hh:103
Gecode::IntPropLevel ipl(void) const
Return current level.
Definition: int.hpp:313
Integer sets.
Definition: int.hh:174
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: int.hpp:133
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
Definition: ipl.hpp:37
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:359
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:249
BoolOpType
Operation types for Booleans.
Definition: int.hh:950
Implication.
Definition: int.hh:953
IntPropLevels(void)
Initialize iterator.
Definition: int.hpp:302
IntRelTypes(void)
Initialize iterator.
Definition: int.hpp:336
Equivalence for reification (default)
Definition: int.hh:855
Gecode::IntSetValues * dsv
Iterator for each variable.
Definition: int.hh:81
bool imp(void) const
Test whether implication as reification mode is supported.
Definition: int.hpp:157
CpltAssignment(int n, const Gecode::IntSet &d)
Initialize assignments for n0 variables and values d0.
Definition: int.hpp:54
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition: dom.cpp:40
Domain propagation Options: basic versus advanced propagation.
Definition: int.hh:979
int a
How many assigments still to be generated Generate new value according to domain.
Definition: int.hh:99
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: int.hpp:61
IntPropBasicAdvanced(void)
Initialize iterator.
Definition: int.hpp:319
int * vals
The current values for the variables.
Definition: int.hh:98
void operator++(void)
Increment to next operation type.
Definition: int.hpp:363
int randval(void)
Definition: int.hpp:76
Gecode::BoolOpType bot(void) const
Return current operation type.
Definition: int.hpp:367
virtual ~RandomAssignment(void)
Destructor.
Definition: int.hpp:104
Bounds propagation.
Definition: int.hh:978
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56
bool eqv(void) const
Test whether equivalence as reification mode is supported.
Definition: int.hpp:153
Gecode::IntSet d1(v1, 7)
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
Definition: int.hpp:161
int * vals
The current values for the variables.
Definition: int.hh:118
RandomAssignment(int n, const Gecode::IntSet &d, int a)
Initialize for a assignments for n0 variables and values d0.
Definition: int.hpp:88
RandomMixAssignment(int n0, const Gecode::IntSet &d0, int n1, const Gecode::IntSet &d1, int a0)
Initialize for a assignments for n0 variables and values d0.
Definition: int.hpp:121
Base class for assignments
Definition: int.hh:59
Use basic propagation algorithm.
Definition: int.hh:981
bool reified
Does the constraint also exist as reified constraint.
Definition: int.hh:230
Exclusive or.
Definition: int.hh:955
Assignment(int n0, const Gecode::IntSet &d0)
Initialize assignments for n0 variables and values d0.
Definition: int.hpp:43
Gecode::IntSet d(v, 7)
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:343
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: int.hpp:95
virtual ~RandomMixAssignment(void)
Destructor.
Definition: int.hpp:144
General test support.
Definition: afc.cpp:39
#define forceinline
Definition: config.hpp:185
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:165
Disjunction.
Definition: int.hh:952
Gecode::IntSet _d1
Domain for second set of variables Generate new value according to domain d.
Definition: int.hh:121
Equality ( )
Definition: int.hh:926
Disequality ( )
Definition: int.hh:927
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Greater ( )
Definition: int.hh:931
Passing integer arguments.
Definition: int.hh:628
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::IntSet d
Domain for each variable.
Definition: int.hh:62
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
const FloatNum max
Largest allowed float value.
Definition: float.hh:844
int rms
Which reification modes are supported.
Definition: int.hh:232
Less or equal ( )
Definition: int.hh:928
Gecode::IntPropLevel ipl(void) const
Return current level.
Definition: int.hpp:330
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition: int.hpp:209