Generated on Tue Jul 18 2017 18:41:42 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: 2016-10-25 12:52:26 +0200 (Tue, 25 Oct 2016) $ by $Author: schulte $
11  * $Revision: 15233 $
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 "test/int.hh"
39 
40 namespace Test { namespace Int {
41 
43  namespace Dom {
44 
50  class DomInt : public Test {
52  public:
54  DomInt(int n)
55  : Test("Dom::Int::"+str(n),n,-4,4,n == 1,
56  Gecode::IPL_DOM) {}
58  virtual bool solution(const Assignment& x) const {
59  for (int i=x.size(); i--; )
60  if (x[i] != -2)
61  return false;
62  return true;
63  }
65  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
66  if (x.size() == 1)
67  Gecode::dom(home, x[0], -2);
68  else
69  Gecode::dom(home, x, -2);
70  }
72  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
73  Gecode::Reify r) {
74  assert(x.size() == 1);
75  Gecode::dom(home, x[0], -2, r);
76  }
77  };
78 
79 
81  class DomRange : public Test {
82  public:
84  DomRange(int n)
85  : Test("Dom::Range::"+str(n),n,-4,4,n == 1,
86  Gecode::IPL_DOM) {}
88  virtual bool solution(const Assignment& x) const {
89  for (int i=x.size(); i--; )
90  if ((x[i] < -2) || (x[i] > 2))
91  return false;
92  return true;
93  }
95  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
96  if (x.size() == 1)
97  Gecode::dom(home, x[0], -2, 2);
98  else
99  Gecode::dom(home, x, -2, 2);
100  }
102  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
103  Gecode::Reify r) {
104  assert(x.size() == 1);
105  Gecode::dom(home, x[0], -2, 2, r);
106  }
107  };
108 
110  class DomRangeEmpty : public Test {
111  public:
113  DomRangeEmpty(void) : Test("Dom::Range::Empty",1,-4,4,true) {}
115  virtual bool solution(const Assignment&) const {
116  return false;
117  }
119  virtual void post(Gecode::Space& home, Gecode::IntVarArray&) {
120  home.fail();
121  }
123  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
124  Gecode::Reify r) {
125  Gecode::dom(home, x[0], 3, 2, r);
126  }
127  };
128 
129 
130  const int r[4][2] = {
131  {-4,-3},{-1,-1},{1,1},{3,5}
132  };
133  Gecode::IntSet d(r,4);
134 
136  class DomDom : public Test {
137  public:
139  DomDom(int n)
140  : Test("Dom::Dom::"+str(n),n,-6,6,n == 1,
141  Gecode::IPL_DOM) {}
143  virtual bool solution(const Assignment& x) const {
144  for (int i=x.size(); i--; )
145  if (!(((x[i] >= -4) && (x[i] <= -3)) ||
146  ((x[i] >= -1) && (x[i] <= -1)) ||
147  ((x[i] >= 1) && (x[i] <= 1)) ||
148  ((x[i] >= 3) && (x[i] <= 5))))
149  return false;
150  return true;
151  }
153  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
154  if (x.size() == 1)
155  Gecode::dom(home, x[0], d);
156  else
157  Gecode::dom(home, x, d);
158  }
160  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
161  Gecode::Reify r) {
162  assert(x.size() == 1);
163  Gecode::dom(home, x[0], d, r);
164  }
165  };
166 
167  DomInt di1(1);
168  DomInt di3(3);
169  DomRange dr1(1);
170  DomRange dr3(3);
171  DomDom dd1(1);
172  DomDom dd3(3);
175 
176  }
177 }}
178 
179 // STATISTICS: test-int
180 
DomRangeEmpty dre
Definition: dom.cpp:173
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: dom.cpp:65
DomDom(int n)
Create and register test.
Definition: dom.cpp:139
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:88
DomInt(int n)
Create and register test.
Definition: dom.cpp:54
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:985
Test for domain constraint (integer)
Definition: dom.cpp:51
int size(void) const
Return number of variables.
Definition: int.hpp:50
Test for domain constraint (full integer set)
Definition: dom.cpp:136
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition: dom.cpp:44
Integer variable array.
Definition: int.hh:744
Test for domain constraint (empty range)
Definition: dom.cpp:110
Computation spaces.
Definition: core.hpp:1748
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:72
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:4081
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: dom.cpp:95
Reification specification.
Definition: int.hh:857
virtual bool solution(const Assignment &) const
Test whether x is solution
Definition: dom.cpp:115
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition: dom.cpp:123
DomRange dr1(1)
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: dom.cpp:153
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition: dom.cpp:160
Integer sets.
Definition: int.hh:174
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: dom.cpp:58
DomInt di1(1)
DomInt di3(3)
virtual void post(Gecode::Space &home, Gecode::IntVarArray &)
Post constraint on x.
Definition: dom.cpp:119
DomRange(int n)
Create and register test.
Definition: dom.cpp:84
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:113
Base class for assignments
Definition: int.hh:63
Domain propagation Preferences: prefer speed or memory.
Definition: int.hh:960
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:102
DomDom dd1(1)
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: dom.cpp:143
Gecode toplevel namespace
const int r[4][2]
Definition: dom.cpp:130
Test for domain constraint (range)
Definition: dom.cpp:81