Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
dom.cpp
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  *
6  * Copyright:
7  * Christian Schulte, 2005
8  *
9  * Last modified:
10  * $Date$ by $Author$
11  * $Revision$
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <gecode/minimodel.hh>
39 
40 #include "test/int.hh"
41 
42 namespace Test { namespace Int {
43 
45  namespace Dom {
46 
52  class DomInt : public Test {
54  public:
56  DomInt(int n)
57  : Test("Dom::Int::"+str(n),n,-4,4,n == 1,
58  Gecode::IPL_DOM) {}
60  virtual bool solution(const Assignment& x) const {
61  for (int i=x.size(); i--; )
62  if (x[i] != -2)
63  return false;
64  return true;
65  }
67  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
68  if (x.size() == 1)
69  Gecode::dom(home, x[0], -2);
70  else
71  Gecode::dom(home, x, -2);
72  }
74  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
75  Gecode::Reify r) {
76  assert(x.size() == 1);
77  if (Base::rand(2) != 0) {
78  Gecode::dom(home, x[0], -2, r);
79  } else {
80  switch (r.mode()) {
81  case Gecode::RM_EQV:
82  Gecode::rel(home, Gecode::dom(x[0], -2) == r.var()); break;
83  case Gecode::RM_IMP:
84  Gecode::rel(home, Gecode::dom(x[0], -2) << r.var()); break;
85  case Gecode::RM_PMI:
86  Gecode::rel(home, Gecode::dom(x[0], -2) >> r.var()); break;
87  default: GECODE_NEVER;
88  }
89  }
90  }
91  };
92 
93 
95  class DomRange : public Test {
96  public:
98  DomRange(int n)
99  : Test("Dom::Range::"+str(n),n,-4,4,n == 1,
100  Gecode::IPL_DOM) {}
102  virtual bool solution(const Assignment& x) const {
103  for (int i=x.size(); i--; )
104  if ((x[i] < -2) || (x[i] > 2))
105  return false;
106  return true;
107  }
109  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
110  if (x.size() == 1)
111  Gecode::dom(home, x[0], -2, 2);
112  else
113  Gecode::dom(home, x, -2, 2);
114  }
116  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
117  Gecode::Reify r) {
118  assert(x.size() == 1);
119  if (Base::rand(2) != 0) {
120  Gecode::dom(home, x[0], -2, 2, r);
121  } else {
122  switch (r.mode()) {
123  case Gecode::RM_EQV:
124  Gecode::rel(home, Gecode::dom(x[0], -2, 2) == r.var()); break;
125  case Gecode::RM_IMP:
126  Gecode::rel(home, Gecode::dom(x[0], -2, 2) << r.var()); break;
127  case Gecode::RM_PMI:
128  Gecode::rel(home, Gecode::dom(x[0], -2, 2) >> r.var()); break;
129  default: GECODE_NEVER;
130  }
131  }
132  }
133  };
134 
136  class DomRangeEmpty : public Test {
137  public:
139  DomRangeEmpty(void) : Test("Dom::Range::Empty",1,-4,4,true) {}
141  virtual bool solution(const Assignment&) const {
142  return false;
143  }
145  virtual void post(Gecode::Space& home, Gecode::IntVarArray&) {
146  home.fail();
147  }
149  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
150  Gecode::Reify r) {
151  Gecode::dom(home, x[0], 3, 2, r);
152  }
153  };
154 
155 
156  const int r[4][2] = {
157  {-4,-3},{-1,-1},{1,1},{3,5}
158  };
159  Gecode::IntSet d(r,4);
160 
162  class DomDom : public Test {
163  public:
165  DomDom(int n)
166  : Test("Dom::Dom::"+str(n),n,-6,6,n == 1,
167  Gecode::IPL_DOM) {}
169  virtual bool solution(const Assignment& x) const {
170  for (int i=x.size(); i--; )
171  if (!(((x[i] >= -4) && (x[i] <= -3)) ||
172  ((x[i] >= -1) && (x[i] <= -1)) ||
173  ((x[i] >= 1) && (x[i] <= 1)) ||
174  ((x[i] >= 3) && (x[i] <= 5))))
175  return false;
176  return true;
177  }
179  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
180  if (x.size() == 1)
181  Gecode::dom(home, x[0], d);
182  else
183  Gecode::dom(home, x, d);
184  }
186  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
187  Gecode::Reify r) {
188  assert(x.size() == 1);
189  if (Base::rand(2) != 0) {
190  Gecode::dom(home, x[0], d, r);
191  } else {
192  switch (r.mode()) {
193  case Gecode::RM_EQV:
194  Gecode::rel(home, Gecode::dom(x[0], d) == r.var()); break;
195  case Gecode::RM_IMP:
196  Gecode::rel(home, Gecode::dom(x[0], d) << r.var()); break;
197  case Gecode::RM_PMI:
198  Gecode::rel(home, Gecode::dom(x[0], d) >> r.var()); break;
199  default: GECODE_NEVER;
200  }
201  }
202  }
203  };
204 
205  DomInt di1(1);
206  DomInt di3(3);
207  DomRange dr1(1);
208  DomRange dr3(3);
209  DomDom dd1(1);
210  DomDom dd3(3);
213 
214  }
215 }}
216 
217 // STATISTICS: test-int
218 
DomRangeEmpty dre
Definition: dom.cpp:211
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: dom.cpp:67
DomDom(int n)
Create and register test.
Definition: dom.cpp:165
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition: int.hpp:212
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: dom.cpp:102
DomInt(int n)
Create and register test.
Definition: dom.cpp:56
Inverse implication for reification.
Definition: int.hh:848
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:973
Test for domain constraint (integer)
Definition: dom.cpp:53
ReifyMode mode(void) const
Return reification mode.
Definition: reify.hpp:60
int size(void) const
Return number of variables.
Definition: int.hpp:50
Test for domain constraint (full integer set)
Definition: dom.cpp:162
static Gecode::Support::RandomGenerator rand
Random number generator.
Definition: test.hh:138
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition: dom.cpp:44
Integer variable array.
Definition: int.hh:742
Test for domain constraint (empty range)
Definition: dom.cpp:136
Computation spaces.
Definition: core.hpp:1668
DomDom dd3(3)
Gecode::IntSet d(r, 4)
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition: dom.cpp:74
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
void fail(void)
Fail space.
Definition: core.hpp:3900
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: dom.cpp:109
Reification specification.
Definition: int.hh:855
virtual bool solution(const Assignment &) const
Test whether x is solution
Definition: dom.cpp:141
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition: dom.cpp:149
DomRange dr1(1)
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: dom.cpp:179
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition: dom.cpp:186
Integer sets.
Definition: int.hh:174
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: dom.cpp:60
DomInt di1(1)
DomInt di3(3)
virtual void post(Gecode::Space &home, Gecode::IntVarArray &)
Post constraint on x.
Definition: dom.cpp:145
DomRange(int n)
Create and register test.
Definition: dom.cpp:98
General test support.
Definition: afc.cpp:43
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
DomRangeEmpty(void)
Create and register test.
Definition: dom.cpp:139
Base class for assignments
Definition: int.hh:63
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:47
Domain propagation Options: basic versus advanced propagation.
Definition: int.hh:958
BoolVar var(void) const
Return Boolean control variable.
Definition: reify.hpp:52
DomRange dr3(3)
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition: dom.cpp:116
DomDom dd1(1)
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: dom.cpp:169
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:841
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
const int r[4][2]
Definition: dom.cpp:156
Test for domain constraint (range)
Definition: dom.cpp:95
Equivalence for reification (default)
Definition: int.hh:834