Generated on Sat Jan 20 2018 22:21:12 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  * Contributing authors:
7  * Gabor Szokoli <szokoli@gecode.org>
8  *
9  * Copyright:
10  * Guido Tack, 2004, 2005
11  *
12  * Last modified:
13  * $Date: 2017-03-10 10:15:56 +0100 (Fri, 10 Mar 2017) $ by $Author: schulte $
14  * $Revision: 15566 $
15  *
16  * This file is part of Gecode, the generic constraint
17  * development environment:
18  * http://www.gecode.org
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  *
39  */
40 
41 #include <gecode/set/rel.hh>
42 #include <gecode/set/rel-op.hh>
43 #include <gecode/set/int.hh>
44 
45 namespace Gecode { namespace Set {
46 
47  template<class View0, class View1>
48  void
49  rel_post(Home home, View0 x0, SetRelType r, View1 x1) {
50  using namespace Set::Rel;
51  using namespace Set::RelOp;
53  switch (r) {
54  case SRT_EQ:
56  break;
57  case SRT_NQ:
59  break;
60  case SRT_SUB:
62  break;
63  case SRT_SUP:
65  break;
66  case SRT_DISJ:
67  {
68  EmptyView emptyset;
70  ::post(home, x0, x1, emptyset)));
71  }
72  break;
73  case SRT_CMPL:
74  {
75  ComplementView<View0> cx0(x0);
77  ::post(home, cx0, x1)));
78  }
79  break;
80  case SRT_LQ:
82  break;
83  case SRT_LE:
85  break;
86  case SRT_GQ:
88  break;
89  case SRT_GR:
91  break;
92  default:
93  throw UnknownRelation("Set::rel");
94  }
95  }
96 
97  template<class View0, class View1, ReifyMode rm>
98  void
99  rel_re(Home home, View0 x, SetRelType r, View1 y, BoolVar b) {
100  using namespace Set::Rel;
101  using namespace Set::RelOp;
102  GECODE_POST;
103  switch (r) {
104  case SRT_EQ:
106  ::post(home, x,y,b)));
107  break;
108  case SRT_NQ:
109  {
110  Gecode::Int::NegBoolView notb(b);
111  switch (rm) {
112  case RM_EQV:
114  ::post(home,x,y,notb)));
115  break;
116  case RM_IMP:
118  ::post(home,x,y,notb)));
119  break;
120  case RM_PMI:
122  ::post(home,x,y,notb)));
123  break;
124  default: throw Gecode::Int::UnknownReifyMode("Set::rel");
125  }
126  }
127  break;
128  case SRT_SUB:
130  break;
131  case SRT_SUP:
133  break;
134  case SRT_DISJ:
135  {
136  // x||y <=> b is equivalent to
137  // ( y <= complement(x) ) <=> b
138 
139  ComplementView<View0> xc(x);
142  ::post(home, y, xc, b)));
143  }
144  break;
145  case SRT_CMPL:
146  {
147  ComplementView<View0> xc(x);
150  ::post(home, xc, y, b)));
151  }
152  break;
153  case SRT_LQ:
155  break;
156  case SRT_LE:
158  break;
159  case SRT_GQ:
161  break;
162  case SRT_GR:
164  break;
165  default:
166  throw UnknownRelation("Set::rel");
167  }
168  }
169 
170 }}
171 
172 namespace Gecode {
173 
174  void
176  using namespace Set;
177  rel_post<SetView,SetView>(home,x,r,y);
178  }
179 
180  void
182  using namespace Set;
183  Gecode::Int::IntView xv(x);
184  SingletonView xsingle(xv);
185  rel_post<SetView,SingletonView>(home,s,r,xv);
186  }
187 
188  void
190  using namespace Set;
191  switch (r) {
192  case SRT_SUB:
193  rel(home, s, SRT_SUP, x);
194  break;
195  case SRT_SUP:
196  rel(home, s, SRT_SUB, x);
197  break;
198  default:
199  rel(home, s, r, x);
200  }
201  }
202 
203  void
205  using namespace Set;
206  switch (r.mode()) {
207  case RM_EQV:
208  rel_re<SetView,SetView,RM_EQV>(home,x,rt,y,r.var());
209  break;
210  case RM_IMP:
211  rel_re<SetView,SetView,RM_IMP>(home,x,rt,y,r.var());
212  break;
213  case RM_PMI:
214  rel_re<SetView,SetView,RM_PMI>(home,x,rt,y,r.var());
215  break;
216  default: throw Gecode::Int::UnknownReifyMode("Set::rel");
217  }
218  }
219 
220  void
221  rel(Home home, SetVar s, SetRelType rt, IntVar x, Reify r) {
222  using namespace Set;
223  Gecode::Int::IntView xv(x);
224  SingletonView xsingle(xv);
225  switch (r.mode()) {
226  case RM_EQV:
227  rel_re<SetView,SingletonView,RM_EQV>(home,s,rt,xsingle,r.var());
228  break;
229  case RM_IMP:
230  rel_re<SetView,SingletonView,RM_IMP>(home,s,rt,xsingle,r.var());
231  break;
232  case RM_PMI:
233  rel_re<SetView,SingletonView,RM_PMI>(home,s,rt,xsingle,r.var());
234  break;
235  default: throw Gecode::Int::UnknownReifyMode("Set::rel");
236  }
237  }
238 
239  void
240  rel(Home home, IntVar x, SetRelType rt, SetVar s, Reify r) {
241  using namespace Set;
242  switch (rt) {
243  case SRT_SUB:
244  rel(home, s, SRT_SUP, x, r);
245  break;
246  case SRT_SUP:
247  rel(home, s, SRT_SUB, x, r);
248  break;
249  default:
250  rel(home, s, rt, x, r);
251  }
252  }
253 
254 }
255 
256 // STATISTICS: set-post
Propagator for negated equality
Definition: rel.hh:267
SetRelType
Common relation types for sets.
Definition: set.hh:645
Inverse implication for reification.
Definition: int.hh:850
ReifyMode mode(void) const
Return reification mode.
Definition: reify.hpp:60
Negated Boolean view.
Definition: view.hpp:1503
Propagator for the subset constraint
Definition: rel.hh:64
Propagator for set less than or equal
Definition: rel.hh:208
Superset ( )
Definition: set.hh:649
Complement.
Definition: set.hh:651
Exception: Unknown relation passed as argument
Definition: exception.hpp:91
Reified equality propagator
Definition: rel.hh:174
Less or equal ( )
Definition: set.hh:652
Reification specification.
Definition: int.hh:857
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
Subset ( )
Definition: set.hh:648
Less ( )
Definition: set.hh:653
Reified propagator for set less than or equal
Definition: rel.hh:234
Singleton set view.
Definition: view.hpp:589
Boolean integer variables.
Definition: int.hh:494
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:784
Integer view for integer variables.
Definition: view.hpp:129
Greater or equal ( )
Definition: set.hh:654
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:784
Reified subset propagator
Definition: rel.hh:115
Set variables
Definition: set.hh:131
Integer variables.
Definition: int.hh:353
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:47
Propagator for the superset of intersection
Definition: rel-op.hh:65
BoolVar var(void) const
Return Boolean control variable.
Definition: reify.hpp:52
Propagator for set equality
Definition: rel.hh:150
Greater ( )
Definition: set.hh:655
Equality ( )
Definition: set.hh:646
Disjoint ( )
Definition: set.hh:650
Post propagator for SetVar x
Definition: set.hh:784
Disequality ( )
Definition: set.hh:647
Complement set view.
Definition: view.hpp:756
Exception: Unknown reification mode passed as argument
Definition: exception.hpp:119
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:843
Constant view for the empty set.
Definition: view.hpp:335
#define GECODE_POST
Check for failure in a constraint post function.
Definition: macros.hpp:44
Home class for posting propagators
Definition: core.hpp:922
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:107
void rel_post(Home home, View0 x0, SetRelType r, View1 x1)
Definition: rel.cpp:49
void rel_re(Home home, View0 x, SetRelType r, View1 y, BoolVar b)
Definition: rel.cpp:99
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Equivalence for reification (default)
Definition: int.hh:836
Boolean view for Boolean variables.
Definition: view.hpp:1315