Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
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  * Last modified:
12  * $Date$ by $Author$
13  * $Revision$
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 namespace Test { namespace Int {
41 
42  /*
43  * Assignments
44  *
45  */
46  inline
48  : n(n0), d(d0) {}
49  inline int
50  Assignment::size(void) const {
51  return n;
52  }
53  inline
55 
56 
57  inline
59  : Assignment(n,d),
60  dsv(new Gecode::IntSetValues[static_cast<unsigned int>(n)]) {
61  for (int i=n; i--; )
62  dsv[i].init(d);
63  }
64  inline bool
66  return dsv[0]();
67  }
68  inline int
70  assert((i>=0) && (i<n));
71  return dsv[i].val();
72  }
73  inline
75  delete [] dsv;
76  }
77 
78 
79  forceinline int
81  unsigned int skip = Base::rand(d.size());
82  for (Gecode::IntSetRanges it(d); true; ++it) {
83  if (it.width() > skip)
84  return it.min() + static_cast<int>(skip);
85  skip -= it.width();
86  }
88  return 0;
89  }
90 
91  inline
93  : Assignment(n,d), vals(new int[n]), a(a0) {
94  for (int i=n; i--; )
95  vals[i] = randval();
96  }
97 
98  inline bool
100  return a>0;
101  }
102  inline int
104  assert((i>=0) && (i<n));
105  return vals[i];
106  }
107  inline
109  delete [] vals;
110  }
111 
112  forceinline int
114  unsigned int skip = Base::rand(d.size());
115  for (Gecode::IntSetRanges it(d); true; ++it) {
116  if (it.width() > skip)
117  return it.min() + static_cast<int>(skip);
118  skip -= it.width();
119  }
120  GECODE_NEVER;
121  return 0;
122  }
123 
124  inline
126  int n1, const Gecode::IntSet& d1,
127  int a0)
128  : Assignment(n0+n1,d0),vals(new int[n0+n1]),a(a0),_n1(n1),_d1(d1) {
129  for (int i=n0; i--; )
130  vals[i] = randval(d);
131  for (int i=n1; i--; )
132  vals[n0+i] = randval(_d1);
133  }
134 
135  inline bool
137  return a>0;
138  }
139 
140  inline int
142  assert((i>=0) && (i<n));
143  return vals[i];
144  }
145 
146  inline
148  delete [] vals;
149  }
150 
151  /*
152  * Tests with integer constraints
153  *
154  */
155  forceinline bool
156  Test::eqv(void) const {
157  return reified && ((rms & (1 << Gecode::RM_EQV)) != 0);
158  }
159  forceinline bool
160  Test::imp(void) const {
161  return reified && ((rms & (1 << Gecode::RM_IMP)) != 0);
162  }
163  forceinline bool
164  Test::pmi(void) const {
165  return reified && ((rms & (1 << Gecode::RM_PMI)) != 0);
166  }
167  inline
168  Test::Test(const std::string& p, const std::string& s,
169  int a, const Gecode::IntSet& d, bool r,
171  : Base(p+s), arity(a), dom(d),
172  reified(r), rms((1 << Gecode::RM_EQV) |
173  (1 << Gecode::RM_IMP) |
174  (1 << Gecode::RM_PMI)),
175  ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
176  testsearch(true), testfix(true) {}
177 
178  inline
179  Test::Test(const std::string& s,
180  int a, const Gecode::IntSet& d, bool r,
182  : Base("Int::"+s), arity(a), dom(d),
183  reified(r), rms((1 << Gecode::RM_EQV) |
184  (1 << Gecode::RM_IMP) |
185  (1 << Gecode::RM_PMI)),
187  testsearch(true), testfix(true) {}
188 
189  inline
190  Test::Test(const std::string& p, const std::string& s,
191  int a, int min, int max, bool r,
193  : Base(p+s), arity(a), dom(min,max),
194  reified(r), rms((1 << Gecode::RM_EQV) |
195  (1 << Gecode::RM_IMP) |
196  (1 << Gecode::RM_PMI)),
198  testsearch(true), testfix(true) {}
199 
200  inline
201  Test::Test(const std::string& s,
202  int a, int min, int max, bool r, Gecode::IntPropLevel i)
203  : Base("Int::"+s), arity(a), dom(min,max),
204  reified(r), rms((1 << Gecode::RM_EQV) |
205  (1 << Gecode::RM_IMP) |
206  (1 << Gecode::RM_PMI)),
208  testsearch(true), testfix(true) {}
209 
210  inline
211  std::string
213  using namespace Gecode;
214  std::stringstream s;
215  switch (vbd(ipl)) {
216  case IPL_VAL: s << "Val"; break;
217  case IPL_BND: s << "Bnd"; break;
218  case IPL_DOM: s << "Dom"; break;
219  default: s << "Def"; break;
220  }
221  if (ipl & IPL_BASIC) s << "+B";
222  if (ipl & IPL_ADVANCED) s << "+A";
223  return s.str();
224  }
225 
226  inline
227  std::string
229  using namespace Gecode;
230  switch (irt) {
231  case IRT_LQ: return "Lq";
232  case IRT_LE: return "Le";
233  case IRT_GQ: return "Gq";
234  case IRT_GR: return "Gr";
235  case IRT_EQ: return "Eq";
236  case IRT_NQ: return "Nq";
237  default: ;
238  }
239  GECODE_NEVER;
240  return "NONE";
241  }
242 
243  inline std::string
245  using namespace Gecode;
246  switch (bot) {
247  case BOT_AND: return "And";
248  case BOT_OR: return "Or";
249  case BOT_IMP: return "Imp";
250  case BOT_EQV: return "Eqv";
251  case BOT_XOR: return "Xor";
252  default: GECODE_NEVER;
253  }
254  GECODE_NEVER;
255  return "NONE";
256  }
257 
258  inline
259  std::string
260  Test::str(int i) {
261  std::stringstream s;
262  s << i;
263  return s.str();
264  }
265 
266  inline
267  std::string
269  std::string s = "";
270  for (int i=0; i<x.size()-1; i++)
271  s += str(x[i]) + ",";
272  return "[" + s + str(x[x.size()-1]) + "]";
273  }
274 
275  template<class T>
276  inline bool
278  using namespace Gecode;
279  switch (r) {
280  case IRT_EQ: return x == y;
281  case IRT_NQ: return x != y;
282  case IRT_LQ: return x <= y;
283  case IRT_LE: return x < y;
284  case IRT_GR: return x > y;
285  case IRT_GQ: return x >= y;
286  default: ;
287  }
288  return false;
289  }
290 
291 
292 
293  inline
295  : i(sizeof(ipls)/sizeof(Gecode::IntPropLevel)-1) {}
296  inline bool
298  return i>=0;
299  }
300  inline void
302  i--;
303  }
304  inline Gecode::IntPropLevel
305  IntPropLevels::ipl(void) const {
306  return ipls[i];
307  }
308 
309 
310  inline
312  : i(sizeof(ipls)/sizeof(Gecode::IntPropLevel)-1) {}
313  inline bool
315  return i>=0;
316  }
317  inline void
319  i--;
320  }
321  inline Gecode::IntPropLevel
323  return ipls[i];
324  }
325 
326 
327  inline
329  : i(sizeof(irts)/sizeof(Gecode::IntRelType)-1) {}
330  inline void
332  i = sizeof(irts)/sizeof(Gecode::IntRelType)-1;
333  }
334  inline bool
336  return i>=0;
337  }
338  inline void
340  i--;
341  }
342  inline Gecode::IntRelType
343  IntRelTypes::irt(void) const {
344  return irts[i];
345  }
346 
347  inline
349  : i(sizeof(bots)/sizeof(Gecode::BoolOpType)-1) {}
350  inline bool
352  return i>=0;
353  }
354  inline void
356  i--;
357  }
358  inline Gecode::BoolOpType
359  BoolOpTypes::bot(void) const {
360  return bots[i];
361  }
362 
363 }}
364 
365 // STATISTICS: test-int
366 
Bounds propagation.
Definition: int.hh:957
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:125
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
Definition: ipl.hpp:41
Gecode::IntPropLevel ipl(void) const
Return current level.
Definition: int.hpp:305
RandomAssignment(int n, const Gecode::IntSet &d, int a)
Initialize for a assignments for n0 variables and values d0.
Definition: int.hpp:92
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition: int.hpp:212
Inverse implication for reification.
Definition: int.hh:848
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1657
Range iterator for integer sets.
Definition: int.hh:272
const FloatNum max
Largest allowed float value.
Definition: float.hh:848
virtual int operator[](int i) const
Return value for variable i.
Definition: int.hpp:103
int size(void) const
Return number of variables.
Definition: int.hpp:50
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:314
static Gecode::Support::RandomGenerator rand
Random number generator.
Definition: test.hh:138
int a
How many assigments still to be generated Generate new value according to domain. ...
Definition: int.hh:103
BoolOpType
Operation types for Booleans.
Definition: int.hh:929
static bool cmp(T x, Gecode::IntRelType r, T y)
Compare x and y with respect to r.
Definition: int.hpp:277
bool imp(void) const
Test whether implication as reification mode is supported.
Definition: int.hpp:160
Gecode::BoolOpType bot(void) const
Return current operation type.
Definition: int.hpp:359
Less or equal ( )
Definition: int.hh:907
Conjunction.
Definition: int.hh:930
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:351
virtual ~RandomAssignment(void)
Destructor.
Definition: int.hpp:108
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition: dom.cpp:44
Gecode::IntSet dom
Domain of variables.
Definition: int.hh:232
Implication.
Definition: int.hh:932
void operator++(void)
Increment to next level.
Definition: int.hpp:318
Greater ( )
Definition: int.hh:910
#define forceinline
Definition: config.hpp:182
virtual int operator[](int i) const
Return value for variable i.
Definition: int.hpp:69
ConTestLevel contest
Whether to test for certain consistency.
Definition: int.hh:240
int rms
Which reification modes are supported.
Definition: int.hh:236
Greater or equal ( )
Definition: int.hh:909
virtual ~CpltAssignment(void)
Destructor.
Definition: int.hpp:74
int val(void) const
Return current value.
Exclusive or.
Definition: int.hh:934
void operator++(void)
Increment to next level.
Definition: int.hpp:301
int n
Number of variables.
Definition: int.hh:65
Gecode::IntSet d1(v1, 7)
Gecode::IntSet d(v, 7)
Gecode::IntSet d
Domain for each variable.
Definition: int.hh:66
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
const FloatNum min
Smallest allowed float value.
Definition: float.hh:850
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Equality ( )
Definition: int.hh:905
No consistency-test.
Definition: int.hh:144
IntRelType
Relation types for integers.
Definition: int.hh:904
CpltAssignment(int n, const Gecode::IntSet &d)
Initialize assignments for n0 variables and values d0.
Definition: int.hpp:58
int a
How many assigments still to be generated.
Definition: int.hh:123
int * vals
The current values for the variables.
Definition: int.hh:122
Gecode::IntRelType irt(void) const
Return current relation type.
Definition: int.hpp:343
IntRelTypes(void)
Initialize iterator.
Definition: int.hpp:328
unsigned int size(void) const
Return size (cardinality) of set.
Definition: int-set-1.hpp:161
Use basic propagation algorithm.
Definition: int.hh:960
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: int.hpp:65
Value propagation.
Definition: int.hh:956
Base class for all tests to be run
Definition: test.hh:107
Gecode::IntSetValues * dsv
Iterator for each variable.
Definition: int.hh:85
Less ( )
Definition: int.hh:908
Integer sets.
Definition: int.hh:174
Test for domain-consistency.
Definition: int.hh:145
Use advanced propagation algorithm.
Definition: int.hh:961
int randval(const Gecode::IntSet &d)
Definition: int.hpp:113
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: int.hpp:99
Disjunction.
Definition: int.hh:931
Gecode::IntPropLevel ipl
Propagation level.
Definition: int.hh:238
IntPropBasicAdvanced(void)
Initialize iterator.
Definition: int.hpp:311
Passing integer arguments.
Definition: int.hh:608
void operator++(void)
Increment to next operation type.
Definition: int.hpp:355
bool testfix
Whether to perform fixpoint test.
Definition: int.hh:244
virtual ~RandomMixAssignment(void)
Destructor.
Definition: int.hpp:147
General test support.
Definition: afc.cpp:43
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:953
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:769
Gecode::IntSet _d1
Domain for second set of variables Generate new value according to domain d.
Definition: int.hh:125
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
struct Gecode::@585::NNF::@62::@64 a
For atomic nodes.
Assignment(int n0, const Gecode::IntSet &d0)
Initialize assignments for n0 variables and values d0.
Definition: int.hpp:47
bool testsearch
Whether to perform search test.
Definition: int.hh:242
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:297
virtual int operator[](int i) const
Return value for variable i.
Definition: int.hpp:141
Region r
Definition: region.cpp:69
Base class for assignments
Definition: int.hh:63
Domain propagation Options: basic versus advanced propagation.
Definition: int.hh:958
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
Definition: int.hpp:164
Equivalence.
Definition: int.hh:933
bool eqv(void) const
Test whether equivalence as reification mode is supported.
Definition: int.hpp:156
void operator++(void)
Increment to next relation type.
Definition: int.hpp:339
IntPropLevels(void)
Initialize iterator.
Definition: int.hpp:294
BoolOpTypes(void)
Initialize iterator.
Definition: int.hpp:348
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:841
Disequality ( )
Definition: int.hh:906
int arity
Number of variables.
Definition: int.hh:230
void reset(void)
Reset iterator.
Definition: int.hpp:331
virtual ~Assignment(void)
Destructor.
Definition: int.hpp:54
Gecode::IntPropLevel ipl(void) const
Return current level.
Definition: int.hpp:322
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
bool reified
Does the constraint also exist as reified constraint.
Definition: int.hh:234
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: int.hpp:136
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:168
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:335
Equivalence for reification (default)
Definition: int.hh:834
int * vals
The current values for the variables.
Definition: int.hh:102