Generated on Sat Feb 7 2015 02:01:33 for Gecode by doxygen 1.8.9.1
rel-op-const.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, 2005
8  *
9  * Last modified:
10  * $Date: 2010-07-28 18:45:22 +0200 (Wed, 28 Jul 2010) $ by $Author: schulte $
11  * $Revision: 11297 $
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 RelOpConst {
46 
52 
53  static IntSet ds_33(-3,3);
54  static IntSet ds_22(-2,2);
55  static IntSet ds_12(-1,2);
56 
57  static IntSet iss[] = {IntSet(-1,1), IntSet(-4,-4), IntSet(0,2)};
58 
60  class RelSIS : public SetTest {
61  private:
62  IntSet is;
65  bool inverse;
66 
67  template<class I, class J>
68  bool
69  sol(I& i, J& j) const {
70  switch (srt) {
71  case SRT_EQ: return Iter::Ranges::equal(i,j);
72  case SRT_NQ: return !Iter::Ranges::equal(i,j);
73  case SRT_SUB: return Iter::Ranges::subset(i,j);
74  case SRT_SUP: return Iter::Ranges::subset(j,i);
75  case SRT_DISJ:
76  {
78  return !inter();
79  }
80  case SRT_CMPL:
81  {
83  return Iter::Ranges::equal(i,jc);
84  }
85  }
87  return false;
88  }
89 
90  public:
93  int intSet, bool inverse0)
94  : SetTest("RelOp::ConstSIS::"+str(sot0)+"::"+str(srt0)+"::"+
95  str(intSet)+(inverse0 ? "i" :""),2,ds_22,false)
96  , is(iss[intSet]), sot(sot0), srt(srt0), inverse(inverse0) {}
98  bool solution(const SetAssignment& x) const {
99  IntSetRanges isr(is);
100  CountableSetRanges xr0(x.lub, x[0]);
101  CountableSetRanges xr1(x.lub, x[1]);
102  switch (sot) {
103  case SOT_UNION:
104  {
106  u(isr, xr0);
107  return sol(u,xr1);
108  }
109  break;
110  case SOT_DUNION:
111  {
113  inter(isr, xr0);
114  if (inter())
115  return false;
117  u(isr,xr0);
118  return sol(u,xr1);
119  }
120  break;
121  case SOT_INTER:
122  {
124  u(isr,xr0);
125  return sol(u,xr1);
126  }
127  break;
128  case SOT_MINUS:
129  {
130  if (!inverse) {
132  u(isr,xr0);
133  return sol(u,xr1);
134  } else {
136  u(xr0,isr);
137  return sol(u,xr1);
138 
139  }
140  }
141  break;
142  }
143  GECODE_NEVER;
144  return false;
145  }
147  void post(Space& home, SetVarArray& x, IntVarArray&) {
148  if (!inverse)
149  Gecode::rel(home, is, sot, x[0], srt, x[1]);
150  else
151  Gecode::rel(home, x[0], sot, is, srt, x[1]);
152  }
153  };
154 
156  class RelSSI : public SetTest {
157  private:
158  IntSet is;
159  Gecode::SetOpType sot;
160  Gecode::SetRelType srt;
161 
162  template<class I, class J>
163  bool
164  sol(I& i, J& j) const {
165  switch (srt) {
166  case SRT_EQ: return Iter::Ranges::equal(i,j);
167  case SRT_NQ: return !Iter::Ranges::equal(i,j);
168  case SRT_SUB: return Iter::Ranges::subset(i,j);
169  case SRT_SUP: return Iter::Ranges::subset(j,i);
170  case SRT_DISJ:
171  {
173  return !inter();
174  }
175  case SRT_CMPL:
176  {
178  return Iter::Ranges::equal(i,jc);
179  }
180  }
181  GECODE_NEVER;
182  return false;
183  }
184 
185  public:
188  int intSet)
189  : SetTest("RelOp::ConstSSI::"+str(sot0)+"::"+str(srt0)+"::"+
190  str(intSet),2,ds_22,false)
191  , is(iss[intSet]), sot(sot0), srt(srt0) {}
193  bool solution(const SetAssignment& x) const {
194  CountableSetRanges xr0(x.lub, x[0]);
195  CountableSetRanges xr1(x.lub, x[1]);
196  IntSetRanges isr(is);
197  switch (sot) {
198  case SOT_UNION:
199  {
201  u(xr0, xr1);
202  return sol(u,isr);
203  }
204  break;
205  case SOT_DUNION:
206  {
208  inter(xr0, xr1);
209  if (inter())
210  return false;
212  u(xr0, xr1);
213  return sol(u,isr);
214  }
215  break;
216  case SOT_INTER:
217  {
219  u(xr0,xr1);
220  return sol(u,isr);
221  }
222  break;
223  case SOT_MINUS:
224  {
226  u(xr0,xr1);
227  return sol(u,isr);
228  }
229  break;
230  }
231  GECODE_NEVER;
232  return false;
233  }
235  void post(Space& home, SetVarArray& x, IntVarArray&) {
236  Gecode::rel(home, x[0], sot, x[1], srt, is);
237  }
238  };
239 
241  class RelISI : public SetTest {
242  private:
243  IntSet is0;
244  IntSet is1;
245  Gecode::SetOpType sot;
246  Gecode::SetRelType srt;
247  bool inverse;
248 
249  template<class I, class J>
250  bool
251  sol(I& i, J& j) const {
252  switch (srt) {
253  case SRT_EQ: return Iter::Ranges::equal(i,j);
254  case SRT_NQ: return !Iter::Ranges::equal(i,j);
255  case SRT_SUB: return Iter::Ranges::subset(i,j);
256  case SRT_SUP: return Iter::Ranges::subset(j,i);
257  case SRT_DISJ:
258  {
260  return !inter();
261  }
262  case SRT_CMPL:
263  {
265  return Iter::Ranges::equal(i,jc);
266  }
267  }
268  GECODE_NEVER;
269  return false;
270  }
271 
272  public:
275  int intSet0, int intSet1, bool inverse0)
276  : SetTest("RelOp::ConstISI::"+str(sot0)+"::"+str(srt0)+"::"+
277  str(intSet0)+"::"+str(intSet1)+
278  (inverse0 ? "i" : ""),1,ds_33,false)
279  , is0(iss[intSet0]), is1(iss[intSet1]), sot(sot0), srt(srt0)
280  , inverse(inverse0) {}
282  bool solution(const SetAssignment& x) const {
283  CountableSetRanges xr0(x.lub, x[0]);
284  IntSetRanges isr0(is0);
285  IntSetRanges isr1(is1);
286  switch (sot) {
287  case SOT_UNION:
288  {
290  u(isr0, xr0);
291  return sol(u,isr1);
292  }
293  break;
294  case SOT_DUNION:
295  {
297  inter(isr0, xr0);
298  if (inter())
299  return false;
301  u(isr0, xr0);
302  return sol(u,isr1);
303  }
304  break;
305  case SOT_INTER:
306  {
308  u(isr0,xr0);
309  return sol(u,isr1);
310  }
311  break;
312  case SOT_MINUS:
313  {
314  if (!inverse) {
316  u(isr0,xr0);
317  return sol(u,isr1);
318  } else {
320  u(xr0,isr0);
321  return sol(u,isr1);
322  }
323  }
324  break;
325  }
326  GECODE_NEVER;
327  return false;
328  }
330  void post(Space& home, SetVarArray& x, IntVarArray&) {
331  if (!inverse)
332  Gecode::rel(home, is0, sot, x[0], srt, is1);
333  else
334  Gecode::rel(home, x[0], sot, is0, srt, is1);
335  }
336  };
337 
339  class Create {
340  public:
342  Create(void) {
343  using namespace Gecode;
344  for (SetRelTypes srts; srts(); ++srts) {
345  for (SetOpTypes sots; sots(); ++sots) {
346  for (int i=0; i<=2; i++) {
347  (void) new RelSIS(sots.sot(),srts.srt(),i,false);
348  (void) new RelSIS(sots.sot(),srts.srt(),i,true);
349  (void) new RelSSI(sots.sot(),srts.srt(),i);
350  (void) new RelISI(sots.sot(),srts.srt(),i,0,false);
351  (void) new RelISI(sots.sot(),srts.srt(),i,1,false);
352  (void) new RelISI(sots.sot(),srts.srt(),i,2,false);
353  (void) new RelISI(sots.sot(),srts.srt(),i,0,true);
354  (void) new RelISI(sots.sot(),srts.srt(),i,1,true);
355  (void) new RelISI(sots.sot(),srts.srt(),i,2,true);
356  }
357  }
358  }
359  }
360  };
361 
363 
365 
366 }}}
367 
368 // STATISTICS: test-set
IntRelType inverse(const IntRelType irt)
Inverse the relation.
Definition: bool-post.cpp:47
Iterator for Boolean operation types.
Definition: set.hh:343
SetRelType
Common relation types for sets.
Definition: set.hh:644
Iterator for set relation types.
Definition: set.hh:325
Range iterator for integer sets.
Definition: int.hh:271
Test for set relation constraint with constants
bool equal(I &i, J &j)
Check whether range iterators i and j are equal.
Integer variable array.
Definition: int.hh:741
SetOpType
Common operations for sets.
Definition: set.hh:661
Superset ( )
Definition: set.hh:648
Complement.
Definition: set.hh:650
Computation spaces.
Definition: core.hpp:1362
RelISI(Gecode::SetOpType sot0, Gecode::SetRelType srt0, int intSet0, int intSet1, bool inverse0)
Create and register test.
Difference.
Definition: set.hh:665
void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Gecode::IntArgs i(4, 1, 2, 3, 4)
void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Range iterator for computing intersection (binary)
RelSSI(Gecode::SetOpType sot0, Gecode::SetRelType srt0, int intSet)
Create and register test.
A complement iterator spezialized for the BndSet limits.
Definition: var-imp.hpp:296
Subset ( )
Definition: set.hh:647
Gecode::IntSet lub
The common superset for all domains.
Definition: set.hh:170
Intersection
Definition: set.hh:664
Integer sets.
Definition: int.hh:171
Help class to create and register tests.
Range iterator for computing union (binary)
SetExpr inter(const SetVarArgs &x)
Intersection of set variables.
Definition: set-expr.cpp:696
union Gecode::@518::NNF::@57 u
Union depending on nodetype t.
General test support.
Definition: afc.cpp:43
Union.
Definition: set.hh:662
bool solution(const SetAssignment &x) const
Test whether x is solution
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Create(void)
Perform creation and registration.
Disjoint union.
Definition: set.hh:663
Base class for tests with set constraints
Definition: set.hh:271
Generate all set assignments.
Definition: set.hh:158
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:47
void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Range iterator producing subsets of an IntSet.
Definition: set.hh:114
Equality ( )
Definition: set.hh:645
Disjoint ( )
Definition: set.hh:649
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
Set variable array
Definition: set.hh:571
bool solution(const SetAssignment &x) const
Test whether x is solution
Disequality ( )
Definition: set.hh:646
RelSIS(Gecode::SetOpType sot0, Gecode::SetRelType srt0, int intSet, bool inverse0)
Create and register test.
Gecode toplevel namespace
Range iterator for computing set difference.
Definition: ranges-diff.hpp:47
bool solution(const SetAssignment &x) const
Test whether x is solution
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
Test for set relation constraint with constants
Test for set relation constraint with constants