Generated on Sat Feb 7 2015 02:01:32 for Gecode by doxygen 1.8.9.1
construct.cpp
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  *
6  * Copyright:
7  * Guido Tack, 2008
8  *
9  * Last modified:
10  * $Date: 2010-04-08 12:35:31 +0200 (Thu, 08 Apr 2010) $ by $Author: schulte $
11  * $Revision: 10684 $
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/set.hh"
39 
40 using namespace Gecode;
41 
42 namespace Test { namespace Set {
43 
45  namespace Var {
46 
48  class Construct : public SetTest {
49  public:
51  Construct(void)
52  : SetTest("Var::Construct",1,IntSet(0,0),false,0) {}
54  virtual bool solution(const SetAssignment&) const {
55  return true;
56  }
57  void con(Space& home, int glbMin, int glbMax,
58  int lubMin, int lubMax,
59  unsigned int minCard = 0,
60  unsigned int maxCard = Gecode::Set::Limits::card,
61  bool fail=true) {
62  bool ok = false;
63  try {
64  SetVar x(home, glbMin, glbMax, lubMin, lubMax, minCard, maxCard);
65  ok = true;
67  if (!fail) {
68  home.fail();
69  return;
70  }
71  ok = true;
72  }
73 
74  if (ok) {
75  try {
76  SetVarArray xs(home, 1,
77  glbMin, glbMax, lubMin, lubMax, minCard, maxCard);
79  if (!fail) {
80  home.fail();
81  return;
82  } else {
83  return;
84  }
85  }
86  if (fail) {
87  home.fail();
88  }
89  }
90  }
91  void con(Space& home, const IntSet& glb, int lubMin, int lubMax,
92  unsigned int minCard = 0,
93  unsigned int maxCard = Gecode::Set::Limits::card,
94  bool fail=true) {
95  bool ok = false;
96  try {
97  SetVar x(home, glb, lubMin, lubMax, minCard, maxCard);
98  ok = true;
100  if (!fail) {
101  home.fail();
102  return;
103  }
104  ok = true;
105  }
106  if (ok) {
107  try {
108  SetVarArray xs(home, 1,
109  glb, lubMin, lubMax, minCard, maxCard);
111  if (!fail) {
112  home.fail();
113  return;
114  } else {
115  return;
116  }
117  }
118  if (fail) {
119  home.fail();
120  }
121  }
122  }
123  void con(Space& home, int glbMin, int glbMax, const IntSet& lub,
124  unsigned int minCard = 0,
125  unsigned int maxCard = Gecode::Set::Limits::card,
126  bool fail=true) {
127  bool ok = false;
128  try {
129  SetVar x(home, glbMin, glbMax, lub, minCard, maxCard);
130  ok = true;
132  if (!fail) {
133  home.fail();
134  return;
135  }
136  ok = true;
137  }
138  if (ok) {
139  try {
140  SetVarArray xs(home, 1,
141  glbMin, glbMax, lub, minCard, maxCard);
143  if (!fail) {
144  home.fail();
145  return;
146  } else {
147  return;
148  }
149  }
150  if (fail) {
151  home.fail();
152  }
153  }
154  }
155  void con(Space& home, const IntSet& glb, const IntSet& lub,
156  unsigned int minCard = 0,
157  unsigned int maxCard = Gecode::Set::Limits::card,
158  bool fail=true) {
159  bool ok = false;
160  try {
161  SetVar x(home, glb, lub, minCard, maxCard);
162  ok = true;
164  if (!fail) {
165  home.fail();
166  return;
167  }
168  ok = true;
169  }
170  if (ok) {
171  try {
172  SetVarArray xs(home, 1,
173  glb, lub, minCard, maxCard);
175  if (!fail) {
176  home.fail();
177  return;
178  } else {
179  return;
180  }
181  }
182  if (fail) {
183  home.fail();
184  }
185  }
186  }
188  virtual void post(Space& home, SetVarArray&, IntVarArray&) {
189  // Check non-empty lower, empty upper bound
190  con(home, 1,1, 1,0);
191  con(home, IntSet(1,1), 1,0);
192  con(home, 1,1, IntSet(1,0));
193  con(home, IntSet(1,1), IntSet(1,0));
194 
195  // Check min cardinality
196  con(home, 1,0, 1,1, 2,3);
197  con(home, IntSet(1,0), 1,1, 2,3);
198  con(home, 1,0, IntSet(1,1), 2,3);
199  con(home, IntSet(1,0), IntSet(1,1), 2,3);
200 
201  // Check max cardinality
202  con(home, 1,3, 1,4, 0,2);
203  con(home, IntSet(1,3), 1,4, 0,2);
204  con(home, 1,3, IntSet(1,4), 0,2);
205  con(home, IntSet(1,3), IntSet(1,4), 0,2);
206 
207  // Check non-subset bounds
208  con(home, 1,3, 2,4);
209  con(home, IntSet(1,3), 2,4);
210  con(home, 1,3, IntSet(2,4));
211  con(home, IntSet(1,3), IntSet(2,4));
212  con(home, 1,4, 1,3);
213  con(home, IntSet(1,4), 1,3);
214  con(home, 1,4, IntSet(1,3));
215  con(home, IntSet(1,4), IntSet(1,3));
216 
217  con(home, IntSet::empty, 2, 4, 0, 10, false);
218  }
219  };
221 
222 
223 }}}
224 
225 // STATISTICS: test-set
Test for cardinality constraint
Definition: construct.cpp:48
void con(Space &home, int glbMin, int glbMax, const IntSet &lub, unsigned int minCard=0, unsigned int maxCard=Gecode::Set::Limits::card, bool fail=true)
Definition: construct.cpp:123
Integer variable array.
Definition: int.hh:741
const unsigned int card
Maximum cardinality of an integer set.
Definition: set.hh:103
void con(Space &home, int glbMin, int glbMax, int lubMin, int lubMax, unsigned int minCard=0, unsigned int maxCard=Gecode::Set::Limits::card, bool fail=true)
Definition: construct.cpp:57
Computation spaces.
Definition: core.hpp:1362
Exception: Variable created with empty domain
Definition: exception.hpp:63
Construct _con
Definition: construct.cpp:220
void fail(void)
Fail space.
Definition: core.hpp:3428
Integer sets.
Definition: int.hh:171
void con(Space &home, const IntSet &glb, int lubMin, int lubMax, unsigned int minCard=0, unsigned int maxCard=Gecode::Set::Limits::card, bool fail=true)
Definition: construct.cpp:91
static const IntSet empty
Empty set.
Definition: int.hh:262
void con(Space &home, const IntSet &glb, const IntSet &lub, unsigned int minCard=0, unsigned int maxCard=Gecode::Set::Limits::card, bool fail=true)
Definition: construct.cpp:155
General test support.
Definition: afc.cpp:43
Base class for variables.
Definition: var.hpp:44
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Set variables
Definition: set.hh:129
Base class for tests with set constraints
Definition: set.hh:271
Generate all set assignments.
Definition: set.hh:158
Set variable array
Definition: set.hh:571
Gecode toplevel namespace
Construct(void)
Create and register test.
Definition: construct.cpp:51
virtual bool solution(const SetAssignment &) const
Test whether x is solution
Definition: construct.cpp:54
virtual void post(Space &home, SetVarArray &, IntVarArray &)
Post constraint on x.
Definition: construct.cpp:188