Generated on Thu Jul 25 2019 00:00:00 for Gecode by doxygen 1.8.15
int.hh
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-08-26 11:14:49 +0200 (Fri, 26 Aug 2016) $ by $Author: schulte $
13  * $Revision: 15156 $
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 #ifndef __GECODE_TEST_INT_HH__
41 #define __GECODE_TEST_INT_HH__
42 
43 #include "test/test.hh"
44 
45 #include <gecode/int.hh>
46 
47 namespace Test {
48 
50  namespace Int {
51 
62  class Assignment {
64  protected:
65  int n;
67  public:
69  Assignment(int n0, const Gecode::IntSet& d0);
71  virtual bool operator()(void) const = 0;
73  virtual void operator++(void) = 0;
75  virtual int operator[](int i) const = 0;
77  int size(void) const;
79  virtual ~Assignment(void);
80  };
81 
83  class CpltAssignment : public Assignment {
84  protected:
86  public:
88  CpltAssignment(int n, const Gecode::IntSet& d);
90  virtual bool operator()(void) const;
92  virtual void operator++(void);
94  virtual int operator[](int i) const;
96  virtual ~CpltAssignment(void);
97  };
98 
100  class RandomAssignment : public Assignment {
101  protected:
102  int* vals;
103  int a;
104  int randval(void);
106  public:
108  RandomAssignment(int n, const Gecode::IntSet& d, int a);
110  virtual bool operator()(void) const;
112  virtual void operator++(void);
114  virtual int operator[](int i) const;
116  virtual ~RandomAssignment(void);
117  };
118 
121  protected:
122  int* vals;
123  int a;
124  int _n1;
126  int randval(const Gecode::IntSet& d);
128  public:
130  RandomMixAssignment(int n0, const Gecode::IntSet& d0,
131  int n1, const Gecode::IntSet& d1, int a0);
133  virtual bool operator()(void) const;
135  virtual void operator++(void);
137  virtual int operator[](int i) const;
139  virtual ~RandomMixAssignment(void);
140  };
141 
148  };
149 
150  class Test;
151 
153  class TestSpace : public Gecode::Space {
154  public:
164  bool reified;
165 
172  TestSpace(int n, Gecode::IntSet& d, Test* t);
182  TestSpace(bool share, TestSpace& s);
184  virtual Gecode::Space* copy(bool share);
186  bool assigned(void) const;
188  void post(void);
190  bool failed(void);
192  int rndvar(void);
194  void rndrel(const Assignment& a, int i, Gecode::IntRelType& irt, int& v);
196  void rel(int i, Gecode::IntRelType irt, int n);
198  void rel(bool sol);
200  void assign(const Assignment& a, bool skip=false);
202  void bound(void);
208  void prune(int i, bool bounds_only);
210  void prune(void);
212  bool prune(const Assignment& a, bool testfix);
214  void disable(void);
216  void enable(void);
218  bool disabled(const Assignment& a, TestSpace& c, bool testfix);
220  unsigned int propagators(void);
221  };
222 
227  class Test : public Base {
228  protected:
230  int arity;
234  bool reified;
236  int rms;
244  bool testfix;
246 
247  bool eqv(void) const;
250  bool imp(void) const;
252  bool pmi(void) const;
254  public:
263  Test(const std::string& p, const std::string& s,
264  int a, const Gecode::IntSet& d, bool r=false,
274  Test(const std::string& s,
275  int a, const Gecode::IntSet& d, bool r=false,
285  Test(const std::string& p, const std::string& s,
286  int a, int min, int max, bool r=false,
296  Test(const std::string& s,
297  int a, int min, int max, bool r=false,
300  virtual Assignment* assignment(void) const;
302  virtual bool solution(const Assignment&) const = 0;
304  virtual bool ignore(const Assignment&) const;
306  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) = 0;
308  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
309  Gecode::Reify r);
311  virtual bool run(void);
313 
314  static std::string str(Gecode::IntPropLevel ipl);
317  static std::string str(Gecode::IntRelType irl);
319  static std::string str(Gecode::BoolOpType bot);
321  static std::string str(int i);
323  static std::string str(const Gecode::IntArgs& i);
325 
327  template<class T> static bool cmp(T x, Gecode::IntRelType r, T y);
330  };
332 
335  private:
337  static const Gecode::IntPropLevel ipls[3];
339  int i;
340  public:
342  IntPropLevels(void);
344  bool operator()(void) const;
346  void operator++(void);
348  Gecode::IntPropLevel ipl(void) const;
349  };
350 
353  private:
355  static const Gecode::IntPropLevel ipls[3];
357  int i;
358  public:
360  IntPropBasicAdvanced(void);
362  bool operator()(void) const;
364  void operator++(void);
366  Gecode::IntPropLevel ipl(void) const;
367  };
368 
370  class IntRelTypes {
371  private:
373  static const Gecode::IntRelType irts[6];
375  int i;
376  public:
378  IntRelTypes(void);
380  void reset(void);
382  bool operator()(void) const;
384  void operator++(void);
386  Gecode::IntRelType irt(void) const;
387  };
388 
390  class BoolOpTypes {
391  private:
393  static const Gecode::BoolOpType bots[5];
395  int i;
396  public:
398  BoolOpTypes(void);
400  bool operator()(void) const;
402  void operator++(void);
404  Gecode::BoolOpType bot(void) const;
405  };
406 
407  }
408 }
409 
414 std::ostream& operator<<(std::ostream& os, const Test::Int::Assignment& a);
415 
416 #include "test/int.hpp"
417 
418 #endif
419 
420 // STATISTICS: test-int
421 
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
virtual void operator++(void)
Move to next assignment.
Definition: int.cpp:74
Gecode::IntPropLevel ipl(void) const
Return current level.
Definition: int.hpp:307
NodeType t
Type of node.
Definition: bool-expr.cpp:234
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
Gecode::IntSet d
Initial domain.
Definition: int.hh:156
Gecode::IntVarArray x
Variables to be tested.
Definition: int.hh:158
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)=0
Post constraint.
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:316
virtual void operator++(void)
Move to next assignment.
Definition: int.cpp:52
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:931
static bool cmp(T x, Gecode::IntRelType r, T y)
Compare x and y with respect to r.
Definition: int.hpp:279
bool imp(void) const
Test whether implication as reification mode is supported.
Definition: int.hpp:160
bool assigned(void) const
Test whether all variables are assigned.
Definition: int.cpp:141
Gecode::BoolOpType bot(void) const
Return current operation type.
Definition: int.hpp:361
Gecode::Reify r
Reification information.
Definition: int.hh:160
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:353
virtual ~RandomAssignment(void)
Destructor.
Definition: int.hpp:108
Gecode::IntSet dom
Domain of variables.
Definition: int.hh:232
Integer variable array.
Definition: int.hh:744
bool failed(void)
Compute a fixpoint and check for failure.
Definition: int.cpp:162
virtual Assignment * assignment(void) const
Create assignment.
Definition: int.cpp:437
void operator++(void)
Increment to next level.
Definition: int.hpp:320
Space for executing tests.
Definition: int.hh:153
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
const int max
Largest allowed integer value.
Definition: int.hh:116
int rms
Which reification modes are supported.
Definition: int.hh:236
Computation spaces.
Definition: core.hpp:1748
int _n1
How many variables in the second set.
Definition: int.hh:124
virtual ~CpltAssignment(void)
Destructor.
Definition: int.hpp:74
Generate random selection of assignments.
Definition: int.hh:100
const int min
Smallest allowed integer value.
Definition: int.hh:118
Iterator for basic and advanced integer propagation levels.
Definition: int.hh:352
void operator++(void)
Increment to next level.
Definition: int.hpp:303
int n
Number of variables.
Definition: int.hh:65
virtual Gecode::Space * copy(bool share)
Copy space during cloning.
Definition: int.cpp:136
Gecode::IntSet d1(v1, 7)
virtual int operator[](int i) const =0
Return value for variable i.
Gecode::IntSet d(v, 7)
Gecode::IntSet d
Domain for each variable.
Definition: int.hh:66
void prune(void)
Prune some random values for some random variable.
Definition: int.cpp:313
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
void rndrel(const Assignment &a, int i, Gecode::IntRelType &irt, int &v)
Randomly select a pruning rel for variable i.
Definition: int.cpp:185
No consistency-test.
Definition: int.hh:144
Generate random selection of assignments.
Definition: int.hh:120
virtual bool run(void)
Perform test.
Definition: int.cpp:468
IntRelType
Relation types for integers.
Definition: int.hh:906
ConTestLevel
Level of consistency to test for.
Definition: int.hh:143
void rel(int i, Gecode::IntRelType irt, int n)
Perform integer tell operation on x[i].
Definition: int.cpp:234
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 bound(void)
Assing a random variable to a random bound.
Definition: int.cpp:272
Simple propagation levels.
Definition: int.hh:957
int * vals
The current values for the variables.
Definition: int.hh:122
Gecode::IntRelType irt(void) const
Return current relation type.
Definition: int.hpp:345
IntRelTypes(void)
Initialize iterator.
Definition: int.hpp:330
Iterator for integer relation types.
Definition: int.hh:370
virtual void operator++(void)=0
Move to next assignment.
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: int.hpp:65
Reification specification.
Definition: int.hh:857
Base class for all tests to be run
Definition: test.hh:107
TestSpace(int n, Gecode::IntSet &d, Test *t)
Create test space without reification.
Definition: int.cpp:95
Gecode::IntSetValues * dsv
Iterator for each variable.
Definition: int.hh:85
Test for bounds(z)-consistency.
Definition: int.hh:147
Test for bounds(d)-consistency.
Definition: int.hh:146
Integer sets.
Definition: int.hh:174
Test for domain-consistency.
Definition: int.hh:145
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
unsigned int propagators(void)
Return the number of propagators.
Definition: int.cpp:418
Gecode::IntPropLevel ipl
Propagation level.
Definition: int.hh:238
void disable(void)
Disable propagators in space and compute fixpoint (make all idle)
Definition: int.cpp:364
IntPropBasicAdvanced(void)
Initialize iterator.
Definition: int.hpp:313
Passing integer arguments.
Definition: int.hh:610
void operator++(void)
Increment to next operation type.
Definition: int.hpp:357
bool testfix
Whether to perform fixpoint test.
Definition: int.hh:244
const int v[7]
Definition: distinct.cpp:263
void enable(void)
Enable propagators in space.
Definition: int.cpp:359
virtual ~RandomMixAssignment(void)
Destructor.
Definition: int.hpp:147
General test support.
Definition: afc.cpp:43
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:955
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:784
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
bool testsearch
Whether to perform search test.
Definition: int.hh:242
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:299
virtual int operator[](int i) const
Return value for variable i.
Definition: int.hpp:141
Region r
Definition: region.cpp:82
void assign(const Assignment &a, bool skip=false)
Assign all (or all but one, if skip is true) variables to values in a.
Definition: int.cpp:260
Base class for assignments
Definition: int.hh:63
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
Definition: int.hpp:164
struct Gecode::Space::@56::@58 c
Data available only during copying.
Value iterator for integer sets.
Definition: int.hh:315
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:341
IntPropLevels(void)
Initialize iterator.
Definition: int.hpp:296
bool disabled(const Assignment &a, TestSpace &c, bool testfix)
Prune values also in a space c with disabled propagators, but not those in assignment a.
Definition: int.cpp:370
BoolOpTypes(void)
Initialize iterator.
Definition: int.hpp:350
Iterator for Boolean operation types.
Definition: int.hh:390
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const FloatView &x)
Print float variable view.
Definition: print.hpp:62
int arity
Number of variables.
Definition: int.hh:230
virtual bool ignore(const Assignment &) const
Whether to ignore assignment for reification.
Definition: int.cpp:459
virtual bool operator()(void) const =0
Test whether all assignments have been iterated.
void reset(void)
Reset iterator.
Definition: int.hpp:333
virtual void operator++(void)
Move to next assignment.
Definition: int.cpp:67
virtual ~Assignment(void)
Destructor.
Definition: int.hpp:54
Test * test
The test currently run.
Definition: int.hh:162
ReifyMode
Mode for reification.
Definition: int.hh:829
void post(void)
Post propagator.
Definition: int.cpp:149
Gecode::IntPropLevel ipl(void) const
Return current level.
Definition: int.hpp:324
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
Generate all assignments.
Definition: int.hh:83
Iterator for simple integer propagation levels.
Definition: int.hh:334
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:337
int * vals
The current values for the variables.
Definition: int.hh:102
bool reified
Whether the test is for a reified propagator.
Definition: int.hh:164
virtual bool solution(const Assignment &) const =0
Check for solution.
int rndvar(void)
Randomly select an unassigned variable.
Definition: int.cpp:174