Generated on Sat Jun 2 2018 07:17:44 for Gecode by doxygen 1.8.13
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  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 #include "test/set.hh"
35 
36 using namespace Gecode;
37 
38 namespace Test { namespace Set {
39 
41  namespace RelOpConst {
42 
48 
49  static IntSet ds_33(-3,3);
50  static IntSet ds_22(-2,2);
51  static IntSet ds_12(-1,2);
52 
53  static IntSet iss[] = {IntSet(-1,1), IntSet(-4,-4), IntSet(0,2)};
54 
56  class RelSIS : public SetTest {
57  private:
58  IntSet is;
61  bool inverse;
62 
63  template<class I, class J>
64  bool
65  sol(I& i, J& j) const {
66  switch (srt) {
67  case SRT_EQ: return Iter::Ranges::equal(i,j);
68  case SRT_NQ: return !Iter::Ranges::equal(i,j);
69  case SRT_SUB: return Iter::Ranges::subset(i,j);
70  case SRT_SUP: return Iter::Ranges::subset(j,i);
71  case SRT_DISJ:
72  {
74  return !inter();
75  }
76  case SRT_CMPL:
77  {
79  return Iter::Ranges::equal(i,jc);
80  }
81  }
83  return false;
84  }
85 
86  public:
89  int intSet, bool inverse0)
90  : SetTest("RelOp::ConstSIS::"+str(sot0)+"::"+str(srt0)+"::"+
91  str(intSet)+(inverse0 ? "i" :""),2,ds_22,false)
92  , is(iss[intSet]), sot(sot0), srt(srt0), inverse(inverse0) {}
94  bool solution(const SetAssignment& x) const {
95  IntSetRanges isr(is);
96  CountableSetRanges xr0(x.lub, x[0]);
97  CountableSetRanges xr1(x.lub, x[1]);
98  switch (sot) {
99  case SOT_UNION:
100  {
102  u(isr, xr0);
103  return sol(u,xr1);
104  }
105  break;
106  case SOT_DUNION:
107  {
109  inter(isr, xr0);
110  if (inter())
111  return false;
113  u(isr,xr0);
114  return sol(u,xr1);
115  }
116  break;
117  case SOT_INTER:
118  {
120  u(isr,xr0);
121  return sol(u,xr1);
122  }
123  break;
124  case SOT_MINUS:
125  {
126  if (!inverse) {
128  u(isr,xr0);
129  return sol(u,xr1);
130  } else {
132  u(xr0,isr);
133  return sol(u,xr1);
134 
135  }
136  }
137  break;
138  }
139  GECODE_NEVER;
140  return false;
141  }
143  void post(Space& home, SetVarArray& x, IntVarArray&) {
144  if (!inverse)
145  Gecode::rel(home, is, sot, x[0], srt, x[1]);
146  else
147  Gecode::rel(home, x[0], sot, is, srt, x[1]);
148  }
149  };
150 
152  class RelSSI : public SetTest {
153  private:
154  IntSet is;
155  Gecode::SetOpType sot;
156  Gecode::SetRelType srt;
157 
158  template<class I, class J>
159  bool
160  sol(I& i, J& j) const {
161  switch (srt) {
162  case SRT_EQ: return Iter::Ranges::equal(i,j);
163  case SRT_NQ: return !Iter::Ranges::equal(i,j);
164  case SRT_SUB: return Iter::Ranges::subset(i,j);
165  case SRT_SUP: return Iter::Ranges::subset(j,i);
166  case SRT_DISJ:
167  {
169  return !inter();
170  }
171  case SRT_CMPL:
172  {
174  return Iter::Ranges::equal(i,jc);
175  }
176  }
177  GECODE_NEVER;
178  return false;
179  }
180 
181  public:
184  int intSet)
185  : SetTest("RelOp::ConstSSI::"+str(sot0)+"::"+str(srt0)+"::"+
186  str(intSet),2,ds_22,false)
187  , is(iss[intSet]), sot(sot0), srt(srt0) {}
189  bool solution(const SetAssignment& x) const {
190  CountableSetRanges xr0(x.lub, x[0]);
191  CountableSetRanges xr1(x.lub, x[1]);
192  IntSetRanges isr(is);
193  switch (sot) {
194  case SOT_UNION:
195  {
197  u(xr0, xr1);
198  return sol(u,isr);
199  }
200  break;
201  case SOT_DUNION:
202  {
204  inter(xr0, xr1);
205  if (inter())
206  return false;
208  u(xr0, xr1);
209  return sol(u,isr);
210  }
211  break;
212  case SOT_INTER:
213  {
215  u(xr0,xr1);
216  return sol(u,isr);
217  }
218  break;
219  case SOT_MINUS:
220  {
222  u(xr0,xr1);
223  return sol(u,isr);
224  }
225  break;
226  }
227  GECODE_NEVER;
228  return false;
229  }
231  void post(Space& home, SetVarArray& x, IntVarArray&) {
232  Gecode::rel(home, x[0], sot, x[1], srt, is);
233  }
234  };
235 
237  class RelISI : public SetTest {
238  private:
239  IntSet is0;
240  IntSet is1;
241  Gecode::SetOpType sot;
242  Gecode::SetRelType srt;
243  bool inverse;
244 
245  template<class I, class J>
246  bool
247  sol(I& i, J& j) const {
248  switch (srt) {
249  case SRT_EQ: return Iter::Ranges::equal(i,j);
250  case SRT_NQ: return !Iter::Ranges::equal(i,j);
251  case SRT_SUB: return Iter::Ranges::subset(i,j);
252  case SRT_SUP: return Iter::Ranges::subset(j,i);
253  case SRT_DISJ:
254  {
256  return !inter();
257  }
258  case SRT_CMPL:
259  {
261  return Iter::Ranges::equal(i,jc);
262  }
263  }
264  GECODE_NEVER;
265  return false;
266  }
267 
268  public:
271  int intSet0, int intSet1, bool inverse0)
272  : SetTest("RelOp::ConstISI::"+str(sot0)+"::"+str(srt0)+"::"+
273  str(intSet0)+"::"+str(intSet1)+
274  (inverse0 ? "i" : ""),1,ds_33,false)
275  , is0(iss[intSet0]), is1(iss[intSet1]), sot(sot0), srt(srt0)
276  , inverse(inverse0) {}
278  bool solution(const SetAssignment& x) const {
279  CountableSetRanges xr0(x.lub, x[0]);
280  IntSetRanges isr0(is0);
281  IntSetRanges isr1(is1);
282  switch (sot) {
283  case SOT_UNION:
284  {
286  u(isr0, xr0);
287  return sol(u,isr1);
288  }
289  break;
290  case SOT_DUNION:
291  {
293  inter(isr0, xr0);
294  if (inter())
295  return false;
297  u(isr0, xr0);
298  return sol(u,isr1);
299  }
300  break;
301  case SOT_INTER:
302  {
304  u(isr0,xr0);
305  return sol(u,isr1);
306  }
307  break;
308  case SOT_MINUS:
309  {
310  if (!inverse) {
312  u(isr0,xr0);
313  return sol(u,isr1);
314  } else {
316  u(xr0,isr0);
317  return sol(u,isr1);
318  }
319  }
320  break;
321  }
322  GECODE_NEVER;
323  return false;
324  }
326  void post(Space& home, SetVarArray& x, IntVarArray&) {
327  if (!inverse)
328  Gecode::rel(home, is0, sot, x[0], srt, is1);
329  else
330  Gecode::rel(home, x[0], sot, is0, srt, is1);
331  }
332  };
333 
335  class Create {
336  public:
338  Create(void) {
339  using namespace Gecode;
340  for (SetRelTypes srts; srts(); ++srts) {
341  for (SetOpTypes sots; sots(); ++sots) {
342  for (int i=0; i<=2; i++) {
343  (void) new RelSIS(sots.sot(),srts.srt(),i,false);
344  (void) new RelSIS(sots.sot(),srts.srt(),i,true);
345  (void) new RelSSI(sots.sot(),srts.srt(),i);
346  (void) new RelISI(sots.sot(),srts.srt(),i,0,false);
347  (void) new RelISI(sots.sot(),srts.srt(),i,1,false);
348  (void) new RelISI(sots.sot(),srts.srt(),i,2,false);
349  (void) new RelISI(sots.sot(),srts.srt(),i,0,true);
350  (void) new RelISI(sots.sot(),srts.srt(),i,1,true);
351  (void) new RelISI(sots.sot(),srts.srt(),i,2,true);
352  }
353  }
354  }
355  }
356  };
357 
359 
361 
362 }}}
363 
364 // STATISTICS: test-set
Iterator for Boolean operation types.
Definition: set.hh:352
SetRelType
Common relation types for sets.
Definition: set.hh:641
Iterator for set relation types.
Definition: set.hh:334
Range iterator for integer sets.
Definition: int.hh:268
bool solution(const SetAssignment &x) const
Test whether x is solution
Test for set relation constraint with constants
bool solution(const SetAssignment &x) const
Test whether x is solution
bool equal(I &i, J &j)
Check whether range iterators i and j are equal.
Integer variable array.
Definition: int.hh:738
SetOpType
Common operations for sets.
Definition: set.hh:658
Superset ( )
Definition: set.hh:645
Complement.
Definition: set.hh:647
Computation spaces.
Definition: core.hpp:1701
RelISI(Gecode::SetOpType sot0, Gecode::SetRelType srt0, int intSet0, int intSet1, bool inverse0)
Create and register test.
Difference.
Definition: set.hh:662
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:292
Subset ( )
Definition: set.hh:644
Gecode::IntSet lub
The common superset for all domains.
Definition: set.hh:154
Intersection
Definition: set.hh:661
union Gecode::@585::NNF::@62 u
Union depending on nodetype t.
Integer sets.
Definition: int.hh:170
Help class to create and register tests.
bool solution(const SetAssignment &x) const
Test whether x is solution
Range iterator for computing union (binary)
SetExpr inter(const SetVarArgs &x)
Intersection of set variables.
Definition: set-expr.cpp:695
General test support.
Definition: afc.cpp:39
Union.
Definition: set.hh:659
Create(void)
Perform creation and registration.
Disjoint union.
Definition: set.hh:660
Base class for tests with set constraints
Definition: set.hh:273
Generate all set assignments.
Definition: set.hh:142
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:43
void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Range iterator producing subsets of an IntSet.
Definition: set.hh:98
Equality ( )
Definition: set.hh:642
Disjoint ( )
Definition: set.hh:646
Post propagator for SetVar x
Definition: set.hh:765
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
Set variable array
Definition: set.hh:568
Disequality ( )
Definition: set.hh:643
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:43
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56
Test for set relation constraint with constants
Test for set relation constraint with constants