Generated on Mon Aug 27 2012 17:15:43 for Gecode by doxygen 1.8.1.2
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: 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/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:
56  {
58  (Eq<View0,View1>::post(home,x0,x1)));
59  }
60  break;
61  case SRT_NQ:
62  {
64  (Distinct<View0,View1>::post(home,x0,x1)));
65  }
66  break;
67  case SRT_SUB:
68  {
70  (Subset<View0,View1>::post(home, x0,x1)));
71  }
72  break;
73  case SRT_SUP:
74  {
76  (Subset<View1,View0>::post(home, x1,x0)));
77  }
78  break;
79  case SRT_DISJ:
80  {
81  EmptyView emptyset;
83  ::post(home, x0, x1, emptyset)));
84  }
85  break;
86  case SRT_CMPL:
87  {
88  ComplementView<View0> cx0(x0);
90  (Eq<ComplementView<View0>, View1>
91  ::post(home, cx0, x1)));
92  }
93  break;
94  case SRT_LQ:
96  break;
97  case SRT_LE:
99  break;
100  case SRT_GQ:
102  break;
103  case SRT_GR:
105  break;
106  default:
107  throw UnknownRelation("Set::rel");
108  }
109  }
110 
111  template<class View0, class View1>
112  void
113  rel_re(Home home, View0 x, SetRelType r, View1 y, BoolVar b) {
114  if (home.failed()) return;
115  switch (r) {
116  case SRT_EQ:
117  {
119  (ReEq<View0,View1>::post(home, x,y,b)));
120  }
121  break;
122  case SRT_NQ:
123  {
124  BoolVar notb(home, 0, 1);
125  rel(home, b, IRT_NQ, notb);
127  (ReEq<View0,View1>::post(home,x,y,notb)));
128  }
129  break;
130  case SRT_SUB:
131  {
133  (ReSubset<View0,View1>::post(home, x,y,b)));
134  }
135  break;
136  case SRT_SUP:
137  {
139  (ReSubset<View1,View0>::post(home, y,x,b)));
140  }
141  break;
142  case SRT_DISJ:
143  {
144  // x||y <=> b is equivalent to
145  // ( y <= complement(x) ) <=> b
146 
147  ComplementView<View0> xc(x);
150  ::post(home, y, xc, b)));
151  }
152  break;
153  case SRT_CMPL:
154  {
155  ComplementView<View0> xc(x);
158  ::post(home, xc, y, b)));
159  }
160  break;
161  case SRT_LQ:
163  break;
164  case SRT_LE:
166  break;
167  case SRT_GQ:
169  break;
170  case SRT_GR:
172  break;
173  default:
174  throw UnknownRelation("Set::rel");
175  }
176  }
177 
178  void
179  rel(Home home, SetVar x, SetRelType r, SetVar y) {
180  rel_post<SetView,SetView>(home,x,r,y);
181  }
182 
183  void
184  rel(Home home, SetVar s, SetRelType r, IntVar x) {
185  Gecode::Int::IntView xv(x);
186  SingletonView xsingle(xv);
187  rel_post<SetView,SingletonView>(home,s,r,xv);
188  }
189 
190  void
191  rel(Home home, IntVar x, SetRelType r, SetVar s) {
192  switch (r) {
193  case SRT_SUB:
194  rel(home, s, SRT_SUP, x);
195  break;
196  case SRT_SUP:
197  rel(home, s, SRT_SUB, x);
198  break;
199  default:
200  rel(home, s, r, x);
201  }
202  }
203 
204  void
206  rel_re<SetView,SetView>(home,x,r,y,b);
207  }
208 
209  void
211  Gecode::Int::IntView xv(x);
212  SingletonView xsingle(xv);
213  rel_re<SetView,SingletonView>(home,s,r,xsingle,b);
214  }
215 
216  void
218  switch (r) {
219  case SRT_SUB:
220  rel(home, s, SRT_SUP, x, b);
221  break;
222  case SRT_SUP:
223  rel(home, s, SRT_SUB, x, b);
224  break;
225  default:
226  rel(home, s, r, x, b);
227  }
228  }
229 
230 }
231 
232 // STATISTICS: set-post