Generated on Mon Aug 27 2012 17:15:42 for Gecode by doxygen 1.8.1.2
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  * Last modified:
13  * $Date: 2011-08-25 00:34:16 +1000 (Thu, 25 Aug 2011) $ by $Author: tack $
14  * $Revision: 12346 $
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.hh>
42 #include <gecode/set/rel.hh>
43 #include <gecode/set/rel-op.hh>
44 
45 namespace Gecode { namespace Set { namespace RelOp {
46 
47  template<class View0, class View1, class Res>
48  forceinline void
49  rel_eq(Home home, View0 x0, SetOpType op, View1 x1, Res x2) {
50  switch(op) {
51  case SOT_DUNION:
52  {
53  EmptyView emptyset;
55  ::post(home, x0, x1, emptyset)));
56  // fall through to SOT_UNION
57  }
58  case SOT_UNION:
59  {
62  ::post(home, x0, x1, x2)));
63  }
64  break;
65  case SOT_INTER:
66  {
68  ::post(home, x0,x1,x2)));
69  }
70  break;
71  case SOT_MINUS:
72  {
73  ComplementView<View1> cx1(x1);
75  (Intersection<View0,
77  ::post(home,x0,cx1,x2)));
78  }
79  break;
80  }
81  }
82 
83  template<class View0, class View1, class View2>
84  forceinline void
85  rel_sub(Home home, View0 x0, SetOpType op, View1 x1, View2 x2) {
86  switch(op) {
87  case SOT_DUNION:
88  {
89  EmptyView emptyset;
91  ::post(home, x0, x1, emptyset)));
92  // fall through to SOT_UNION
93  }
94  case SOT_UNION:
95  {
96  SetVar tmp(home);
98  (Rel::Subset<SetView,View2>::post(home,tmp,x2)));
99 
102  ::post(home, x0, x1, tmp)));
103  }
104  break;
105  case SOT_INTER:
106  {
108  ::post(home, x0,x1,x2)));
109  }
110  break;
111  case SOT_MINUS:
112  {
113  ComplementView<View1> cx1(x1);
115  (SuperOfInter<View0,
116  ComplementView<View1>,View2>
117  ::post(home,x0,cx1,x2)));
118  }
119  break;
120  }
121 
122  }
123 
124  template<class View0, class View1, class View2>
125  forceinline void
126  rel_sup(Home home, View0 x0, SetOpType op, View1 x1, View2 x2) {
127  switch(op) {
128  case SOT_DUNION:
129  {
130  EmptyView emptyset;
132  ::post(home, x0, x1, emptyset)));
133  // fall through to SOT_UNION
134  }
135  case SOT_UNION:
136  {
139  ::post(home, x0, x1, x2)));
140  }
141  break;
142  case SOT_INTER:
143  {
144  SetVar tmp(home);
146  (Rel::Subset<View2,SetView>::post(home,x2,tmp)));
147 
149  ::post(home, x0,x1,tmp)));
150  }
151  break;
152  case SOT_MINUS:
153  {
154  SetVar tmp(home);
156  (Rel::Subset<View2,SetView>::post(home,x2,tmp)));
157 
158  ComplementView<View1> cx1(x1);
160  (Intersection<View0,
162  ::post(home,x0,cx1,tmp)));
163  }
164  break;
165  }
166 
167  }
168 
169  template<class View>
170  forceinline void
171  rel_op_post_lex(Home home, SetView x0, SetRelType r, View x1) {
172  switch (r) {
173  case SRT_LQ:
175  break;
176  case SRT_LE:
178  break;
179  case SRT_GQ:
181  break;
182  case SRT_GR:
184  break;
185  default:
186  throw UnknownRelation("Set::rel");
187  }
188  }
189 
190  template<class View0, class View1, class View2>
191  forceinline void
192  rel_op_post_nocompl(Home home, View0 x, SetOpType op, View1 y,
193  SetRelType r, View2 z) {
194  if (home.failed()) return;
195  switch(r) {
196  case SRT_EQ:
197  rel_eq<View0,View1,View2>(home, x, op, y, z);
198  break;
199  case SRT_LQ: case SRT_LE: case SRT_GQ: case SRT_GR:
200  {
202  rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
203  rel_op_post_lex<View2>(home,tmp,r,z);
204  }
205  break;
206  case SRT_NQ:
207  {
208  SetVar tmp(home);
211  ::post(home,tmp,z)));
212  rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
213  }
214  break;
215  case SRT_SUB:
216  rel_sub<View0,View1,View2>(home, x, op, y, z);
217  break;
218  case SRT_SUP:
219  rel_sup<View0,View1,View2>(home, x, op, y, z);
220  break;
221  case SRT_DISJ:
222  {
223  SetVar tmp(home);
224  EmptyView emptyset;
226  ::post(home, z, tmp, emptyset)));
227  rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
228  }
229  break;
230  default:
231  GECODE_NEVER;
232  }
233 
234  }
235 
236  GECODE_SET_EXPORT void
237  post_nocompl(Home home, SetView x, SetOpType op, SetView y,
238  SetRelType r, SetView z);
239  GECODE_SET_EXPORT void
241  SetRelType r, SetView z);
242 
243  GECODE_SET_EXPORT void
244  post_nocompl(Home home, SetView x, SetOpType op, SetView y,
246 
247  GECODE_SET_EXPORT void
250 
251  GECODE_SET_EXPORT void
252  post_compl(Home home, SetView x, SetOpType op, SetView y, SetView z);
253 
254  GECODE_SET_EXPORT void
256 
257  GECODE_SET_EXPORT void
259 
260  GECODE_SET_EXPORT void
262  ConstSetView z);
263 
264 }}}
265 
266 // STATISTICS: set-prop