Generated on Sat Feb 7 2015 02:01:16 for Gecode by doxygen 1.8.9.1
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: 2013-02-27 17:15:18 +0100 (Wed, 27 Feb 2013) $ by $Author: schulte $
14  * $Revision: 13426 $
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 {
46  using namespace Set;
47  using namespace Set::Rel;
48  using namespace Set::RelOp;
49 
50  template<class View0, class View1>
51  void
52  rel_post(Home home, View0 x0, SetRelType r, View1 x1) {
53  if (home.failed()) return;
54  switch (r) {
55  case SRT_EQ:
57  break;
58  case SRT_NQ:
60  break;
61  case SRT_SUB:
63  break;
64  case SRT_SUP:
66  break;
67  case SRT_DISJ:
68  {
69  EmptyView emptyset;
71  ::post(home, x0, x1, emptyset)));
72  }
73  break;
74  case SRT_CMPL:
75  {
76  ComplementView<View0> cx0(x0);
78  ::post(home, cx0, x1)));
79  }
80  break;
81  case SRT_LQ:
83  break;
84  case SRT_LE:
86  break;
87  case SRT_GQ:
89  break;
90  case SRT_GR:
92  break;
93  default:
94  throw UnknownRelation("Set::rel");
95  }
96  }
97 
98  template<class View0, class View1, ReifyMode rm>
99  void
100  rel_re(Home home, View0 x, SetRelType r, View1 y, BoolVar b) {
101  if (home.failed()) return;
102  switch (r) {
103  case SRT_EQ:
105  ::post(home, x,y,b)));
106  break;
107  case SRT_NQ:
108  {
109  Gecode::Int::NegBoolView notb(b);
110  switch (rm) {
111  case RM_EQV:
113  ::post(home,x,y,notb)));
114  break;
115  case RM_IMP:
117  ::post(home,x,y,notb)));
118  break;
119  case RM_PMI:
121  ::post(home,x,y,notb)));
122  break;
123  default: throw Gecode::Int::UnknownReifyMode("Set::rel");
124  }
125  }
126  break;
127  case SRT_SUB:
129  break;
130  case SRT_SUP:
132  break;
133  case SRT_DISJ:
134  {
135  // x||y <=> b is equivalent to
136  // ( y <= complement(x) ) <=> b
137 
138  ComplementView<View0> xc(x);
140  ::post(home, y, xc, b)));
141  }
142  break;
143  case SRT_CMPL:
144  {
145  ComplementView<View0> xc(x);
148  ::post(home, xc, y, b)));
149  }
150  break;
151  case SRT_LQ:
153  break;
154  case SRT_LE:
156  break;
157  case SRT_GQ:
159  break;
160  case SRT_GR:
162  break;
163  default:
164  throw UnknownRelation("Set::rel");
165  }
166  }
167 
168  void
170  rel_post<SetView,SetView>(home,x,r,y);
171  }
172 
173  void
175  Gecode::Int::IntView xv(x);
176  SingletonView xsingle(xv);
177  rel_post<SetView,SingletonView>(home,s,r,xv);
178  }
179 
180  void
182  switch (r) {
183  case SRT_SUB:
184  rel(home, s, SRT_SUP, x);
185  break;
186  case SRT_SUP:
187  rel(home, s, SRT_SUB, x);
188  break;
189  default:
190  rel(home, s, r, x);
191  }
192  }
193 
194  void
195  rel(Home home, SetVar x, SetRelType rt, SetVar y, Reify r) {
196  switch (r.mode()) {
197  case RM_EQV:
198  rel_re<SetView,SetView,RM_EQV>(home,x,rt,y,r.var());
199  break;
200  case RM_IMP:
201  rel_re<SetView,SetView,RM_IMP>(home,x,rt,y,r.var());
202  break;
203  case RM_PMI:
204  rel_re<SetView,SetView,RM_PMI>(home,x,rt,y,r.var());
205  break;
206  default: throw Gecode::Int::UnknownReifyMode("Set::rel");
207  }
208  }
209 
210  void
211  rel(Home home, SetVar s, SetRelType rt, IntVar x, Reify r) {
212  Gecode::Int::IntView xv(x);
213  SingletonView xsingle(xv);
214  switch (r.mode()) {
215  case RM_EQV:
216  rel_re<SetView,SingletonView,RM_EQV>(home,s,rt,xsingle,r.var());
217  break;
218  case RM_IMP:
219  rel_re<SetView,SingletonView,RM_IMP>(home,s,rt,xsingle,r.var());
220  break;
221  case RM_PMI:
222  rel_re<SetView,SingletonView,RM_PMI>(home,s,rt,xsingle,r.var());
223  break;
224  default: throw Gecode::Int::UnknownReifyMode("Set::rel");
225  }
226  }
227 
228  void
229  rel(Home home, IntVar x, SetRelType rt, SetVar s, Reify r) {
230  switch (rt) {
231  case SRT_SUB:
232  rel(home, s, SRT_SUP, x, r);
233  break;
234  case SRT_SUP:
235  rel(home, s, SRT_SUB, x, r);
236  break;
237  default:
238  rel(home, s, rt, x, r);
239  }
240  }
241 
242 }
243 
244 // STATISTICS: set-post
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3446
Propagator for negated equality
Definition: rel.hh:261
SetRelType
Common relation types for sets.
Definition: set.hh:644
Inverse implication for reification.
Definition: int.hh:847
ReifyMode mode(void) const
Return reification mode.
Definition: reify.hpp:60
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:228
BoolVar var(void) const
Return Boolean control variable.
Definition: reify.hpp:52
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:203
Superset ( )
Definition: set.hh:648
Complement.
Definition: set.hh:650
Exception: Unknown relation passed as argument
Definition: exception.hpp:91
Reified equality propagator
Definition: rel.hh:170
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
void rel_post(Home home, View0 x0, SetRelType r, View1 x1)
Definition: rel.cpp:52
Less or equal ( )
Definition: set.hh:651
Reification specification.
Definition: int.hh:854
Subset ( )
Definition: set.hh:647
Less ( )
Definition: set.hh:652
Reified propagator for set less than or equal
Definition: rel.hh:229
Singleton set view.
Definition: view.hpp:589
Boolean integer variables.
Definition: int.hh:491
Integer view for integer variables.
Definition: view.hpp:129
Greater or equal ( )
Definition: set.hh:653
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
void rel_re(Home home, View0 x, SetRelType r, View1 y, BoolVar b)
Definition: rel.cpp:100
Integer variables.
Definition: int.hh:350
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
Propagator for set equality
Definition: rel.hh:146
Greater ( )
Definition: set.hh:654
Equality ( )
Definition: set.hh:645
Disjoint ( )
Definition: set.hh:649
Disequality ( )
Definition: set.hh:646
Complement set view.
Definition: view.hpp:754
Exception: Unknown reification mode passed as argument
Definition: exception.hpp:119
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:840
Constant view for the empty set.
Definition: view.hpp:335
Home class for posting propagators
Definition: core.hpp:717
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:96
Equivalence for reification (default)
Definition: int.hh:833
Boolean view for Boolean variables.
Definition: view.hpp:1315