Generated on Tue Jan 28 2020 00:00:00 for Gecode by doxygen 1.8.17
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: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
13  * $Revision: 14967 $
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)),
186  ipl(i), contest(ipl == Gecode::IPL_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  ipl(i), contest(ipl == Gecode::IPL_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::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)),
207  ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
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_SPEED) s << "+S";
222  if (ipl & IPL_MEMORY) s << "+M";
223  if (ipl & IPL_BASIC) s << "+B";
224  if (ipl & IPL_ADVANCED) s << "+A";
225  return s.str();
226  }
227 
228  inline
229  std::string
231  using namespace Gecode;
232  switch (irt) {
233  case IRT_LQ: return "Lq";
234  case IRT_LE: return "Le";
235  case IRT_GQ: return "Gq";
236  case IRT_GR: return "Gr";
237  case IRT_EQ: return "Eq";
238  case IRT_NQ: return "Nq";
239  default: ;
240  }
241  GECODE_NEVER;
242  return "NONE";
243  }
244 
245  inline std::string
247  using namespace Gecode;
248  switch (bot) {
249  case BOT_AND: return "And";
250  case BOT_OR: return "Or";
251  case BOT_IMP: return "Imp";
252  case BOT_EQV: return "Eqv";
253  case BOT_XOR: return "Xor";
254  default: GECODE_NEVER;
255  }
256  GECODE_NEVER;
257  return "NONE";
258  }
259 
260  inline
261  std::string
262  Test::str(int i) {
263  std::stringstream s;
264  s << i;
265  return s.str();
266  }
267 
268  inline
269  std::string
271  std::string s = "";
272  for (int i=0; i<x.size()-1; i++)
273  s += str(x[i]) + ",";
274  return "[" + s + str(x[x.size()-1]) + "]";
275  }
276 
277  template<class T>
278  inline bool
280  using namespace Gecode;
281  switch (r) {
282  case IRT_EQ: return x == y;
283  case IRT_NQ: return x != y;
284  case IRT_LQ: return x <= y;
285  case IRT_LE: return x < y;
286  case IRT_GR: return x > y;
287  case IRT_GQ: return x >= y;
288  default: ;
289  }
290  return false;
291  }
292 
293 
294 
295  inline
297  : i(sizeof(ipls)/sizeof(Gecode::IntPropLevel)-1) {}
298  inline bool
300  return i>=0;
301  }
302  inline void
304  i--;
305  }
306  inline Gecode::IntPropLevel
307  IntPropLevels::ipl(void) const {
308  return ipls[i];
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  }
323  inline Gecode::IntPropLevel
325  return ipls[i];
326  }
327 
328 
329  inline
331  : i(sizeof(irts)/sizeof(Gecode::IntRelType)-1) {}
332  inline void
334  i = sizeof(irts)/sizeof(Gecode::IntRelType)-1;
335  }
336  inline bool
338  return i>=0;
339  }
340  inline void
342  i--;
343  }
344  inline Gecode::IntRelType
345  IntRelTypes::irt(void) const {
346  return irts[i];
347  }
348 
349  inline
351  : i(sizeof(bots)/sizeof(Gecode::BoolOpType)-1) {}
352  inline bool
354  return i>=0;
355  }
356  inline void
358  i--;
359  }
360  inline Gecode::BoolOpType
361  BoolOpTypes::bot(void) const {
362  return bots[i];
363  }
364 
365 }}
366 
367 // STATISTICS: test-int
368 
IntRelType
Relation types for integers.
Definition: int.hh:906
Region r
Definition: region.cpp:82
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:784
@ BOT_AND
Conjunction.
Definition: int.hh:932
#define forceinline
Definition: config.hpp:173
virtual ~Assignment(void)
Destructor.
Definition: int.hpp:54
void reset(void)
Reset iterator.
Definition: int.hpp:333
@ RM_PMI
Inverse implication for reification.
Definition: int.hh:850
void operator++(void)
Increment to next level.
Definition: int.hpp:303
virtual int operator[](int i) const
Return value for variable i.
Definition: int.hpp:141
virtual int operator[](int i) const
Return value for variable i.
Definition: int.hpp:103
void operator++(void)
Increment to next level.
Definition: int.hpp:320
@ IRT_GQ
Greater or equal ( )
Definition: int.hh:911
Gecode::IntPropLevel ipl
Propagation level.
Definition: int.hh:238
void operator++(void)
Increment to next relation type.
Definition: int.hpp:341
Gecode::IntRelType irt(void) const
Return current relation type.
Definition: int.hpp:345
BoolOpTypes(void)
Initialize iterator.
Definition: int.hpp:350
@ IRT_LE
Less ( )
Definition: int.hh:910
@ IPL_ADVANCED
Use advanced propagation algorithm.
Definition: int.hh:966
int n
Number of variables.
Definition: int.hh:65
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:316
@ CTL_DOMAIN
Test for domain-consistency.
Definition: int.hh:145
int randval(const Gecode::IntSet &d)
Definition: int.hpp:113
@ CTL_NONE
No consistency-test.
Definition: int.hh:144
int a
How many assigments still to be generated.
Definition: int.hh:123
@ RM_IMP
Implication for reification.
Definition: int.hh:843
Gecode::IntArgs i(4, 1, 2, 3, 4)
@ IPL_VAL
Value propagation.
Definition: int.hh:958
const FloatNum min
Smallest allowed float value.
Definition: float.hh:850
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:955
static Gecode::Support::RandomGenerator rand
Random number generator.
Definition: test.hh:138
static bool cmp(T x, Gecode::IntRelType r, T y)
Compare x and y with respect to r.
Definition: int.hpp:279
int val(void) const
Return current value.
Range iterator for integer sets.
Definition: int.hh:274
unsigned int size(void) const
Return size (cardinality) of set.
Definition: int-set-1.hpp:161
@ BOT_EQV
Equivalence.
Definition: int.hh:935
virtual int operator[](int i) const
Return value for variable i.
Definition: int.hpp:69
int size(void) const
Return number of variables.
Definition: int.hpp:50
virtual ~CpltAssignment(void)
Destructor.
Definition: int.hpp:74
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:299
Gecode toplevel namespace
Base class for all tests to be run
Definition: test.hh:107
Gecode::IntPropLevel ipl(void) const
Return current level.
Definition: int.hpp:307
Integer sets.
Definition: int.hh:174
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: int.hpp:136
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
Definition: ipl.hpp:41
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:353
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
BoolOpType
Operation types for Booleans.
Definition: int.hh:931
@ BOT_IMP
Implication.
Definition: int.hh:934
IntPropLevels(void)
Initialize iterator.
Definition: int.hpp:296
IntRelTypes(void)
Initialize iterator.
Definition: int.hpp:330
@ RM_EQV
Equivalence for reification (default)
Definition: int.hh:836
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
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
CpltAssignment(int n, const Gecode::IntSet &d)
Initialize assignments for n0 variables and values d0.
Definition: int.hpp:58
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition: dom.cpp:44
@ IPL_DOM
Domain propagation Preferences: prefer speed or memory.
Definition: int.hh:960
int a
How many assigments still to be generated Generate new value according to domain.
Definition: int.hh:103
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: int.hpp:65
IntPropBasicAdvanced(void)
Initialize iterator.
Definition: int.hpp:313
int * vals
The current values for the variables.
Definition: int.hh:102
void operator++(void)
Increment to next operation type.
Definition: int.hpp:357
int randval(void)
Definition: int.hpp:80
Gecode::BoolOpType bot(void) const
Return current operation type.
Definition: int.hpp:361
virtual ~RandomAssignment(void)
Destructor.
Definition: int.hpp:108
@ IPL_BND
Bounds propagation.
Definition: int.hh:959
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
bool eqv(void) const
Test whether equivalence as reification mode is supported.
Definition: int.hpp:156
Gecode::IntSet d1(v1, 7)
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
Definition: int.hpp:164
int * vals
The current values for the variables.
Definition: int.hh:122
RandomAssignment(int n, const Gecode::IntSet &d, int a)
Initialize for a assignments for n0 variables and values d0.
Definition: int.hpp:92
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
Base class for assignments
Definition: int.hh:63
@ IPL_BASIC
Use basic propagation algorithm.
Definition: int.hh:965
bool reified
Does the constraint also exist as reified constraint.
Definition: int.hh:234
@ BOT_XOR
Exclusive or.
Definition: int.hh:936
Assignment(int n0, const Gecode::IntSet &d0)
Initialize assignments for n0 variables and values d0.
Definition: int.hpp:47
Gecode::IntSet d(v, 7)
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:337
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: int.hpp:99
virtual ~RandomMixAssignment(void)
Destructor.
Definition: int.hpp:147
General test support.
Definition: afc.cpp:43
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
@ BOT_OR
Disjunction.
Definition: int.hh:933
Gecode::IntSet _d1
Domain for second set of variables Generate new value according to domain d.
Definition: int.hh:125
@ IRT_EQ
Equality ( )
Definition: int.hh:907
@ IRT_NQ
Disequality ( )
Definition: int.hh:908
@ IPL_MEMORY
Prefer to save memory Options: basic versus advanced propagation.
Definition: int.hh:963
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
@ IRT_GR
Greater ( )
Definition: int.hh:912
Passing integer arguments.
Definition: int.hh:610
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
@ IPL_SPEED
Prefer speed.
Definition: int.hh:962
const FloatNum max
Largest allowed float value.
Definition: float.hh:848
int rms
Which reification modes are supported.
Definition: int.hh:236
@ IRT_LQ
Less or equal ( )
Definition: int.hh:909
Gecode::IntPropLevel ipl(void) const
Return current level.
Definition: int.hpp:324
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition: int.hpp:212