Generated on Mon Feb 8 2021 00:00:00 for Gecode by doxygen 1.8.20
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  * This file is part of Gecode, the generic constraint
13  * development environment:
14  * http://www.gecode.org
15  *
16  * Permission is hereby granted, free of charge, to any person obtaining
17  * a copy of this software and associated documentation files (the
18  * "Software"), to deal in the Software without restriction, including
19  * without limitation the rights to use, copy, modify, merge, publish,
20  * distribute, sublicense, and/or sell copies of the Software, and to
21  * permit persons to whom the Software is furnished to do so, subject to
22  * the following conditions:
23  *
24  * The above copyright notice and this permission notice shall be
25  * included in all copies or substantial portions of the Software.
26  *
27  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34  *
35  */
36 
37 #include <gecode/set/rel.hh>
38 #include <gecode/set/rel-op.hh>
39 #include <gecode/set/int.hh>
40 
41 namespace Gecode { namespace Set {
42 
43  template<class View0, class View1>
44  forceinline void
45  rel_post(Home home, View0 x0, SetRelType r, View1 x1) {
46  using namespace Set::Rel;
47  using namespace Set::RelOp;
49  switch (r) {
50  case SRT_EQ:
52  break;
53  case SRT_NQ:
55  break;
56  case SRT_SUB:
58  break;
59  case SRT_SUP:
61  break;
62  case SRT_DISJ:
63  {
64  EmptyView emptyset;
66  ::post(home, x0, x1, emptyset)));
67  }
68  break;
69  case SRT_CMPL:
70  {
71  ComplementView<View0> cx0(x0);
73  ::post(home, cx0, x1)));
74  }
75  break;
76  case SRT_LQ:
78  break;
79  case SRT_LE:
81  break;
82  case SRT_GQ:
84  break;
85  case SRT_GR:
87  break;
88  default:
89  throw UnknownRelation("Set::rel");
90  }
91  }
92 
93  template<class View0, class View1, ReifyMode rm>
94  forceinline void
95  rel_re(Home home, View0 x, SetRelType r, View1 y, BoolVar b) {
96  using namespace Set::Rel;
97  using namespace Set::RelOp;
99  switch (r) {
100  case SRT_EQ:
102  ::post(home, x,y,b)));
103  break;
104  case SRT_NQ:
105  {
107  switch (rm) {
108  case RM_EQV:
110  ::post(home,x,y,notb)));
111  break;
112  case RM_IMP:
114  ::post(home,x,y,notb)));
115  break;
116  case RM_PMI:
118  ::post(home,x,y,notb)));
119  break;
120  default: throw Gecode::Int::UnknownReifyMode("Set::rel");
121  }
122  }
123  break;
124  case SRT_SUB:
126  break;
127  case SRT_SUP:
129  break;
130  case SRT_DISJ:
131  {
132  // x||y <=> b is equivalent to
133  // ( y <= complement(x) ) <=> b
134 
138  ::post(home, y, xc, b)));
139  }
140  break;
141  case SRT_CMPL:
142  {
146  ::post(home, xc, y, b)));
147  }
148  break;
149  case SRT_LQ:
151  break;
152  case SRT_LE:
154  break;
155  case SRT_GQ:
157  break;
158  case SRT_GR:
160  break;
161  default:
162  throw UnknownRelation("Set::rel");
163  }
164  }
165 
166 }}
167 
168 namespace Gecode {
169 
170  void
172  using namespace Set;
173  rel_post<SetView,SetView>(home,x,r,y);
174  }
175 
176  void
178  using namespace Set;
180  SingletonView xsingle(xv);
181  rel_post<SetView,SingletonView>(home,s,r,xv);
182  }
183 
184  void
186  using namespace Set;
187  switch (r) {
188  case SRT_SUB:
189  rel(home, s, SRT_SUP, x);
190  break;
191  case SRT_SUP:
192  rel(home, s, SRT_SUB, x);
193  break;
194  default:
195  rel(home, s, r, x);
196  }
197  }
198 
199  void
201  using namespace Set;
202  switch (r.mode()) {
203  case RM_EQV:
204  rel_re<SetView,SetView,RM_EQV>(home,x,rt,y,r.var());
205  break;
206  case RM_IMP:
207  rel_re<SetView,SetView,RM_IMP>(home,x,rt,y,r.var());
208  break;
209  case RM_PMI:
210  rel_re<SetView,SetView,RM_PMI>(home,x,rt,y,r.var());
211  break;
212  default: throw Gecode::Int::UnknownReifyMode("Set::rel");
213  }
214  }
215 
216  void
217  rel(Home home, SetVar s, SetRelType rt, IntVar x, Reify r) {
218  using namespace Set;
220  SingletonView xsingle(xv);
221  switch (r.mode()) {
222  case RM_EQV:
223  rel_re<SetView,SingletonView,RM_EQV>(home,s,rt,xsingle,r.var());
224  break;
225  case RM_IMP:
226  rel_re<SetView,SingletonView,RM_IMP>(home,s,rt,xsingle,r.var());
227  break;
228  case RM_PMI:
229  rel_re<SetView,SingletonView,RM_PMI>(home,s,rt,xsingle,r.var());
230  break;
231  default: throw Gecode::Int::UnknownReifyMode("Set::rel");
232  }
233  }
234 
235  void
236  rel(Home home, IntVar x, SetRelType rt, SetVar s, Reify r) {
237  using namespace Set;
238  switch (rt) {
239  case SRT_SUB:
240  rel(home, s, SRT_SUP, x, r);
241  break;
242  case SRT_SUP:
243  rel(home, s, SRT_SUB, x, r);
244  break;
245  default:
246  rel(home, s, rt, x, r);
247  }
248  }
249 
250 }
251 
252 // STATISTICS: set-post
Exception: Unknown reification mode passed as argument
Definition: exception.hpp:115
Negated Boolean view.
Definition: view.hpp:1574
Post propagator for SetVar x
Definition: set.hh:767
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
@ RM_PMI
Inverse implication for reification.
Definition: int.hh:869
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:103
Singleton set view.
Definition: view.hpp:594
@ RM_IMP
Implication for reification.
Definition: int.hh:862
Propagator for set equality
Definition: rel.hh:150
@ SRT_LQ
Less or equal ( )
Definition: set.hh:650
@ SRT_GQ
Greater or equal ( )
Definition: set.hh:652
@ SRT_SUB
Subset ( )
Definition: set.hh:646
Propagator for the subset constraint
Definition: rel.hh:65
@ SRT_SUP
Superset ( )
Definition: set.hh:647
@ SRT_DISJ
Disjoint ( )
Definition: set.hh:648
Boolean view for Boolean variables.
Definition: view.hpp:1380
Gecode toplevel namespace
@ SRT_EQ
Equality ( )
Definition: set.hh:644
Reification specification.
Definition: int.hh:876
Constant view for the empty set.
Definition: view.hpp:336
@ RM_EQV
Equivalence for reification (default)
Definition: int.hh:855
Home class for posting propagators
Definition: core.hpp:856
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
Boolean integer variables.
Definition: int.hh:512
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition: filter.cpp:138
Set variables
Definition: set.hh:127
Reified equality propagator
Definition: rel.hh:174
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
Integer variables.
Definition: int.hh:371
SetRelType
Common relation types for sets.
Definition: set.hh:643
@ SRT_LE
Less ( )
Definition: set.hh:651
@ SRT_GR
Greater ( )
Definition: set.hh:653
@ SRT_NQ
Disequality ( )
Definition: set.hh:645
@ SRT_CMPL
Complement.
Definition: set.hh:649
void rel_post(Home home, View0 x0, SetRelType r, View1 x1)
Definition: rel.cpp:45
void rel_re(Home home, View0 x, SetRelType r, View1 y, BoolVar b)
Definition: rel.cpp:95
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:43
Propagator for negated equality
Definition: rel.hh:268
Reified propagator for set less than or equal
Definition: rel.hh:234
#define GECODE_POST
Check for failure in a constraint post function.
Definition: macros.hpp:40
Integer view for integer variables.
Definition: view.hpp:129
#define forceinline
Definition: config.hpp:192
Propagator for the superset of intersection
Definition: rel-op.hh:63
Exception: Unknown relation passed as argument
Definition: exception.hpp:87
Complement set view.
Definition: view.hpp:769
Propagator for set less than or equal
Definition: rel.hh:208
Reified subset propagator
Definition: rel.hh:115