Generated on Mon Jul 27 2020 00:00:00 for Gecode by doxygen 1.8.18
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  default: GECODE_NEVER;
82  }
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  default: GECODE_NEVER;
139  }
140  GECODE_NEVER;
141  return false;
142  }
144  void post(Space& home, SetVarArray& x, IntVarArray&) {
145  if (!inverse)
146  Gecode::rel(home, is, sot, x[0], srt, x[1]);
147  else
148  Gecode::rel(home, x[0], sot, is, srt, x[1]);
149  }
150  };
151 
153  class RelSSI : public SetTest {
154  private:
155  IntSet is;
156  Gecode::SetOpType sot;
157  Gecode::SetRelType srt;
158 
159  template<class I, class J>
160  bool
161  sol(I& i, J& j) const {
162  switch (srt) {
163  case SRT_EQ: return Iter::Ranges::equal(i,j);
164  case SRT_NQ: return !Iter::Ranges::equal(i,j);
165  case SRT_SUB: return Iter::Ranges::subset(i,j);
166  case SRT_SUP: return Iter::Ranges::subset(j,i);
167  case SRT_DISJ:
168  {
170  return !inter();
171  }
172  case SRT_CMPL:
173  {
175  return Iter::Ranges::equal(i,jc);
176  }
177  default: GECODE_NEVER;
178  }
179  GECODE_NEVER;
180  return false;
181  }
182 
183  public:
186  int intSet)
187  : SetTest("RelOp::ConstSSI::"+str(sot0)+"::"+str(srt0)+"::"+
188  str(intSet),2,ds_22,false)
189  , is(iss[intSet]), sot(sot0), srt(srt0) {}
191  bool solution(const SetAssignment& x) const {
192  CountableSetRanges xr0(x.lub, x[0]);
193  CountableSetRanges xr1(x.lub, x[1]);
194  IntSetRanges isr(is);
195  switch (sot) {
196  case SOT_UNION:
197  {
199  u(xr0, xr1);
200  return sol(u,isr);
201  }
202  break;
203  case SOT_DUNION:
204  {
206  inter(xr0, xr1);
207  if (inter())
208  return false;
210  u(xr0, xr1);
211  return sol(u,isr);
212  }
213  break;
214  case SOT_INTER:
215  {
217  u(xr0,xr1);
218  return sol(u,isr);
219  }
220  break;
221  case SOT_MINUS:
222  {
224  u(xr0,xr1);
225  return sol(u,isr);
226  }
227  break;
228  default: GECODE_NEVER;
229  }
230  GECODE_NEVER;
231  return false;
232  }
234  void post(Space& home, SetVarArray& x, IntVarArray&) {
235  Gecode::rel(home, x[0], sot, x[1], srt, is);
236  }
237  };
238 
240  class RelISI : public SetTest {
241  private:
242  IntSet is0;
243  IntSet is1;
244  Gecode::SetOpType sot;
245  Gecode::SetRelType srt;
246  bool inverse;
247 
248  template<class I, class J>
249  bool
250  sol(I& i, J& j) const {
251  switch (srt) {
252  case SRT_EQ: return Iter::Ranges::equal(i,j);
253  case SRT_NQ: return !Iter::Ranges::equal(i,j);
254  case SRT_SUB: return Iter::Ranges::subset(i,j);
255  case SRT_SUP: return Iter::Ranges::subset(j,i);
256  case SRT_DISJ:
257  {
259  return !inter();
260  }
261  case SRT_CMPL:
262  {
264  return Iter::Ranges::equal(i,jc);
265  }
266  default: GECODE_NEVER;
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  default: GECODE_NEVER;
326  }
327  GECODE_NEVER;
328  return false;
329  }
331  void post(Space& home, SetVarArray& x, IntVarArray&) {
332  if (!inverse)
333  Gecode::rel(home, is0, sot, x[0], srt, is1);
334  else
335  Gecode::rel(home, x[0], sot, is0, srt, is1);
336  }
337  };
338 
340  class Create {
341  public:
343  Create(void) {
344  using namespace Gecode;
345  for (SetRelTypes srts; srts(); ++srts) {
346  for (SetOpTypes sots; sots(); ++sots) {
347  for (int i=0; i<=2; i++) {
348  (void) new RelSIS(sots.sot(),srts.srt(),i,false);
349  (void) new RelSIS(sots.sot(),srts.srt(),i,true);
350  (void) new RelSSI(sots.sot(),srts.srt(),i);
351  (void) new RelISI(sots.sot(),srts.srt(),i,0,false);
352  (void) new RelISI(sots.sot(),srts.srt(),i,1,false);
353  (void) new RelISI(sots.sot(),srts.srt(),i,2,false);
354  (void) new RelISI(sots.sot(),srts.srt(),i,0,true);
355  (void) new RelISI(sots.sot(),srts.srt(),i,1,true);
356  (void) new RelISI(sots.sot(),srts.srt(),i,2,true);
357  }
358  }
359  }
360  }
361  };
362 
364 
366 
367 }}}
368 
369 // STATISTICS: test-set
Post propagator for SetVar x
Definition: set.hh:767
bool solution(const SetAssignment &x) const
Test whether x is solution
bool solution(const SetAssignment &x) const
Test whether x is solution
RelISI(Gecode::SetOpType sot0, Gecode::SetRelType srt0, int intSet0, int intSet1, bool inverse0)
Create and register test.
Computation spaces.
Definition: core.hpp:1742
SetOpType
Common operations for sets.
Definition: set.hh:660
@ SRT_SUB
Subset ( )
Definition: set.hh:646
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
Integer variable array.
Definition: int.hh:763
void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
@ SRT_SUP
Superset ( )
Definition: set.hh:647
Range iterator for integer sets.
Definition: int.hh:292
Create c
Generate all set assignments.
Definition: set.hh:142
@ SOT_INTER
Intersection
Definition: set.hh:663
@ SRT_DISJ
Disjoint ( )
Definition: set.hh:648
void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Gecode toplevel namespace
union Gecode::@602::NNF::@65 u
Union depending on nodetype t.
Integer sets.
Definition: int.hh:174
A complement iterator spezialized for the BndSet limits.
Definition: var-imp.hpp:293
@ SRT_EQ
Equality ( )
Definition: set.hh:644
Range iterator for computing intersection (binary)
RelSSI(Gecode::SetOpType sot0, Gecode::SetRelType srt0, int intSet)
Create and register test.
@ SOT_UNION
Union.
Definition: set.hh:661
Range iterator for computing set difference.
Definition: ranges-diff.hpp:43
bool solution(const SetAssignment &x) const
Test whether x is solution
Base class for tests with set constraints
Definition: set.hh:273
bool equal(I &i, J &j)
Check whether range iterators i and j are equal.
SetRelType
Common relation types for sets.
Definition: set.hh:643
Iterator for Boolean operation types.
Definition: set.hh:352
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56
@ SRT_NQ
Disequality ( )
Definition: set.hh:645
Iterator for set relation types.
Definition: set.hh:334
Create(void)
Perform creation and registration.
Range iterator for computing union (binary)
Test for set relation constraint with constants
@ SRT_CMPL
Complement.
Definition: set.hh:649
@ SOT_DUNION
Disjoint union.
Definition: set.hh:662
Test for set relation constraint with constants
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.
General test support.
Definition: afc.cpp:39
Range iterator producing subsets of an IntSet.
Definition: set.hh:99
Test for set relation constraint with constants
Help class to create and register tests.
Set variable array
Definition: set.hh:570
@ SOT_MINUS
Difference.
Definition: set.hh:664
RelSIS(Gecode::SetOpType sot0, Gecode::SetRelType srt0, int intSet, bool inverse0)
Create and register test.
Gecode::IntArgs i({1, 2, 3, 4})
SetExpr inter(const SetVarArgs &x)
Intersection of set variables.
Definition: set-expr.cpp:696