Generated on for Gecode by doxygen 1.18.0
post.hpp
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.dev>
5 *
6 * Contributing authors:
7 * Gabor Szokoli <szokoli@gecode.dev>
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.dev
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.hh>
38#include <gecode/set/rel.hh>
39#include <gecode/set/rel-op.hh>
40
41namespace Gecode { namespace Set { namespace RelOp {
42
43 template<class View0, class View1, class Res>
44 forceinline void
45 rel_eq(Home home, View0 x0, SetOpType op, View1 x1, Res x2) {
46 switch(op) {
47 case SOT_DUNION:
48 {
49 EmptyView emptyset;
51 ::post(home, x0, x1, emptyset)));
52 }
53 // fall through
54 case SOT_UNION:
55 {
58 ::post(home, x0, x1, x2)));
59 }
60 break;
61 case SOT_INTER:
62 {
64 ::post(home, x0,x1,x2)));
65 }
66 break;
67 case SOT_MINUS:
68 {
71 (Intersection<View0,
73 ::post(home,x0,cx1,x2)));
74 }
75 break;
76 }
77 }
78
79 template<class View0, class View1, class View2>
80 forceinline void
81 rel_sub(Home home, View0 x0, SetOpType op, View1 x1, View2 x2) {
82 switch(op) {
83 case SOT_DUNION:
84 {
85 EmptyView emptyset;
87 ::post(home, x0, x1, emptyset)));
88 }
89 // fall through
90 case SOT_UNION:
91 {
92 SetVar tmp(home);
95
98 ::post(home, x0, x1, tmp)));
99 }
100 break;
101 case SOT_INTER:
102 {
104 ::post(home, x0,x1,x2)));
105 }
106 break;
107 case SOT_MINUS:
108 {
109 ComplementView<View1> cx1(x1);
111 (SuperOfInter<View0,
113 ::post(home,x0,cx1,x2)));
114 }
115 break;
116 }
117
118 }
119
120 template<class View0, class View1, class View2>
121 forceinline void
122 rel_sup(Home home, View0 x0, SetOpType op, View1 x1, View2 x2) {
123 switch(op) {
124 case SOT_DUNION:
125 {
126 EmptyView emptyset;
128 ::post(home, x0, x1, emptyset)));
129 }
130 // fall through
131 case SOT_UNION:
132 {
135 ::post(home, x0, x1, x2)));
136 }
137 break;
138 case SOT_INTER:
139 {
140 SetVar tmp(home);
142 (Rel::Subset<View2,SetView>::post(home,x2,tmp)));
143
145 ::post(home, x0,x1,tmp)));
146 }
147 break;
148 case SOT_MINUS:
149 {
150 SetVar tmp(home);
152 (Rel::Subset<View2,SetView>::post(home,x2,tmp)));
153
154 ComplementView<View1> cx1(x1);
156 (Intersection<View0,
158 ::post(home,x0,cx1,tmp)));
159 }
160 break;
161 }
162
163 }
164
165 template<class View>
166 forceinline void
168 switch (r) {
169 case SRT_LQ:
171 break;
172 case SRT_LE:
174 break;
175 case SRT_GQ:
177 break;
178 case SRT_GR:
180 break;
181 default:
182 throw UnknownRelation("Set::rel");
183 }
184 }
185
187 template<class View0, class View1>
188 forceinline SetVar
189 rel_op_result(Home home, View0 x, SetOpType op, View1 y) {
190 LubRanges<View0> x_lub(x);
191 LubRanges<View1> y_lub(y);
192 switch (op) {
193 case SOT_UNION:
194 case SOT_DUNION:
195 {
197 lub(x_lub,y_lub);
198 return SetVar(home,IntSet::empty,IntSet(lub));
199 }
200 case SOT_INTER:
201 {
203 lub(x_lub,y_lub);
204 return SetVar(home,IntSet::empty,IntSet(lub));
205 }
206 case SOT_MINUS:
207 return SetVar(home,IntSet::empty,IntSet(x_lub));
208 default:
209 throw UnknownOperation("Set::rel");
210 }
211 }
212
213 template<class View0, class View1, class View2>
214 forceinline void
215 rel_op_post_nocompl(Home home, View0 x, SetOpType op, View1 y,
216 SetRelType r, View2 z) {
217 if (home.failed()) return;
218 switch(r) {
219 case SRT_EQ:
220 rel_eq<View0,View1,View2>(home, x, op, y, z);
221 break;
222 case SRT_LQ: case SRT_LE: case SRT_GQ: case SRT_GR:
223 {
224 // The order propagator walks every value of the upper bound.
225 SetVar tmp = rel_op_result(home, x, op, y);
226 rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
227 rel_op_post_lex<View2>(home,tmp,r,z);
228 }
229 break;
230 case SRT_NQ:
231 {
232 SetVar tmp(home);
235 ::post(home,tmp,z)));
236 rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
237 }
238 break;
239 case SRT_SUB:
240 rel_sub<View0,View1,View2>(home, x, op, y, z);
241 break;
242 case SRT_SUP:
243 rel_sup<View0,View1,View2>(home, x, op, y, z);
244 break;
245 case SRT_DISJ:
246 {
247 SetVar tmp(home);
248 EmptyView emptyset;
250 ::post(home, z, tmp, emptyset)));
251 rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
252 }
253 break;
254 default:
256 }
257
258 }
259
262 SetRelType r, SetView z);
265 SetRelType r, SetView z);
266
270
274
277
280
283
286 ConstSetView z);
287
288}}}
289
290// STATISTICS: set-prop
Home class for posting propagators
Definition core.hpp:863
bool failed(void) const
Check whether corresponding space is failed.
Definition core.hpp:4293
IntSet(void)
Initialize as empty set.
Definition int-set-1.hpp:47
static const IntSet empty
Empty set.
Definition int.hh:302
Range iterator for computing intersection (binary).
Range iterator for computing union (binary).
Set variables
Definition set.hh:127
SetVar(void)
Default constructor.
Definition set.hpp:46
Complement set view.
Definition view.hpp:769
Constant view.
Definition view.hpp:186
Constant view for the empty set.
Definition view.hpp:336
Range iterator for the least upper bound.
Definition var-imp.hpp:317
Propagator for ternary intersection
Definition rel-op.hh:124
Propagator for the subset of union
Definition rel-op.hh:93
Propagator for the superset of intersection
Definition rel-op.hh:63
Propagator for ternary union
Definition rel-op.hh:154
Propagator for negated equality
Definition rel.hh:268
static ExecStatus post(Home home, View0 x, View1 y)
Post propagator .
Definition lq.hpp:325
static ExecStatus post(Home home, View0 x, View1 y)
Post propagator .
Definition subset.hpp:55
Set view for set variables
Definition view.hpp:56
UnknownOperation(const char *l)
Initialize with location l.
UnknownRelation(const char *l)
Initialize with location l.
#define GECODE_SET_EXPORT
Definition set.hh:67
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition macros.hpp:103
SetOpType
Common operations for sets.
Definition set.hh:667
SetRelType
Common relation types for sets.
Definition set.hh:650
@ SOT_MINUS
Difference.
Definition set.hh:671
@ SOT_DUNION
Disjoint union.
Definition set.hh:669
@ SOT_UNION
Union.
Definition set.hh:668
@ SOT_INTER
Intersection
Definition set.hh:670
@ SRT_GQ
Greater or equal ( ).
Definition set.hh:659
@ SRT_GR
Greater ( ).
Definition set.hh:660
@ SRT_LQ
Less or equal ( ).
Definition set.hh:657
@ SRT_NQ
Disequality ( ).
Definition set.hh:652
@ SRT_LE
Less ( ).
Definition set.hh:658
@ SRT_EQ
Equality ( ).
Definition set.hh:651
@ SRT_SUP
Superset ( ).
Definition set.hh:654
@ SRT_DISJ
Disjoint ( ).
Definition set.hh:655
@ SRT_SUB
Subset ( ).
Definition set.hh:653
Standard set operation propagators.
Definition rel-op.hh:46
SetVar rel_op_result(Home home, View0 x, SetOpType op, View1 y)
Return a set variable whose upper bound contains every value of x op y.
Definition post.hpp:189
void rel_op_post_nocompl(Home home, View0 x, SetOpType op, View1 y, SetRelType r, View2 z)
Definition post.hpp:215
void post_nocompl(Home home, SetView x, SetOpType op, SetView y, SetRelType r, SetView z)
void rel_eq(Home home, View0 x0, SetOpType op, View1 x1, Res x2)
Definition post.hpp:45
void post_compl(Home home, SetView x, SetOpType op, SetView y, SetView z)
void rel_sup(Home home, View0 x0, SetOpType op, View1 x1, View2 x2)
Definition post.hpp:122
void rel_op_post_lex(Home home, SetView x0, SetRelType r, View x1)
Definition post.hpp:167
void rel_sub(Home home, View0 x0, SetOpType op, View1 x1, View2 x2)
Definition post.hpp:81
Finite integer sets.
Definition var-imp.hpp:145
Gecode toplevel namespace
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56