Generated on Sat Feb 7 2015 02:01:16 for Gecode by doxygen 1.8.9.1
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: 2011-11-29 17:20:37 +0100 (Tue, 29 Nov 2011) $ by $Author: schulte $
11  * $Revision: 12486 $
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) : Test("Dom::Int::"+str(n),n,-4,4,n == 1) {}
56  virtual bool solution(const Assignment& x) const {
57  for (int i=x.size(); i--; )
58  if (x[i] != -2)
59  return false;
60  return true;
61  }
63  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
64  if (x.size() == 1)
65  Gecode::dom(home, x[0], -2);
66  else
67  Gecode::dom(home, x, -2);
68  }
70  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
71  Gecode::Reify r) {
72  assert(x.size() == 1);
73  Gecode::dom(home, x[0], -2, r);
74  }
75  };
76 
77 
79  class DomRange : public Test {
80  public:
82  DomRange(int n) : Test("Dom::Range::"+str(n),n,-4,4,n == 1) {}
84  virtual bool solution(const Assignment& x) const {
85  for (int i=x.size(); i--; )
86  if ((x[i] < -2) || (x[i] > 2))
87  return false;
88  return true;
89  }
91  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
92  if (x.size() == 1)
93  Gecode::dom(home, x[0], -2, 2);
94  else
95  Gecode::dom(home, x, -2, 2);
96  }
98  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
99  Gecode::Reify r) {
100  assert(x.size() == 1);
101  Gecode::dom(home, x[0], -2, 2, r);
102  }
103  };
104 
106  class DomRangeEmpty : public Test {
107  public:
109  DomRangeEmpty(void) : Test("Dom::Range::Empty",1,-4,4,true) {}
111  virtual bool solution(const Assignment&) const {
112  return false;
113  }
115  virtual void post(Gecode::Space& home, Gecode::IntVarArray&) {
116  home.fail();
117  }
119  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
120  Gecode::Reify r) {
121  Gecode::dom(home, x[0], 3, 2, r);
122  }
123  };
124 
125 
126  const int r[4][2] = {
127  {-4,-3},{-1,-1},{1,1},{3,5}
128  };
129  Gecode::IntSet d(r,4);
130 
132  class DomDom : public Test {
133  public:
135  DomDom(int n) : Test("Dom::Dom::"+str(n),n,-6,6,n == 1) {}
137  virtual bool solution(const Assignment& x) const {
138  for (int i=x.size(); i--; )
139  if (!(((x[i] >= -4) && (x[i] <= -3)) ||
140  ((x[i] >= -1) && (x[i] <= -1)) ||
141  ((x[i] >= 1) && (x[i] <= 1)) ||
142  ((x[i] >= 3) && (x[i] <= 5))))
143  return false;
144  return true;
145  }
147  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
148  if (x.size() == 1)
149  Gecode::dom(home, x[0], d);
150  else
151  Gecode::dom(home, x, d);
152  }
154  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
155  Gecode::Reify r) {
156  assert(x.size() == 1);
157  Gecode::dom(home, x[0], d, r);
158  }
159  };
160 
161  DomInt di1(1);
162  DomInt di3(3);
163  DomRange dr1(1);
164  DomRange dr3(3);
165  DomDom dd1(1);
166  DomDom dd3(3);
169 
170  }
171 }}
172 
173 // STATISTICS: test-int
174 
DomRangeEmpty dre
Definition: dom.cpp:167
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: dom.cpp:63
DomDom(int n)
Create and register test.
Definition: dom.cpp:135
DomInt(int n)
Create and register test.
Definition: dom.cpp:54
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: dom.cpp:56
Test for domain constraint (integer)
Definition: dom.cpp:51
Test for domain constraint (full integer set)
Definition: dom.cpp:132
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition: dom.cpp:44
Integer variable array.
Definition: int.hh:741
Test for domain constraint (empty range)
Definition: dom.cpp:106
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: dom.cpp:137
Computation spaces.
Definition: core.hpp:1362
DomDom dd3(3)
static std::string str(Gecode::ExtensionalPropKind epk)
Map extensional propagation kind to string.
Definition: int.hpp:212
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:70
Gecode::IntArgs i(4, 1, 2, 3, 4)
virtual bool solution(const Assignment &) const
Test whether x is solution
Definition: dom.cpp:111
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
void fail(void)
Fail space.
Definition: core.hpp:3428
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: dom.cpp:91
Reification specification.
Definition: int.hh:854
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition: dom.cpp:119
DomRange dr1(1)
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: dom.cpp:147
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition: dom.cpp:154
Integer sets.
Definition: int.hh:171
DomInt di1(1)
DomInt di3(3)
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: dom.cpp:84
virtual void post(Gecode::Space &home, Gecode::IntVarArray &)
Post constraint on x.
Definition: dom.cpp:115
DomRange(int n)
Create and register test.
Definition: dom.cpp:82
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:109
Base class for assignments
Definition: int.hh:63
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:98
DomDom dd1(1)
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:985
const int r[4][2]
Definition: dom.cpp:126
int size(void) const
Return number of variables.
Definition: int.hpp:50
Test for domain constraint (range)
Definition: dom.cpp:79