Generated on Wed Jan 24 2018 21:22:26 for Gecode by doxygen 1.8.13
rel.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: 2016-12-02 13:20:09 +0100 (Fri, 02 Dec 2016) $ by $Author: schulte $
11  * $Revision: 15304 $
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 <gecode/minimodel.hh>
39 
40 #include "test/set.hh"
41 
42 using namespace Gecode;
43 
44 namespace Test { namespace Set {
45 
47  namespace Rel {
48 
54 
55  static IntSet ds_33(-3,3);
56  static IntSet ds_03(0,3);
57 
59  class RelBin : public SetTest {
60  private:
62  bool shared;
63  public:
65  RelBin(Gecode::SetRelType srt0, bool shared0)
66  : SetTest("Rel::Bin::"+str(srt0)+"::S"+(shared0 ? "1":"0"),
67  shared0 ? 1 : 2,ds_33,true)
68  , srt(srt0), shared(shared0){}
69  int minSymDiff(const SetAssignment& x) const {
70  int x1 = shared ? x[0] : x[1];
72  CountableSetRanges xr00(x.lub, x[0]);
73  CountableSetRanges xr10(x.lub, x1);
74  Diff a(xr00,xr10);
75  CountableSetRanges xr01(x.lub, x[0]);
76  CountableSetRanges xr11(x.lub, x1);
77  Diff b(xr11,xr01);
79  return u() ? u.min() : Gecode::Set::Limits::max+1;
80  }
81  bool in(int i, CountableSetRanges& c, bool eq=false) const {
82  if (eq && i==Gecode::Set::Limits::max+1)
83  return true;
85  return Iter::Ranges::subset(s,c);
86  }
88  bool solution(const SetAssignment& x) const {
89  int x1 = shared ? x[0] : x[1];
90  CountableSetRanges xr0(x.lub, x[0]);
91  CountableSetRanges xr1(x.lub, x1);
92  switch (srt) {
93  case SRT_EQ: return Iter::Ranges::equal(xr0, xr1);
94  case SRT_NQ: return !Iter::Ranges::equal(xr0, xr1);
95 
96  case SRT_LQ: return (!xr0()) || in(minSymDiff(x),xr1,true);
97  case SRT_LE: return xr0() ? in(minSymDiff(x),xr1) : xr1();
98  case SRT_GQ: return (!xr1()) || in(minSymDiff(x),xr0,true);
99  case SRT_GR: return xr1() ? in(minSymDiff(x),xr0) : xr0();
100 
101  case SRT_SUB: return Iter::Ranges::subset(xr0, xr1);
102  case SRT_SUP: return Iter::Ranges::subset(xr1, xr0);
103  case SRT_DISJ:
104  {
106  inter(xr0,xr1);
107  return !inter();
108  }
109  case SRT_CMPL:
110  {
112  return Iter::Ranges::equal(rc,xr1);
113  }
114  default:
115  GECODE_NEVER;
116  }
117  GECODE_NEVER;
118  return false;
119  }
121  void post(Space& home, SetVarArray& x, IntVarArray&) {
122  if (!shared)
123  Gecode::rel(home, x[0], srt, x[1]);
124  else
125  Gecode::rel(home, x[0], srt, x[0]);
126  }
128  void post(Space& home, SetVarArray& x, IntVarArray&, Reify r) {
129  if (!shared)
130  Gecode::rel(home, x[0], srt, x[1], r);
131  else
132  Gecode::rel(home, x[0], srt, x[0], r);
133  }
134  };
135 
137  class ITE : public SetTest {
138  public:
140  ITE(void)
141  : SetTest("ITE",3,ds_03,false,1) {}
143  virtual bool solution(const SetAssignment& x) const {
144  if ((x.intval() < 0) || (x.intval() > 1))
145  return false;
146  if (x.intval() == 1) {
147  CountableSetRanges xr0(x.lub, x[0]);
148  CountableSetRanges xr2(x.lub, x[2]);
149  return Iter::Ranges::equal(xr0,xr2);
150  } else {
151  CountableSetRanges xr1(x.lub, x[1]);
152  CountableSetRanges xr2(x.lub, x[2]);
153  return Iter::Ranges::equal(xr1,xr2);
154  }
155  }
157  void post(Space& home, SetVarArray& x, IntVarArray& y) {
158  Gecode::ite(home, Gecode::channel(home,y[0]), x[0], x[1], x[2]);
159  }
160  };
161 
182 
185 
186 }}}
187 
188 // STATISTICS: test-set
ITE(void)
Construct and register test.
Definition: rel.cpp:140
RelBin _relbin_shared_le(Gecode::SRT_LE, true)
SetRelType
Common relation types for sets.
Definition: set.hh:645
union Gecode::@579::NNF::@61 u
Union depending on nodetype t.
Range iterator for singleton range.
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition: channel.cpp:45
RelBin _relbin_le(Gecode::SRT_LE, false)
RelBin _relbin_nq(Gecode::SRT_NQ, false)
bool equal(I &i, J &j)
Check whether range iterators i and j are equal.
RelBin(Gecode::SetRelType srt0, bool shared0)
Create and register test.
Definition: rel.cpp:65
Integer variable array.
Definition: int.hh:744
RelBin _relbin_sup(Gecode::SRT_SUP, false)
Superset ( )
Definition: set.hh:649
RelBin _relbin_gr(Gecode::SRT_GR, false)
Complement.
Definition: set.hh:651
const int max
Largest allowed integer in integer set.
Definition: set.hh:101
RelBin _relbin_shared_sub(Gecode::SRT_SUB, true)
Computation spaces.
Definition: core.hpp:1748
RelBin _relbin_sub(Gecode::SRT_SUB, false)
RelBin _relbin_lq(Gecode::SRT_LQ, false)
RelBin _relbin_cmpl(Gecode::SRT_CMPL, false)
Test for binary set relation constraint
Definition: rel.cpp:59
void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition: rel.cpp:121
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
bool in(int i, CountableSetRanges &c, bool eq=false) const
Definition: rel.cpp:81
Gecode::IntArgs i(4, 1, 2, 3, 4)
RelBin _relbin_shared_cmpl(Gecode::SRT_CMPL, true)
Range iterator for computing intersection (binary)
RelBin _relbin_shared_disj(Gecode::SRT_DISJ, true)
Less or equal ( )
Definition: set.hh:652
A complement iterator spezialized for the BndSet limits.
Definition: var-imp.hpp:296
void post(Space &home, SetVarArray &x, IntVarArray &, Reify r)
Post reified constraint on x for b.
Definition: rel.cpp:128
virtual bool solution(const SetAssignment &x) const
Check whether x is a solution.
Definition: rel.cpp:143
Reification specification.
Definition: int.hh:857
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
RelBin _relbin_shared_lq(Gecode::SRT_LQ, true)
Subset ( )
Definition: set.hh:648
Gecode::IntSet lub
The common superset for all domains.
Definition: set.hh:170
Integer sets.
Definition: int.hh:174
Less ( )
Definition: set.hh:653
RelBin _relbin_shared_eq(Gecode::SRT_EQ, true)
RelBin _relbin_shared_sup(Gecode::SRT_SUP, true)
Range iterator for computing union (binary)
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:784
SetExpr inter(const SetVarArgs &x)
Intersection of set variables.
Definition: set-expr.cpp:699
Create c
Definition: rel.cpp:625
General test support.
Definition: afc.cpp:43
Greater or equal ( )
Definition: set.hh:654
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:784
Test for if-then-else-constraint
Definition: rel.cpp:137
RelBin _relbin_eq(Gecode::SRT_EQ, false)
Base class for tests with set constraints
Definition: set.hh:289
Generate all set assignments.
Definition: set.hh:158
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:47
int minSymDiff(const SetAssignment &x) const
Definition: rel.cpp:69
Range iterator producing subsets of an IntSet.
Definition: set.hh:114
Greater ( )
Definition: set.hh:655
Equality ( )
Definition: set.hh:646
Disjoint ( )
Definition: set.hh:650
RelBin _relbin_shared_gr(Gecode::SRT_GR, true)
Post propagator for SetVar x
Definition: set.hh:784
RelBin _relbin_shared_nq(Gecode::SRT_NQ, true)
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:702
Set variable array
Definition: set.hh:572
RelBin _relbin_shared_gq(Gecode::SRT_GQ, true)
Disequality ( )
Definition: set.hh:647
bool solution(const SetAssignment &x) const
Test whether x is solution
Definition: rel.cpp:88
Gecode toplevel namespace
Range iterator for computing set difference.
Definition: ranges-diff.hpp:47
RelBin _relbin_disj(Gecode::SRT_DISJ, false)
int min(void) const
Return smallest value of range.
void post(Space &home, SetVarArray &x, IntVarArray &y)
Post constraint on x and y.
Definition: rel.cpp:157
RelBin _relbin_gq(Gecode::SRT_GQ, false)
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
int intval(void) const
Return value for first integer variable.
Definition: set.hh:185
void ite(Home home, BoolVar b, FloatVar x, FloatVar y, FloatVar z)
Post propagator for if-then-else constraint.
Definition: bool.cpp:43