Generated on Thu Mar 16 2017 03:24:23 for Gecode by doxygen 1.8.13
set.hh
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Guido Tack <tack@gecode.org>
5  * Christian Schulte <schulte@gecode.org>
6  *
7  * Copyright:
8  * Guido Tack, 2005
9  * Christian Schulte, 2005
10  *
11  * Last modified:
12  * $Date: 2016-10-18 17:27:37 +0200 (Tue, 18 Oct 2016) $ by $Author: schulte $
13  * $Revision: 15216 $
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_SET_HH__
41 #define __GECODE_TEST_SET_HH__
42 
43 #include <gecode/set.hh>
44 #include "test/test.hh"
45 #include "test/int.hh"
46 
47 namespace Test {
48 
50  namespace Set {
51 
57  class FakeSpace : public Gecode::Space {
59  public:
61  FakeSpace(void) {}
63  virtual Gecode::Space* copy(bool share) {
64  (void) share;
65  return NULL;
66  }
67  };
68 
74 
77  private:
79  int cur;
80  int i;
81  public:
85  CountableSetValues(const Gecode::IntSet& d0, int cur0)
86  : dv(d0), cur(cur0), i(1) {
87  if (! (i & cur))
88  operator++();
89  }
91  void init(const Gecode::IntSet& d0, int cur0) {
92  dv = d0;
93  cur = cur0;
94  i = 1;
95  if (! (i & cur))
96  operator++();
97  }
99  bool operator()(void) const {
100  return i<=cur;
101  }
103  void operator++(void) {
104  do {
105  ++dv;
106  i = i<<1;
107  } while (! (i & cur) && i<cur);
108  }
110  int val(void) const { return dv.val(); }
111  };
112 
115  : public Gecode::Iter::Values::ToRanges<CountableSetValues> {
116  private:
119  public:
123  CountableSetRanges(const Gecode::IntSet& d, int cur) : v(d, cur) {
125  }
127  void init(const Gecode::IntSet& d, int cur) {
128  v.init(d, cur);
130  }
131  };
132 
134  class CountableSet {
135  private:
139  unsigned int cur;
141  unsigned int lubmax;
142  public:
144  CountableSet(const Gecode::IntSet& s);
146  CountableSet(void) {}
148  void init(const Gecode::IntSet& s);
150  bool operator()(void) const { return cur<lubmax; }
152  void operator++(void);
154  int val(void) const;
155  };
156 
159  private:
161  int n;
163  CountableSet* dsv;
167  bool done;
168  public:
172  int withInt;
174  SetAssignment(int n, const Gecode::IntSet& d, int i = 0);
176  bool operator()(void) const { return !done; }
178  void operator++(void);
180  int operator[](int i) const {
181  assert((i>=0) && (i<n));
182  return dsv[i].val();
183  }
185  int intval(void) const { return ir[0]; }
187  const Test::Int::Assignment& ints(void) const { return ir; }
189  int size(void) const { return n; }
191  ~SetAssignment(void) { delete [] dsv; }
192  };
193 
194 
195  class SetTest;
196 
198  class SetTestSpace : public Gecode::Space {
199  public:
207  int withInt;
211  bool reified;
214 
224  SetTestSpace(int n, Gecode::IntSet& d0, int i, SetTest* t,
225  bool log=true);
235  SetTestSpace(int n, Gecode::IntSet& d0, int i, SetTest* t,
236  Gecode::ReifyMode rm, bool log=true);
238  SetTestSpace(bool share, SetTestSpace& s);
240  virtual Gecode::Space* copy(bool share);
242  void post(void);
244  bool failed(void);
246  void rel(int i, Gecode::SetRelType srt, const Gecode::IntSet& is);
248  void cardinality(int i, int cmin, int cmax);
250  void rel(int i, Gecode::IntRelType irt, int n);
252  void rel(bool sol);
254  void assign(const SetAssignment& a);
256  bool assigned(void) const;
258  void removeFromLub(int v, int i, const SetAssignment& a);
260  void removeFromLub(int v, int i, const SetAssignment& a,
261  SetTestSpace& c);
263  void addToGlb(int v, int i, const SetAssignment& a);
265  void addToGlb(int v, int i, const SetAssignment& a,
266  SetTestSpace& c);
268  bool fixprob(void);
270  bool prune(const SetAssignment& a);
272  unsigned int propagators(void);
274  void disable(void);
276  void enable(void);
278  bool disabled(const SetAssignment& a, SetTestSpace& c);
280  bool same(SetTestSpace& c);
281  };
282 
287  class SetTest : public Base {
288  private:
290  int arity;
292  Gecode::IntSet lub;
294  bool reified;
296  int withInt;
297 
299  void removeFromLub(int v, Gecode::SetVar& x, int i,
300  const Gecode::IntSet& a);
302  void addToGlb(int v, Gecode::SetVar& x, int i, const Gecode::IntSet& a);
304  SetAssignment* make_assignment(void);
305  protected:
307  bool disabled;
308  public:
316  SetTest(const std::string& s,
317  int a, const Gecode::IntSet& d, bool r=false, int w=0)
318  : Base("Set::"+s), arity(a), lub(d), reified(r), withInt(w),
319  disabled(true) {}
321  virtual bool solution(const SetAssignment&) const = 0;
323  virtual void post(Gecode::Space& home, Gecode::SetVarArray& x,
324  Gecode::IntVarArray& y) = 0;
329  virtual bool run(void);
330 
332 
333  static std::string str(Gecode::SetRelType srt);
336  static std::string str(Gecode::SetOpType srt);
338  static std::string str(int i);
340  static std::string str(const Gecode::IntArgs& i);
342  };
344 
346  class SetRelTypes {
347  private:
349  static const Gecode::SetRelType srts[6];
351  int i;
352  public:
354  SetRelTypes(void);
356  bool operator()(void) const;
358  void operator++(void);
360  Gecode::SetRelType srt(void) const;
361  };
362 
364  class SetOpTypes {
365  private:
367  static const Gecode::SetOpType sots[4];
369  int i;
370  public:
372  SetOpTypes(void);
374  bool operator()(void) const;
376  void operator++(void);
378  Gecode::SetOpType sot(void) const;
379  };
380 
381 }}
382 
387 std::ostream&
388 operator<<(std::ostream&, const Test::Set::SetAssignment& a);
389 
390 #include "test/set.hpp"
391 
392 #endif
393 
394 // STATISTICS: test-set
virtual void post(Gecode::Space &, Gecode::SetVarArray &, Gecode::IntVarArray &, Gecode::Reify)
Post reified propagator.
Definition: set.hh:326
Iterator for Boolean operation types.
Definition: set.hh:364
NodeType t
Type of node.
Definition: bool-expr.cpp:234
bool disabled
Whether to perform full tests for disabled propagators.
Definition: set.hh:307
CountableSetRanges(const Gecode::IntSet &d, int cur)
Initialize with set d0 and bit-pattern cur0.
Definition: set.hh:123
SetRelType
Common relation types for sets.
Definition: set.hh:643
Iterator for set relation types.
Definition: set.hh:346
void operator++(void)
Move to next value.
Definition: set.hh:103
Gecode::Reify r
Reification information.
Definition: set.hh:209
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:228
void log(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition: arithmetic.cpp:151
Gecode::SetVarArray x
Set variables to be tested.
Definition: set.hh:203
CountableSet(void)
Default constructor.
Definition: set.hh:146
int val(void) const
Return current subset.
Definition: set.cpp:68
Integer variable array.
Definition: int.hh:742
bool operator()(void) const
Test if finished.
Definition: set.hh:99
SetOpType
Common operations for sets.
Definition: set.hh:660
CountableSetRanges(void)
Default constructor.
Definition: set.hh:121
Computation spaces.
Definition: core.hpp:1672
ExecStatus prune(Space &home, ViewArray< VX > &x, ConstIntView)
Definition: rel.hpp:257
SetTest(const std::string &s, int a, const Gecode::IntSet &d, bool r=false, int w=0)
Constructor.
Definition: set.hh:316
int val(void) const
Return current value.
void init(const Gecode::IntSet &d, int cur)
Initialize with set d0 and bit-pattern cur0.
Definition: set.hh:127
Gecode::IntSet d(v, 7)
bool reified
Whether the test is for a reified propagator.
Definition: set.hh:211
struct Gecode::@554::NNF::@60::@62 a
For atomic nodes.
Gecode::IntArgs i(4, 1, 2, 3, 4)
void assign(Home home, const FloatVarArgs &x, FloatAssign fa, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with value selection vals.
Definition: branch.cpp:113
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
IntRelType
Relation types for integers.
Definition: int.hh:904
void init(I &i)
Initialize with value iterator i.
bool failed(void) const
Check whether space is failed.
Definition: core.hpp:3963
Range iterator from value iterator.
Reification specification.
Definition: int.hh:855
Base class for all tests to be run
Definition: test.hh:107
Gecode::IntSet lub
The common superset for all domains.
Definition: set.hh:170
Integer sets.
Definition: int.hh:172
const Test::Int::Assignment & ints(void) const
Return assignment for integer variables.
Definition: set.hh:187
CountableSetValues(void)
Default constructor.
Definition: set.hh:83
Value iterator producing subsets of an IntSet.
Definition: set.hh:76
Passing integer arguments.
Definition: int.hh:608
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const Dictionary &d)
Print statistics summary.
Definition: scowl.hpp:13621
virtual Gecode::Space * copy(bool share)
Faked copy function.
Definition: set.hh:63
Gecode::IntSet d
Initial domain.
Definition: set.hh:201
LinIntExpr cardinality(const SetExpr &e)
Cardinality of set expression.
Definition: set-expr.cpp:818
const int v[7]
Definition: distinct.cpp:263
General test support.
Definition: afc.cpp:43
int val(void) const
Return current value.
Definition: set.hh:110
int withInt
How many integer variables to iterate.
Definition: set.hh:172
FakeSpace(void)
Faked constructor.
Definition: set.hh:61
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Set variables
Definition: set.hh:129
Home operator()(Propagator &p)
Return a home for this space with the information that p is being rewritten.
Definition: core.hpp:3316
struct Gecode::Space::@55::@57 c
Data available only during copying.
Base class for tests with set constraints
Definition: set.hh:287
Generate all set assignments.
Definition: set.hh:158
Region r
Definition: region.cpp:82
Base class for assignments
Definition: int.hh:63
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:47
bool same(const Item &i, const Item &j)
Whether two items are the same.
Definition: propagate.hpp:76
Gecode::IntVarArray y
Int variables to be tested.
Definition: set.hh:205
~SetAssignment(void)
Destructor.
Definition: set.hh:191
Value iterator for integer sets.
Definition: int.hh:313
Range iterator producing subsets of an IntSet.
Definition: set.hh:114
int withInt
How many integer variables are used by the test.
Definition: set.hh:207
CountableSetValues(const Gecode::IntSet &d0, int cur0)
Initialize with set d0 and bit-pattern cur0.
Definition: set.hh:85
Set variable array
Definition: set.hh:570
void init(const Gecode::IntSet &d0, int cur0)
Initialize with set d0 and bit-pattern cur0.
Definition: set.hh:91
bool operator()(void) const
Test whether all assignments have been iterated.
Definition: set.hh:176
int size(void) const
Return arity.
Definition: set.hh:189
SetTest * test
The test currently run.
Definition: set.hh:213
Space for executing set tests.
Definition: set.hh:198
Iterate all subsets of a given set.
Definition: set.hh:134
ReifyMode
Mode for reification.
Definition: int.hh:827
int intval(void) const
Return value for first integer variable.
Definition: set.hh:185
int operator[](int i) const
Return value for variable i.
Definition: set.hh:180
bool operator()(void) const
Check if still subsets left.
Definition: set.hh:150
Generate all assignments.
Definition: int.hh:83