Generated on for Gecode by doxygen 1.17.0
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.dev>
5 * Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
6 *
7 * Copyright:
8 * Christian Schulte, 2005
9 * Mikael Zayenz Lagerkvist, 2006
10 *
11 * This file is part of Gecode, the generic constraint
12 * development environment:
13 * http://www.gecode.dev
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining
16 * a copy of this software and associated documentation files (the
17 * "Software"), to deal in the Software without restriction, including
18 * without limitation the rights to use, copy, modify, merge, publish,
19 * distribute, sublicense, and/or sell copies of the Software, and to
20 * permit persons to whom the Software is furnished to do so, subject to
21 * the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be
24 * included in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 *
34 */
35
36#ifndef GECODE_TEST_INT_HH
37#define GECODE_TEST_INT_HH
38
39#include "test/test.hh"
40
41#include <gecode/int.hh>
42
43namespace Test {
44
46 namespace Int {
47
52
58
59 class Assignment {
60 protected:
61 int n;
63 public:
65 Assignment(int n0, const Gecode::IntSet& d0);
67 virtual bool has_more(void) const = 0;
69 virtual void next(Gecode::Support::RandomGenerator& rand) = 0;
71 virtual int operator[](int i) const = 0;
73 int size(void) const;
75 virtual ~Assignment(void);
76 };
77
79 class CpltAssignment : public Assignment {
80 protected:
82 public:
84 CpltAssignment(int n, const Gecode::IntSet& d);
86 virtual bool has_more(void) const;
90 virtual int operator[](int i) const;
92 virtual ~CpltAssignment(void);
93 };
94
97 protected:
98 int* vals;
99 int a;
102 public:
106 virtual bool has_more(void) const;
110 virtual int operator[](int i) const;
112 virtual ~RandomAssignment(void);
113 };
114
117 protected:
118 int* vals;
119 int a;
120 int _n1;
124 public:
126 RandomMixAssignment(int n0, const Gecode::IntSet& d0, int n1, const Gecode::IntSet& d1, int a0,
129 virtual bool has_more(void) const;
133 virtual int operator[](int i) const;
135 virtual ~RandomMixAssignment(void);
136 };
137
145
146 class Test;
147
149 class TestSpace : public Gecode::Space {
150 public:
161
180 virtual Gecode::Space* copy(void);
182 bool assigned(void) const;
184 void post(void);
186 bool failed(void);
190 void rndrel(const Assignment& a, int i, Gecode::IntRelType& irt, int& v, Gecode::Support::RandomGenerator& rand);
192 void rel(int i, Gecode::IntRelType irt, int n);
194 void rel(bool sol);
196 void assign(const Assignment& a, bool skip, Gecode::Support::RandomGenerator& rand);
204 void prune(int i, bool bounds_only, Gecode::Support::RandomGenerator& rand);
208 bool prune(const Assignment& a, bool testfix, Gecode::Support::RandomGenerator& rand);
210 void disable(void);
212 void enable(void);
214 bool disabled(const Assignment& a, TestSpace& c, bool testfix, Gecode::Support::RandomGenerator& rand);
216 unsigned int propagators(void);
217 };
218
223 class Test : public Base {
224 protected:
226 int arity;
232 int rms;
242
243
244 bool eqv(void) const;
246 bool imp(void) const;
248 bool pmi(void) const;
250 public:
259 Test(const std::string& p, const std::string& s,
260 int a, const Gecode::IntSet& d, bool r=false,
270 Test(const std::string& s,
271 int a, const Gecode::IntSet& d, bool r=false,
281 Test(const std::string& p, const std::string& s,
282 int a, int min, int max, bool r=false,
292 Test(const std::string& s,
293 int a, int min, int max, bool r=false,
296 virtual Assignment* assignment(void) const;
298 virtual bool solution(const Assignment&) const = 0;
300 virtual bool ignore(const Assignment&) const;
302 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) = 0;
304 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
305 Gecode::Reify r);
307 virtual bool run(void);
309
310
311 static std::string str(bool b);
313 static std::string str(int i);
315 static std::string str(const Gecode::IntArgs& i);
317 static std::string str(Gecode::IntPropLevel ipl);
319 static std::string str(Gecode::IntRelType irl);
321 static std::string str(Gecode::BoolOpType bot);
323
325
326 template<class T> static bool cmp(T x, Gecode::IntRelType r, T y);
328 };
329
330
333 private:
335 static const Gecode::IntPropLevel ipls[3];
337 int i;
338 public:
340 IntPropLevels(void);
342 bool operator()(void) const;
344 void operator++(void);
346 Gecode::IntPropLevel ipl(void) const;
347 };
348
351 private:
353 static const Gecode::IntPropLevel ipls[3];
355 int i;
356 public:
360 bool operator()(void) const;
362 void operator++(void);
364 Gecode::IntPropLevel ipl(void) const;
365 };
366
369 private:
371 static const Gecode::IntRelType irts[6];
373 int i;
374 public:
376 IntRelTypes(void);
378 void reset(void);
380 bool operator()(void) const;
382 void operator++(void);
384 Gecode::IntRelType irt(void) const;
385 };
386
389 private:
391 static const Gecode::BoolOpType bots[5];
393 int i;
394 public:
396 BoolOpTypes(void);
398 bool operator()(void) const;
400 void operator++(void);
402 Gecode::BoolOpType bot(void) const;
403 };
404
405 }
406}
407
412std::ostream& operator<<(std::ostream& os, const Test::Int::Assignment& a);
413
414#include "test/int.hpp"
415
416#endif
417
418// STATISTICS: test-int
419
Passing integer arguments.
Definition int.hh:652
Value iterator for integer sets.
Definition int.hh:351
Integer sets.
Definition int.hh:178
Integer variable array.
Definition int.hh:791
Reification specification.
Definition int.hh:910
Computation spaces.
Definition core.hpp:1775
struct Gecode::Space::@055132133326276162005044145100211202071356247106::@155123175027073262103111264343315000271204104107 c
Data available only during copying.
Base(std::string s)
Create and register test with name s.
Base class for assignments
Definition int.hh:59
Gecode::IntSet d
Domain for each variable.
Definition int.hh:62
int n
Number of variables.
Definition int.hh:61
virtual ~Assignment(void)
Destructor.
Definition int.hpp:50
Assignment(int n0, const Gecode::IntSet &d0)
Initialize assignments for n0 variables and values d0.
Definition int.hpp:43
virtual void next(Gecode::Support::RandomGenerator &rand)=0
Move to next assignment.
virtual bool has_more(void) const =0
Test whether all assignments have been iterated.
int size(void) const
Return number of variables.
Definition int.hpp:46
virtual int operator[](int i) const =0
Return value for variable i.
BoolOpTypes(void)
Initialize iterator.
Definition int.hpp:344
bool operator()(void) const
Test whether iterator is done.
Definition int.hpp:347
Gecode::BoolOpType bot(void) const
Return current operation type.
Definition int.hpp:355
void operator++(void)
Increment to next operation type.
Definition int.hpp:351
CpltAssignment(int n, const Gecode::IntSet &d)
Initialize assignments for n0 variables and values d0.
Definition int.hpp:54
virtual int operator[](int i) const
Return value for variable i.
Definition int.hpp:65
virtual ~CpltAssignment(void)
Destructor.
Definition int.hpp:70
Gecode::IntSetValues * dsv
Iterator for each variable.
Definition int.hh:81
virtual void next(Gecode::Support::RandomGenerator &rand)
Move to next assignment.
virtual bool has_more(void) const
Test whether all assignments have been iterated.
Definition int.hpp:61
Gecode::IntPropLevel ipl(void) const
Return current level.
Definition int.hpp:318
bool operator()(void) const
Test whether iterator is done.
Definition int.hpp:310
IntPropBasicAdvanced(void)
Initialize iterator.
Definition int.hpp:307
void operator++(void)
Increment to next level.
Definition int.hpp:314
IntPropLevels(void)
Initialize iterator.
Definition int.hpp:290
Gecode::IntPropLevel ipl(void) const
Return current level.
Definition int.hpp:301
bool operator()(void) const
Test whether iterator is done.
Definition int.hpp:293
void operator++(void)
Increment to next level.
Definition int.hpp:297
void operator++(void)
Increment to next relation type.
Definition int.hpp:335
bool operator()(void) const
Test whether iterator is done.
Definition int.hpp:331
void reset(void)
Reset iterator.
Definition int.hpp:327
IntRelTypes(void)
Initialize iterator.
Definition int.hpp:324
Gecode::IntRelType irt(void) const
Return current relation type.
Definition int.hpp:339
virtual int operator[](int i) const
Return value for variable i.
Definition int.hpp:99
virtual ~RandomAssignment(void)
Destructor.
Definition int.hpp:104
int a
How many assignments still to be generated Generate new value according to domain.
Definition int.hh:99
virtual void next(Gecode::Support::RandomGenerator &rand)
Move to next assignment.
int * vals
The current values for the variables.
Definition int.hh:98
RandomAssignment(int n, const Gecode::IntSet &d, int a0, Gecode::Support::RandomGenerator &rand)
Initialize for a assignments for n0 variables and values d0.
Definition int.hpp:88
int randval(Gecode::Support::RandomGenerator &rand)
Definition int.hpp:76
virtual bool has_more(void) const
Test whether all assignments have been iterated.
Definition int.hpp:95
int _n1
How many variables in the second set.
Definition int.hh:120
int randval(const Gecode::IntSet &d, Gecode::Support::RandomGenerator &rand)
Definition int.hpp:109
Gecode::IntSet _d1
Domain for second set of variables Generate new value according to domain d.
Definition int.hh:121
virtual int operator[](int i) const
Return value for variable i.
Definition int.hpp:137
virtual bool has_more(void) const
Test whether all assignments have been iterated.
Definition int.hpp:132
virtual void next(Gecode::Support::RandomGenerator &rand)
Move to next assignment.
RandomMixAssignment(int n0, const Gecode::IntSet &d0, int n1, const Gecode::IntSet &d1, int a0, Gecode::Support::RandomGenerator &rand)
Initialize for a assignments for n0 variables and values d0.
Definition int.hpp:121
virtual ~RandomMixAssignment(void)
Destructor.
Definition int.hpp:143
int a
How many assignments still to be generated.
Definition int.hh:119
int * vals
The current values for the variables.
Definition int.hh:118
int rndvar(Gecode::Support::RandomGenerator &rand)
Randomly select an unassigned variable.
Gecode::Reify r
Reification information.
Definition int.hh:156
void assign(const Assignment &a, bool skip, Gecode::Support::RandomGenerator &rand)
Assign all (or all but one, if skip is true) variables to values in a.
bool prune(const Assignment &a, bool testfix, Gecode::Support::RandomGenerator &rand)
Prune values but not those in assignment a.
TestSpace(int n, Gecode::IntSet &d, Test *t)
Create test space without reification.
Gecode::IntSet d
Initial domain.
Definition int.hh:152
void rndrel(const Assignment &a, int i, Gecode::IntRelType &irt, int &v, Gecode::Support::RandomGenerator &rand)
Randomly select a pruning rel for variable i.
Test * test
The test currently run.
Definition int.hh:158
bool disabled(const Assignment &a, TestSpace &c, bool testfix, Gecode::Support::RandomGenerator &rand)
Prune values also in a space c with disabled propagators, but not those in assignment a.
void post(void)
Post propagator.
void prune(Gecode::Support::RandomGenerator &rand)
Prune some random values for some random variable.
bool assigned(void) const
Test whether all variables are assigned.
void prune(int i, bool bounds_only, Gecode::Support::RandomGenerator &rand)
Prune some random values from variable i.
bool failed(void)
Compute a fixpoint and check for failure.
bool reified
Whether the test is for a reified propagator.
Definition int.hh:160
void disable(void)
Disable propagators in space and compute fixpoint (make all idle).
void rel(bool sol)
Perform Boolean tell on b.
virtual Gecode::Space * copy(void)
Copy space during cloning.
TestSpace(int n, Gecode::IntSet &d, Test *t, Gecode::ReifyMode rm)
Create test space with reification.
Gecode::IntVarArray x
Variables to be tested.
Definition int.hh:154
void bound(Gecode::Support::RandomGenerator &rand)
Assign a random variable to a random bound.
TestSpace(TestSpace &s)
Constructor for cloning s.
void enable(void)
Enable propagators in space.
void rel(int i, Gecode::IntRelType irt, int n)
Perform integer tell operation on x[i].
unsigned int propagators(void)
Return the number of propagators.
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
Definition int.hpp:160
bool reified
Does the constraint also exist as reified constraint.
Definition int.hh:230
virtual bool run(void)
Perform test.
bool testsearch
Whether to perform search test.
Definition int.hh:238
static std::string str(bool b)
Map bool to string.
Definition int.hpp:255
bool testfix
Whether to perform fixpoint test.
Definition int.hh:240
int rms
Which reification modes are supported.
Definition int.hh:232
virtual Assignment * assignment(void) const
Create assignment.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)=0
Post constraint.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint.
Gecode::IntPropLevel ipl
Propagation level.
Definition int.hh:234
bool eqv(void) const
Test whether equivalence as reification mode is supported.
Definition int.hpp:152
virtual bool ignore(const Assignment &) const
Whether to ignore assignment for reification.
int arity
Number of variables.
Definition int.hh:226
static bool cmp(T x, Gecode::IntRelType r, T y)
Compare x and y with respect to r.
Definition int.hpp:273
virtual bool solution(const Assignment &) const =0
Check for solution.
Gecode::IntSet dom
Domain of variables.
Definition int.hh:228
bool imp(void) const
Test whether implication as reification mode is supported.
Definition int.hpp:156
ConTestLevel contest
Whether to test for certain consistency.
Definition int.hh:236
LinearCongruentialGenerator< 2147483647, 48271, 44488, 3399 > RandomGenerator
Default values for linear congruential generator.
Definition random.hpp:183
IntRelType
Relation types for integers.
Definition int.hh:959
ReifyMode
Mode for reification.
Definition int.hh:882
BoolOpType
Operation types for Booleans.
Definition int.hh:984
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:1008
@ IPL_DEF
Simple propagation levels.
Definition int.hh:1010
Testing finite domain integers.
Definition int.hh:46
ConTestLevel
Level of consistency to test for.
Definition int.hh:139
@ CTL_BOUNDS_Z
Test for bounds(z)-consistency.
Definition int.hh:143
@ CTL_BOUNDS_D
Test for bounds(d)-consistency.
Definition int.hh:142
@ CTL_NONE
No consistency-test.
Definition int.hh:140
@ CTL_DOMAIN
Test for domain-consistency.
Definition int.hh:141
General test support.
Definition assign.hh:52
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const Dictionary &d)
Print statistics summary.
Definition scowl.hpp:13625