Generated on Sat Feb 7 2015 02:01:22 for Gecode by doxygen 1.8.9.1
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: 2013-03-12 20:00:00 +0100 (Tue, 12 Mar 2013) $ by $Author: schulte $
13  * $Revision: 13507 $
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  icl(i), contest(icl == Gecode::ICL_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)),
186  icl(i), contest(icl == Gecode::ICL_DOM ? CTL_DOMAIN : CTL_NONE),
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)),
197  icl(i), contest(icl == Gecode::ICL_DOM ? CTL_DOMAIN : CTL_NONE),
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::IntConLevel 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)),
207  icl(i), contest(icl == Gecode::ICL_DOM ? CTL_DOMAIN : CTL_NONE),
208  testsearch(true), testfix(true) {}
209 
210  inline
211  std::string
213  using namespace Gecode;
214  switch (epk) {
215  case EPK_MEMORY: return "Memory";
216  case EPK_SPEED: return "Speed";
217  default: return "Def";
218  }
219  }
220 
221  inline
222  std::string
224  using namespace Gecode;
225  switch (icl) {
226  case ICL_VAL: return "Val";
227  case ICL_BND: return "Bnd";
228  case ICL_DOM: return "Dom";
229  default: return "Def";
230  }
231  }
232 
233  inline
234  std::string
236  using namespace Gecode;
237  switch (irt) {
238  case IRT_LQ: return "Lq";
239  case IRT_LE: return "Le";
240  case IRT_GQ: return "Gq";
241  case IRT_GR: return "Gr";
242  case IRT_EQ: return "Eq";
243  case IRT_NQ: return "Nq";
244  default: ;
245  }
246  GECODE_NEVER;
247  return "NONE";
248  }
249 
250  inline std::string
252  using namespace Gecode;
253  switch (bot) {
254  case BOT_AND: return "And";
255  case BOT_OR: return "Or";
256  case BOT_IMP: return "Imp";
257  case BOT_EQV: return "Eqv";
258  case BOT_XOR: return "Xor";
259  default: GECODE_NEVER;
260  }
261  GECODE_NEVER;
262  return "NONE";
263  }
264 
265  inline
266  std::string
267  Test::str(int i) {
268  std::stringstream s;
269  s << i;
270  return s.str();
271  }
272 
273  inline
274  std::string
276  std::string s = "";
277  for (int i=0; i<x.size()-1; i++)
278  s += str(x[i]) + ",";
279  return "[" + s + str(x[x.size()-1]) + "]";
280  }
281 
282  template<class T>
283  inline bool
285  using namespace Gecode;
286  switch (r) {
287  case IRT_EQ: return x == y;
288  case IRT_NQ: return x != y;
289  case IRT_LQ: return x <= y;
290  case IRT_LE: return x < y;
291  case IRT_GR: return x > y;
292  case IRT_GQ: return x >= y;
293  default: ;
294  }
295  return false;
296  }
297 
298 
299 
300  inline
302  : i(sizeof(icls)/sizeof(Gecode::IntConLevel)-1) {}
303  inline bool
305  return i>=0;
306  }
307  inline void
309  i--;
310  }
311  inline Gecode::IntConLevel
312  IntConLevels::icl(void) const {
313  return icls[i];
314  }
315 
316 
317  inline
319  : i(sizeof(irts)/sizeof(Gecode::IntRelType)-1) {}
320  inline void
322  i = sizeof(irts)/sizeof(Gecode::IntRelType)-1;
323  }
324  inline bool
326  return i>=0;
327  }
328  inline void
330  i--;
331  }
332  inline Gecode::IntRelType
333  IntRelTypes::irt(void) const {
334  return irts[i];
335  }
336 
337  inline
339  : i(sizeof(bots)/sizeof(Gecode::BoolOpType)-1) {}
340  inline bool
342  return i>=0;
343  }
344  inline void
346  i--;
347  }
348  inline Gecode::BoolOpType
349  BoolOpTypes::bot(void) const {
350  return bots[i];
351  }
352 
353 }}
354 
355 // STATISTICS: test-int
356 
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
RandomAssignment(int n, const Gecode::IntSet &d, int a)
Initialize for a assignments for n0 variables and values d0.
Definition: int.hpp:92
IntConLevel
Consistency levels for integer propagators.
Definition: int.hh:937
Inverse implication for reification.
Definition: int.hh:847
Range iterator for integer sets.
Definition: int.hh:271
const FloatNum max
Largest allowed float value.
Definition: float.hh:831
Test(const std::string &p, const std::string &s, int a, const Gecode::IntSet &d, bool r=false, Gecode::IntConLevel i=Gecode::ICL_DEF)
Constructor.
Definition: int.hpp:168
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1662
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:916
static bool cmp(T x, Gecode::IntRelType r, T y)
Compare x and y with respect to r.
Definition: int.hpp:284
Value propagation or consistency (naive)
Definition: int.hh:938
Less or equal ( )
Definition: int.hh:906
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: int.hpp:99
Conjunction.
Definition: int.hh:917
virtual ~RandomAssignment(void)
Destructor.
Definition: int.hpp:108
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: int.hpp:65
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition: dom.cpp:44
Implication.
Definition: int.hh:919
Greater ( )
Definition: int.hh:909
bool eqv(void) const
Test whether equivalence as reification mode is supported.
Definition: int.hpp:156
Gecode::IntConLevel icl(void) const
Return current level.
Definition: int.hpp:312
int rms
Which reification modes are supported.
Definition: int.hh:224
Greater or equal ( )
Definition: int.hh:908
virtual ~CpltAssignment(void)
Destructor.
Definition: int.hpp:74
Exclusive or.
Definition: int.hh:921
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
static std::string str(Gecode::ExtensionalPropKind epk)
Map extensional propagation kind to string.
Definition: int.hpp:212
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
const FloatNum min
Smallest allowed float value.
Definition: float.hh:833
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:904
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:304
Prefer speed over memory consumption.
Definition: int.hh:1984
No consistency-test.
Definition: int.hh:144
Gecode::IntConLevel icl
Consistency level.
Definition: int.hh:226
IntRelType
Relation types for integers.
Definition: int.hh:903
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
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
void operator++(void)
Increment to next level.
Definition: int.hpp:308
int * vals
The current values for the variables.
Definition: int.hh:122
IntRelTypes(void)
Initialize iterator.
Definition: int.hpp:318
virtual int operator[](int i) const
Return value for variable i.
Definition: int.hpp:103
Base class for all tests to be run
Definition: test.hh:107
Gecode::IntSetValues * dsv
Iterator for each variable.
Definition: int.hh:85
bool imp(void) const
Test whether implication as reification mode is supported.
Definition: int.hpp:160
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
Definition: int.hpp:164
Less ( )
Definition: int.hh:907
Integer sets.
Definition: int.hh:171
Test for domain-consistency.
Definition: int.hh:145
int randval(const Gecode::IntSet &d)
Definition: int.hpp:113
ExtensionalPropKind
Extensional propagation kind.
Definition: int.hh:1982
Disjunction.
Definition: int.hh:918
Gecode::IntRelType irt(void) const
Return current relation type.
Definition: int.hpp:333
unsigned int size(void) const
Return size (cardinality) of set.
Definition: int-set-1.hpp:161
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:341
Passing integer arguments.
Definition: int.hh:607
void operator++(void)
Increment to next operation type.
Definition: int.hpp:345
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: int.hpp:136
virtual ~RandomMixAssignment(void)
Destructor.
Definition: int.hpp:147
General test support.
Definition: afc.cpp:43
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
Assignment(int n0, const Gecode::IntSet &d0)
Initialize assignments for n0 variables and values d0.
Definition: int.hpp:47
Base class for assignments
Definition: int.hh:63
#define forceinline
Definition: config.hpp:132
IntConLevels(void)
Initialize iterator.
Definition: int.hpp:301
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:325
Equivalence.
Definition: int.hh:920
void operator++(void)
Increment to next relation type.
Definition: int.hpp:329
int val(void) const
Return current value.
virtual int operator[](int i) const
Return value for variable i.
Definition: int.hpp:69
Bounds propagation or consistency.
Definition: int.hh:939
BoolOpTypes(void)
Initialize iterator.
Definition: int.hpp:338
Prefer little memory over speed.
Definition: int.hh:1985
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:840
virtual int operator[](int i) const
Return value for variable i.
Definition: int.hpp:141
Disequality ( )
Definition: int.hh:905
void reset(void)
Reset iterator.
Definition: int.hpp:321
virtual ~Assignment(void)
Destructor.
Definition: int.hpp:54
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
int size(void) const
Return number of variables.
Definition: int.hpp:50
Domain propagation or consistency.
Definition: int.hh:940
bool reified
Does the constraint also exist as reified constraint.
Definition: int.hh:222
Gecode::BoolOpType bot(void) const
Return current operation type.
Definition: int.hpp:349
Equivalence for reification (default)
Definition: int.hh:833
int * vals
The current values for the variables.
Definition: int.hh:102