Generated on Thu Mar 16 2017 03:24:16 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: 2016-10-23 14:09:24 +0200 (Sun, 23 Oct 2016) $ by $Author: schulte $
14  * $Revision: 15218 $
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);
141  ::post(home, y, xc, b)));
142  }
143  break;
144  case SRT_CMPL:
145  {
146  ComplementView<View0> xc(x);
149  ::post(home, xc, y, b)));
150  }
151  break;
152  case SRT_LQ:
154  break;
155  case SRT_LE:
157  break;
158  case SRT_GQ:
160  break;
161  case SRT_GR:
163  break;
164  default:
165  throw UnknownRelation("Set::rel");
166  }
167  }
168 
169 }}
170 
171 namespace Gecode {
172 
173  void
175  using namespace Set;
176  rel_post<SetView,SetView>(home,x,r,y);
177  }
178 
179  void
181  using namespace Set;
182  Gecode::Int::IntView xv(x);
183  SingletonView xsingle(xv);
184  rel_post<SetView,SingletonView>(home,s,r,xv);
185  }
186 
187  void
189  using namespace Set;
190  switch (r) {
191  case SRT_SUB:
192  rel(home, s, SRT_SUP, x);
193  break;
194  case SRT_SUP:
195  rel(home, s, SRT_SUB, x);
196  break;
197  default:
198  rel(home, s, r, x);
199  }
200  }
201 
202  void
203  rel(Home home, SetVar x, SetRelType rt, SetVar y, Reify r) {
204  using namespace Set;
205  switch (r.mode()) {
206  case RM_EQV:
207  rel_re<SetView,SetView,RM_EQV>(home,x,rt,y,r.var());
208  break;
209  case RM_IMP:
210  rel_re<SetView,SetView,RM_IMP>(home,x,rt,y,r.var());
211  break;
212  case RM_PMI:
213  rel_re<SetView,SetView,RM_PMI>(home,x,rt,y,r.var());
214  break;
215  default: throw Gecode::Int::UnknownReifyMode("Set::rel");
216  }
217  }
218 
219  void
220  rel(Home home, SetVar s, SetRelType rt, IntVar x, Reify r) {
221  using namespace Set;
222  Gecode::Int::IntView xv(x);
223  SingletonView xsingle(xv);
224  switch (r.mode()) {
225  case RM_EQV:
226  rel_re<SetView,SingletonView,RM_EQV>(home,s,rt,xsingle,r.var());
227  break;
228  case RM_IMP:
229  rel_re<SetView,SingletonView,RM_IMP>(home,s,rt,xsingle,r.var());
230  break;
231  case RM_PMI:
232  rel_re<SetView,SingletonView,RM_PMI>(home,s,rt,xsingle,r.var());
233  break;
234  default: throw Gecode::Int::UnknownReifyMode("Set::rel");
235  }
236  }
237 
238  void
239  rel(Home home, IntVar x, SetRelType rt, SetVar s, Reify r) {
240  using namespace Set;
241  switch (rt) {
242  case SRT_SUB:
243  rel(home, s, SRT_SUP, x, r);
244  break;
245  case SRT_SUP:
246  rel(home, s, SRT_SUB, x, r);
247  break;
248  default:
249  rel(home, s, rt, x, r);
250  }
251  }
252 
253 }
254 
255 // STATISTICS: set-post
Propagator for negated equality
Definition: rel.hh:267
SetRelType
Common relation types for sets.
Definition: set.hh:643
Inverse implication for reification.
Definition: int.hh:848
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:647
Complement.
Definition: set.hh:649
Exception: Unknown relation passed as argument
Definition: exception.hpp:91
Reified equality propagator
Definition: rel.hh:174
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
Less or equal ( )
Definition: set.hh:650
Reification specification.
Definition: int.hh:855
Subset ( )
Definition: set.hh:646
Less ( )
Definition: set.hh:651
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:492
Integer view for integer variables.
Definition: view.hpp:129
Greater or equal ( )
Definition: set.hh:652
Reified subset propagator
Definition: rel.hh:115
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Set variables
Definition: set.hh:129
Integer variables.
Definition: int.hh:351
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:653
Equality ( )
Definition: set.hh:644
Disjoint ( )
Definition: set.hh:648
Disequality ( )
Definition: set.hh:645
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:841
struct Gecode::@554::NNF::@60::@61 b
For binary nodes (and, or, eqv)
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:905
#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:834
Boolean view for Boolean variables.
Definition: view.hpp:1315