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
43/* Configure linking, as for the Gecode variable libraries. */
44#if !defined(GECODE_STATIC_LIBS) && \
45 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
46#ifdef GECODE_BUILD_TESTINT
47#define GECODE_TESTINT_EXPORT __declspec( dllexport )
48#else
49#define GECODE_TESTINT_EXPORT __declspec( dllimport )
50#endif
51#elif defined(GECODE_GCC_HAS_CLASS_VISIBILITY)
52#define GECODE_TESTINT_EXPORT __attribute__ ((visibility("default")))
53#else
54#define GECODE_TESTINT_EXPORT
55#endif
56
57namespace Test {
58
60 namespace Int {
61
66
72
74 protected:
75 int n;
77 public:
79 Assignment(int n0, const Gecode::IntSet& d0);
81 virtual bool has_more(void) const = 0;
83 virtual void next(Gecode::Support::RandomGenerator& rand) = 0;
85 virtual int operator[](int i) const = 0;
87 int size(void) const;
89 virtual ~Assignment(void);
90 };
91
94 protected:
96 public:
98 CpltAssignment(int n, const Gecode::IntSet& d);
100 virtual bool has_more(void) const;
102 virtual void next(Gecode::Support::RandomGenerator& rand);
104 virtual int operator[](int i) const;
106 virtual ~CpltAssignment(void);
107 };
108
111 protected:
112 int* vals;
113 int a;
116 public:
120 virtual bool has_more(void) const;
122 virtual void next(Gecode::Support::RandomGenerator& rand);
124 virtual int operator[](int i) const;
126 virtual ~RandomAssignment(void);
127 };
128
131 protected:
132 int* vals;
133 int a;
134 int _n1;
138 public:
140 RandomMixAssignment(int n0, const Gecode::IntSet& d0, int n1, const Gecode::IntSet& d1, int a0,
143 virtual bool has_more(void) const;
145 virtual void next(Gecode::Support::RandomGenerator& rand);
147 virtual int operator[](int i) const;
149 virtual ~RandomMixAssignment(void);
150 };
151
159
161
164 public:
175
182 TestSpace(int n, Gecode::IntSet& d, Test* t);
194 virtual Gecode::Space* copy(void);
196 bool assigned(void) const;
198 void post(void);
200 bool failed(void);
204 void rndrel(const Assignment& a, int i, Gecode::IntRelType& irt, int& v, Gecode::Support::RandomGenerator& rand);
206 void rel(int i, Gecode::IntRelType irt, int n);
208 void rel(bool sol);
210 void assign(const Assignment& a, bool skip, Gecode::Support::RandomGenerator& rand);
218 void prune(int i, bool bounds_only, Gecode::Support::RandomGenerator& rand);
222 bool prune(const Assignment& a, bool testfix, Gecode::Support::RandomGenerator& rand);
224 void disable(void);
226 void enable(void);
228 bool disabled(const Assignment& a, TestSpace& c, bool testfix, Gecode::Support::RandomGenerator& rand);
230 unsigned int propagators(void);
231 };
232
271 protected:
273 int arity;
279 int rms;
289
290
291 bool eqv(void) const;
293 bool imp(void) const;
295 bool pmi(void) const;
297 public:
306 Test(const std::string& p, const std::string& s,
307 int a, const Gecode::IntSet& d, bool r=false,
310 Test(TestTags tags, const std::string& p, const std::string& s,
311 int a, const Gecode::IntSet& d, bool r=false,
321 Test(const std::string& s,
322 int a, const Gecode::IntSet& d, bool r=false,
325 Test(TestTags tags, const std::string& s,
326 int a, const Gecode::IntSet& d, bool r=false,
336 Test(const std::string& p, const std::string& s,
337 int a, int min, int max, bool r=false,
340 Test(TestTags tags, const std::string& p, const std::string& s,
341 int a, int min, int max, bool r=false,
351 Test(const std::string& s,
352 int a, int min, int max, bool r=false,
355 Test(TestTags tags, const std::string& s,
356 int a, int min, int max, bool r=false,
363 virtual Assignment* assignment(void) const;
365 virtual bool solution(const Assignment&) const = 0;
367 virtual bool ignore(const Assignment&) const;
369 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) = 0;
371 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
374 virtual bool run(void);
376
377
378 static std::string str(bool b);
380 static std::string str(int i);
382 static std::string str(const Gecode::IntArgs& i);
384 static std::string str(Gecode::IntPropLevel ipl);
386 static std::string str(Gecode::IntRelType irl);
388 static std::string str(Gecode::BoolOpType bot);
390
392
393 template<class T> static bool cmp(T x, Gecode::IntRelType r, T y);
395 };
396
411 protected:
413 int items;
414 public:
416 OpenTest(const std::string& name, int items, int extra,
417 const Gecode::IntSet& domain,
420 virtual void post(Gecode::Space& home, Gecode::OpenIntVarList list,
421 Gecode::IntVarArray& x) = 0;
423 void post(Gecode::Space& home, Gecode::IntVarArray& x) override;
425 bool run(void) override;
426 };
427
428
431 private:
433 static const Gecode::IntPropLevel ipls[3];
435 int i;
436 public:
438 IntPropLevels(void);
440 bool operator()(void) const;
442 void operator++(void);
444 Gecode::IntPropLevel ipl(void) const;
445 };
446
449 private:
451 static const Gecode::IntPropLevel ipls[3];
453 int i;
454 public:
458 bool operator()(void) const;
460 void operator++(void);
462 Gecode::IntPropLevel ipl(void) const;
463 };
464
467 private:
469 static const Gecode::IntRelType irts[6];
471 int i;
472 public:
474 IntRelTypes(void);
476 void reset(void);
478 bool operator()(void) const;
480 void operator++(void);
482 Gecode::IntRelType irt(void) const;
483 };
484
487 private:
489 static const Gecode::BoolOpType bots[5];
491 int i;
492 public:
494 BoolOpTypes(void);
496 bool operator()(void) const;
498 void operator++(void);
500 Gecode::BoolOpType bot(void) const;
501 };
502
503 }
504}
505
510GECODE_TESTINT_EXPORT std::ostream& operator<<(std::ostream& os, const ::Test::Int::Assignment& a);
511
512#include "test/int.hpp"
513
514#endif
515
516// STATISTICS: test-int
Passing integer arguments.
Definition int.hh:653
Value iterator for integer sets.
Definition int.hh:352
Integer sets.
Definition int.hh:179
Integer variable array.
Definition int.hh:792
Open list of integer variables.
Definition int.hh:1076
Reification specification.
Definition int.hh:1176
Computation spaces.
Definition core.hpp:1787
struct Gecode::Space::@055132133326276162005044145100211202071356247106::@155123175027073262103111264343315000271204104107 c
Data available only during copying.
Base(std::string s)
Create and register a standard test with name s.
Definition test.cpp:125
const std::string & name(void) const
Return name of test.
Definition test.hpp:91
TestTags tags(void) const
Return tags for test.
Definition test.hpp:95
Base class for assignments
Definition int.hh:73
Gecode::IntSet d
Domain for each variable.
Definition int.hh:76
int n
Number of variables.
Definition int.hh:75
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:367
bool operator()(void) const
Test whether iterator is done.
Definition int.hpp:370
Gecode::BoolOpType bot(void) const
Return current operation type.
Definition int.hpp:378
void operator++(void)
Increment to next operation type.
Definition int.hpp:374
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 void next(Gecode::Support::RandomGenerator &rand)
Move to next assignment.
Definition int.cpp:49
Gecode::IntSetValues * dsv
Iterator for each variable.
Definition int.hh:95
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:341
bool operator()(void) const
Test whether iterator is done.
Definition int.hpp:333
IntPropBasicAdvanced(void)
Initialize iterator.
Definition int.hpp:330
void operator++(void)
Increment to next level.
Definition int.hpp:337
IntPropLevels(void)
Initialize iterator.
Definition int.hpp:313
Gecode::IntPropLevel ipl(void) const
Return current level.
Definition int.hpp:324
bool operator()(void) const
Test whether iterator is done.
Definition int.hpp:316
void operator++(void)
Increment to next level.
Definition int.hpp:320
void operator++(void)
Increment to next relation type.
Definition int.hpp:358
bool operator()(void) const
Test whether iterator is done.
Definition int.hpp:354
void reset(void)
Reset iterator.
Definition int.hpp:350
IntRelTypes(void)
Initialize iterator.
Definition int.hpp:347
Gecode::IntRelType irt(void) const
Return current relation type.
Definition int.hpp:362
OpenTest(const std::string &name, int items, int extra, const Gecode::IntSet &domain, Gecode::IntPropLevel ipl=Gecode::IPL_DEF)
Initialize item and auxiliary variables with the common domain.
Definition int.cpp:1159
int items
Number of items in the completed list.
Definition int.hh:413
virtual void post(Gecode::Space &home, Gecode::OpenIntVarList list, Gecode::IntVarArray &x)=0
Post the tested relation on an open list and its variable array.
bool run(void) override
Run closed-list tests and incremental histories.
Definition int.cpp:1214
virtual int operator[](int i) const
Return value for variable i.
Definition int.hpp:99
int a
How many assignments still to be generated Generate new value according to domain.
Definition int.hh:113
int * vals
The current values for the variables.
Definition int.hh:112
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 void next(Gecode::Support::RandomGenerator &rand)
Move to next assignment.
Definition int.cpp:63
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:134
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:135
virtual int operator[](int i) const
Return value for variable i.
Definition int.hpp:137
virtual void next(Gecode::Support::RandomGenerator &rand)
Move to next assignment.
Definition int.cpp:70
virtual bool has_more(void) const
Test whether all assignments have been iterated.
Definition int.hpp:132
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
int a
How many assignments still to be generated.
Definition int.hh:133
int * vals
The current values for the variables.
Definition int.hh:132
int rndvar(Gecode::Support::RandomGenerator &rand)
Randomly select an unassigned variable.
Definition int.cpp:170
Gecode::Reify r
Reification information.
Definition int.hh:170
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.
Definition int.cpp:260
TestSpace(int n, Gecode::IntSet &d, Test *t)
Create test space without reification.
Definition int.cpp:91
Gecode::IntSet d
Initial domain.
Definition int.hh:166
void rndrel(const Assignment &a, int i, Gecode::IntRelType &irt, int &v, Gecode::Support::RandomGenerator &rand)
Randomly select a pruning rel for variable i.
Definition int.cpp:181
Test * test
The test currently run.
Definition int.hh:172
virtual Gecode::Space * copy(void)
Copy space during cloning.
Definition int.cpp:132
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.
Definition int.cpp:380
void post(void)
Post propagator.
Definition int.cpp:145
bool assigned(void) const
Test whether all variables are assigned.
Definition int.cpp:137
void prune(int i, bool bounds_only, Gecode::Support::RandomGenerator &rand)
Prune some random values from variable i.
Definition int.cpp:281
bool failed(void)
Compute a fixpoint and check for failure.
Definition int.cpp:158
bool reified
Whether the test is for a reified propagator.
Definition int.hh:174
void disable(void)
Disable propagators in space and compute fixpoint (make all idle).
Definition int.cpp:374
Gecode::IntVarArray x
Variables to be tested.
Definition int.hh:168
void bound(Gecode::Support::RandomGenerator &rand)
Assign a random variable to a random bound.
Definition int.cpp:273
void enable(void)
Enable propagators in space.
Definition int.cpp:369
void rel(int i, Gecode::IntRelType irt, int n)
Perform integer tell operation on x[i].
Definition int.cpp:234
unsigned int propagators(void)
Return the number of propagators.
Definition int.cpp:427
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
Definition int.hpp:160
virtual bool run(void)
Perform test.
Definition int.cpp:481
bool reified
Does the constraint also exist as reified constraint.
Definition int.hh:277
virtual bool ignore(const Assignment &) const
Whether to ignore assignment for reification.
Definition int.cpp:472
bool testsearch
Whether to perform search test.
Definition int.hh:285
static std::string str(bool b)
Map bool to string.
Definition int.hpp:278
bool testfix
Whether to perform fixpoint test.
Definition int.hh:287
int rms
Supported reification modes, encoded as a bit mask of 1 << Gecode::RM_*.
Definition int.hh:279
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)=0
Post constraint.
Gecode::IntPropLevel ipl
Propagation level.
Definition int.hh:281
bool eqv(void) const
Test whether equivalence as reification mode is supported.
Definition int.hpp:152
int arity
Number of variables.
Definition int.hh:273
static bool cmp(T x, Gecode::IntRelType r, T y)
Compare x and y with respect to r.
Definition int.hpp:296
virtual bool solution(const Assignment &) const =0
Check for solution.
virtual Assignment * assignment(void) const
Create the assignment generator (complete by default).
Definition int.cpp:446
Gecode::IntSet dom
Domain of variables.
Definition int.hh:275
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:283
Set of test tags.
Definition test.hh:105
LinearCongruentialGenerator< 2147483647, 48271, 44488, 3399 > RandomGenerator
Default values for linear congruential generator.
Definition random.hpp:183
IntRelType
Relation types for integers.
Definition int.hh:1225
ReifyMode
Mode for reification.
Definition int.hh:1148
BoolOpType
Operation types for Booleans.
Definition int.hh:1250
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:1274
@ IPL_DEF
Simple propagation levels.
Definition int.hh:1276
ConTestLevel
Level of consistency to test for.
Definition int.hh:153
@ CTL_BOUNDS_Z
Test for bounds(z)-consistency.
Definition int.hh:157
@ CTL_BOUNDS_D
Test for bounds(d)-consistency.
Definition int.hh:156
@ CTL_NONE
No consistency-test.
Definition int.hh:154
@ CTL_DOMAIN
Test for domain-consistency.
Definition int.hh:155
General test support.
Definition afc.cpp:41
Region r
Definition region.cpp:65
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const Dictionary &d)
Print statistics summary.
Definition scowl.hpp:13625
#define GECODE_TESTINT_EXPORT
Definition int.hh:54