Generated on Sat Jun 2 2018 07:17:44 for Gecode by doxygen 1.8.13
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.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.hh>
38 #include <gecode/set/rel.hh>
39 #include <gecode/set/rel-op.hh>
40 
41 namespace 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  // fall through to SOT_UNION
53  }
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  {
69  ComplementView<View1> cx1(x1);
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  // fall through to SOT_UNION
89  }
90  case SOT_UNION:
91  {
92  SetVar tmp(home);
94  (Rel::Subset<SetView,View2>::post(home,tmp,x2)));
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,
112  ComplementView<View1>,View2>
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  // fall through to SOT_UNION
130  }
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
167  rel_op_post_lex(Home home, SetView x0, SetRelType r, View x1) {
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 
186  template<class View0, class View1, class View2>
187  forceinline void
188  rel_op_post_nocompl(Home home, View0 x, SetOpType op, View1 y,
189  SetRelType r, View2 z) {
190  if (home.failed()) return;
191  switch(r) {
192  case SRT_EQ:
193  rel_eq<View0,View1,View2>(home, x, op, y, z);
194  break;
195  case SRT_LQ: case SRT_LE: case SRT_GQ: case SRT_GR:
196  {
198  rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
199  rel_op_post_lex<View2>(home,tmp,r,z);
200  }
201  break;
202  case SRT_NQ:
203  {
204  SetVar tmp(home);
207  ::post(home,tmp,z)));
208  rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
209  }
210  break;
211  case SRT_SUB:
212  rel_sub<View0,View1,View2>(home, x, op, y, z);
213  break;
214  case SRT_SUP:
215  rel_sup<View0,View1,View2>(home, x, op, y, z);
216  break;
217  case SRT_DISJ:
218  {
219  SetVar tmp(home);
220  EmptyView emptyset;
222  ::post(home, z, tmp, emptyset)));
223  rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
224  }
225  break;
226  default:
227  GECODE_NEVER;
228  }
229 
230  }
231 
232  GECODE_SET_EXPORT void
234  SetRelType r, SetView z);
235  GECODE_SET_EXPORT void
237  SetRelType r, SetView z);
238 
239  GECODE_SET_EXPORT void
240  post_nocompl(Home home, SetView x, SetOpType op, SetView y,
241  SetRelType r, ConstSetView z);
242 
243  GECODE_SET_EXPORT void
245  SetRelType r, ConstSetView z);
246 
247  GECODE_SET_EXPORT void
248  post_compl(Home home, SetView x, SetOpType op, SetView y, SetView z);
249 
250  GECODE_SET_EXPORT void
252 
253  GECODE_SET_EXPORT void
255 
256  GECODE_SET_EXPORT void
258  ConstSetView z);
259 
260 }}}
261 
262 // STATISTICS: set-prop
Post propagator for SetVar SetOpType op
Definition: set.hh:765
Propagator for negated equality
Definition: rel.hh:267
SetRelType
Common relation types for sets.
Definition: set.hh:641
const int min
Smallest allowed integer in integer set.
Definition: set.hh:99
void post_nocompl(Home home, ConstSetView x, SetOpType op, SetView y, SetRelType r, ConstSetView z)
Propagator for ternary union
Definition: rel-op.hh:152
Propagator for the subset constraint
Definition: rel.hh:64
Propagator for set less than or equal
Definition: rel.hh:208
SetOpType
Common operations for sets.
Definition: set.hh:658
Superset ( )
Definition: set.hh:645
#define forceinline
Definition: config.hpp:185
const int max
Largest allowed integer in integer set.
Definition: set.hh:97
Difference.
Definition: set.hh:662
Propagator for the subset of union
Definition: rel-op.hh:91
Exception: Unknown relation passed as argument
Definition: exception.hpp:87
void rel_sub(Home home, View0 x0, SetOpType op, View1 x1, View2 x2)
Definition: post.hpp:81
Less or equal ( )
Definition: set.hh:648
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3967
Subset ( )
Definition: set.hh:644
Intersection
Definition: set.hh:661
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition: set.hh:765
Less ( )
Definition: set.hh:649
static const IntSet empty
Empty set.
Definition: int.hh:259
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:765
Set view for set variables
Definition: view.hpp:56
void rel_eq(Home home, View0 x0, SetOpType op, View1 x1, Res x2)
Definition: post.hpp:45
Union.
Definition: set.hh:659
Greater or equal ( )
Definition: set.hh:650
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:765
Constant view.
Definition: view.hpp:186
Set variables
Definition: set.hh:127
Disjoint union.
Definition: set.hh:660
void rel_sup(Home home, View0 x0, SetOpType op, View1 x1, View2 x2)
Definition: post.hpp:122
Propagator for the superset of intersection
Definition: rel-op.hh:61
Greater ( )
Definition: set.hh:651
Equality ( )
Definition: set.hh:642
Disjoint ( )
Definition: set.hh:646
Post propagator for SetVar x
Definition: set.hh:765
Disequality ( )
Definition: set.hh:643
Complement set view.
Definition: view.hpp:752
Gecode toplevel namespace
void post_compl(Home home, ConstSetView x, SetOpType op, SetView y, ConstSetView z)
void rel_op_post_nocompl(Home home, View0 x, SetOpType op, View1 y, SetRelType r, View2 z)
Definition: post.hpp:188
Constant view for the empty set.
Definition: view.hpp:331
Home class for posting propagators
Definition: core.hpp:853
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:103
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56
void rel_op_post_lex(Home home, SetView x0, SetRelType r, View x1)
Definition: post.hpp:167
#define GECODE_SET_EXPORT
Definition: set.hh:67
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition: filter.cpp:138
Propagator for ternary intersection
Definition: rel-op.hh:122