Generated on Sat Feb 7 2015 02:01:19 for Gecode by doxygen 1.8.9.1
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: 2013-02-06 15:10:02 +0100 (Wed, 06 Feb 2013) $ by $Author: schulte $
13  * $Revision: 13270 $
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  void rel(int i, Gecode::IntRelType irt, int n);
194  void rel(bool sol);
196  void assign(const Assignment& a, bool skip=false);
198  void bound(void);
204  void prune(int i, bool bounds_only);
206  void prune(void);
208  bool prune(const Assignment& a, bool testfix);
209  };
210 
215  class Test : public Base {
216  protected:
218  int arity;
222  bool reified;
224  int rms;
232  bool testfix;
234 
235  bool eqv(void) const;
238  bool imp(void) const;
240  bool pmi(void) const;
242  public:
251  Test(const std::string& p, const std::string& s,
252  int a, const Gecode::IntSet& d, bool r=false,
262  Test(const std::string& s,
263  int a, const Gecode::IntSet& d, bool r=false,
273  Test(const std::string& p, const std::string& s,
274  int a, int min, int max, bool r=false,
284  Test(const std::string& s,
285  int a, int min, int max, bool r=false,
288  virtual Assignment* assignment(void) const;
290  virtual bool solution(const Assignment&) const = 0;
292  virtual bool ignore(const Assignment&) const;
294  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) = 0;
296  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
297  Gecode::Reify r);
299  virtual bool run(void);
301 
302  static std::string str(Gecode::ExtensionalPropKind epk);
305  static std::string str(Gecode::IntConLevel icl);
307  static std::string str(Gecode::IntRelType irl);
309  static std::string str(Gecode::BoolOpType bot);
311  static std::string str(int i);
313  static std::string str(const Gecode::IntArgs& i);
315 
317  template<class T> static bool cmp(T x, Gecode::IntRelType r, T y);
320  };
322 
324  class IntConLevels {
325  private:
327  static const Gecode::IntConLevel icls[3];
329  int i;
330  public:
332  IntConLevels(void);
334  bool operator()(void) const;
336  void operator++(void);
338  Gecode::IntConLevel icl(void) const;
339  };
340 
342  class IntRelTypes {
343  private:
345  static const Gecode::IntRelType irts[6];
347  int i;
348  public:
350  IntRelTypes(void);
352  void reset(void);
354  bool operator()(void) const;
356  void operator++(void);
358  Gecode::IntRelType irt(void) const;
359  };
360 
362  class BoolOpTypes {
363  private:
365  static const Gecode::BoolOpType bots[5];
367  int i;
368  public:
370  BoolOpTypes(void);
372  bool operator()(void) const;
374  void operator++(void);
376  Gecode::BoolOpType bot(void) const;
377  };
378 
379  }
380 }
381 
386 std::ostream& operator<<(std::ostream& os, const Test::Int::Assignment& a);
387 
388 #include "test/int.hpp"
389 
390 #endif
391 
392 // STATISTICS: test-int
393 
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
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
Gecode::IntSet d
Initial domain.
Definition: int.hh:156
IntConLevel
Consistency levels for integer propagators.
Definition: int.hh:937
Gecode::IntVarArray x
Variables to be tested.
Definition: int.hh:158
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)=0
Post constraint.
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
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:916
static bool cmp(T x, Gecode::IntRelType r, T y)
Compare x and y with respect to r.
Definition: int.hpp:284
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: int.hpp:99
Gecode::Reify r
Reification information.
Definition: int.hh:160
virtual ~RandomAssignment(void)
Destructor.
Definition: int.hpp:108
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: int.hpp:65
Gecode::IntSet dom
Domain of variables.
Definition: int.hh:220
Iterator for integer consistency levels.
Definition: int.hh:324
Integer variable array.
Definition: int.hh:741
bool failed(void)
Compute a fixpoint and check for failure.
Definition: int.cpp:162
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
Space for executing tests.
Definition: int.hh:153
ConTestLevel contest
Whether to test for certain consistency.
Definition: int.hh:228
const int max
Largest allowed integer value.
Definition: int.hh:113
int rms
Which reification modes are supported.
Definition: int.hh:224
Computation spaces.
Definition: core.hpp:1362
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:115
int n
Number of variables.
Definition: int.hh:65
bool assigned(void) const
Test whether all variables are assigned.
Definition: int.cpp:141
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
virtual Assignment * assignment(void) const
Create assignment.
Definition: int.cpp:359
static std::string str(Gecode::ExtensionalPropKind epk)
Map extensional propagation kind to string.
Definition: int.hpp:212
void prune(void)
Prune some random values for some random variable.
Definition: int.cpp:257
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
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:304
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:390
Gecode::IntConLevel icl
Consistency level.
Definition: int.hh:226
IntRelType
Relation types for integers.
Definition: int.hh:903
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:174
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
void bound(void)
Assing a random variable to a random bound.
Definition: int.cpp:212
int * vals
The current values for the variables.
Definition: int.hh:122
IntRelTypes(void)
Initialize iterator.
Definition: int.hpp:318
Iterator for integer relation types.
Definition: int.hh:342
virtual void operator++(void)=0
Move to next assignment.
virtual int operator[](int i) const
Return value for variable i.
Definition: int.hpp:103
Reification specification.
Definition: int.hh:854
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
bool imp(void) const
Test whether implication as reification mode is supported.
Definition: int.hpp:160
Test for bounds(z)-consistency.
Definition: int.hh:147
Test for bounds(d)-consistency.
Definition: int.hh:146
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
Definition: int.hpp:164
Integer sets.
Definition: int.hh:171
Test for domain-consistency.
Definition: int.hh:145
virtual bool ignore(const Assignment &) const
Whether to ignore assignment for reification.
Definition: int.cpp:381
int randval(const Gecode::IntSet &d)
Definition: int.hpp:113
ExtensionalPropKind
Extensional propagation kind.
Definition: int.hh:1982
Gecode::IntRelType irt(void) const
Return current relation type.
Definition: int.hpp:333
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
bool testfix
Whether to perform fixpoint test.
Definition: int.hh:232
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
bool testsearch
Whether to perform search test.
Definition: int.hh:230
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:200
Base class for assignments
Definition: int.hh:63
IntConLevels(void)
Initialize iterator.
Definition: int.hpp:301
The default consistency for a constraint.
Definition: int.hh:941
Value iterator for integer sets.
Definition: int.hh:312
bool operator()(void) const
Test whether iterator is done.
Definition: int.hpp:325
void operator++(void)
Increment to next relation type.
Definition: int.hpp:329
virtual int operator[](int i) const
Return value for variable i.
Definition: int.hpp:69
BoolOpTypes(void)
Initialize iterator.
Definition: int.hpp:338
Iterator for Boolean operation types.
Definition: int.hh:362
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const FloatView &x)
Print float variable view.
Definition: print.hpp:62
virtual int operator[](int i) const
Return value for variable i.
Definition: int.hpp:141
int arity
Number of variables.
Definition: int.hh:218
virtual bool operator()(void) const =0
Test whether all assignments have been iterated.
void reset(void)
Reset iterator.
Definition: int.hpp:321
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:826
void post(void)
Post propagator.
Definition: int.cpp:149
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
int size(void) const
Return number of variables.
Definition: int.hpp:50
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
Generate all assignments.
Definition: int.hh:83
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.