Generated on Tue Oct 22 2013 00:49:03 for Gecode by doxygen 1.8.4
ite.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2013
8  *
9  * Last modified:
10  * $Date: 2013-04-29 20:52:35 +0200 (Mon, 29 Apr 2013) $ by $Author: schulte $
11  * $Revision: 13590 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <gecode/int/rel.hh>
39 
40 #include <algorithm>
41 
42 namespace Gecode { namespace Int { namespace Bool {
43 
44  template<class View, PropCond pc>
46  IteBase<View,pc>::IteBase(Home home, BoolView b0, View y0, View y1, View y2)
47  : Propagator(home), b(b0), x0(y0), x1(y1), x2(y2) {
48  b.subscribe(home,*this,PC_BOOL_VAL);
49  x0.subscribe(home,*this,pc);
50  x1.subscribe(home,*this,pc);
51  x2.subscribe(home,*this,pc);
52  }
53 
54  template<class View, PropCond pc>
57  : Propagator(home,share,p) {
58  b.update(home,share,p.b);
59  x0.update(home,share,p.x0);
60  x1.update(home,share,p.x1);
61  x2.update(home,share,p.x2);
62  }
63 
64  template<class View, PropCond pc>
65  PropCost
66  IteBase<View,pc>::cost(const Space&, const ModEventDelta&) const {
68  }
69 
70  template<class View, PropCond pc>
71  forceinline size_t
73  b.cancel(home,*this,PC_BOOL_VAL);
74  x0.cancel(home,*this,pc);
75  x1.cancel(home,*this,pc);
76  x2.cancel(home,*this,pc);
77  (void) Propagator::dispose(home);
78  return sizeof(*this);
79  }
80 
81 
82 
83  template<class View>
85  IteBnd<View>::IteBnd(Home home, BoolView b, View x0, View x1, View x2)
86  : IteBase<View,PC_INT_BND>(home,b,x0,x1,x2) {}
87 
88  template<class View>
91  : IteBase<View,PC_INT_BND>(home,share,p) {}
92 
93  template<class View>
94  Actor*
95  IteBnd<View>::copy(Space& home, bool share) {
96  return new (home) IteBnd<View>(home,share,*this);
97  }
98 
99  template<class View>
100  inline ExecStatus
101  IteBnd<View>::post(Home home, BoolView b, View x0, View x1, View x2) {
102  if (same(x0,x1) || b.one())
103  return Rel::EqBnd<View,View>::post(home,x2,x0);
104  if (b.zero())
105  return Rel::EqBnd<View,View>::post(home,x2,x1);
106  GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
107  GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
108  (void) new (home) IteBnd<View>(home,b,x0,x1,x2);
109  return ES_OK;
110  }
111 
112  template<class View>
113  ExecStatus
115  if (b.one())
116  GECODE_REWRITE(*this,(Rel::EqBnd<View,View>::post(home(*this),x2,x0)));
117  if (b.zero())
118  GECODE_REWRITE(*this,(Rel::EqBnd<View,View>::post(home(*this),x2,x1)));
119 
120  GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
121  GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
122 
123  RelTest eq20 = rtest_eq_bnd(x2,x0);
124  RelTest eq21 = rtest_eq_bnd(x2,x1);
125 
126  if ((eq20 == RT_FALSE) && (eq21 == RT_FALSE))
127  return ES_FAILED;
128 
129  if (eq20 == RT_FALSE) {
130  GECODE_ME_CHECK(b.zero_none(home));
131  if (eq21 == RT_TRUE)
132  return home.ES_SUBSUMED(*this);
133  else
134  GECODE_REWRITE(*this,(Rel::EqBnd<View,View>::post(home(*this),x2,x1)));
135  }
136 
137  if (eq21 == RT_FALSE) {
138  GECODE_ME_CHECK(b.one_none(home));
139  if (eq20 == RT_TRUE)
140  return home.ES_SUBSUMED(*this);
141  else
142  GECODE_REWRITE(*this,(Rel::EqBnd<View,View>::post(home(*this),x2,x0)));
143  }
144 
145  if ((eq20 == RT_TRUE) && (eq21 == RT_TRUE))
146  return home.ES_SUBSUMED(*this);
147 
148  return ES_FIX;
149  }
150 
151 
152 
153  template<class View>
155  IteDom<View>::IteDom(Home home, BoolView b, View x0, View x1, View x2)
156  : IteBase<View,PC_INT_DOM>(home,b,x0,x1,x2) {}
157 
158  template<class View>
161  : IteBase<View,PC_INT_DOM>(home,share,p) {}
162 
163  template<class View>
164  Actor*
165  IteDom<View>::copy(Space& home, bool share) {
166  return new (home) IteDom<View>(home,share,*this);
167  }
168 
169  template<class View>
170  inline ExecStatus
171  IteDom<View>::post(Home home, BoolView b, View x0, View x1, View x2) {
172  if (same(x0,x1) || b.one())
173  return Rel::EqDom<View,View>::post(home,x2,x0);
174  if (b.zero())
175  return Rel::EqDom<View,View>::post(home,x2,x1);
176  GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
177  GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
178  (void) new (home) IteDom<View>(home,b,x0,x1,x2);
179  return ES_OK;
180  }
181 
182  template<class View>
183  PropCost
184  IteDom<View>::cost(const Space&, const ModEventDelta& med) const {
185  if (View::me(med) == ME_INT_DOM)
187  else
189  }
190 
191  template<class View>
192  ExecStatus
194  if (b.one())
195  GECODE_REWRITE(*this,(Rel::EqDom<View,View>::post(home(*this),x2,x0)));
196  if (b.zero())
197  GECODE_REWRITE(*this,(Rel::EqDom<View,View>::post(home(*this),x2,x1)));
198 
199  GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
200  GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
201 
202  if (View::me(med) != ME_INT_DOM) {
203  RelTest eq20 = rtest_eq_bnd(x2,x0);
204  RelTest eq21 = rtest_eq_bnd(x2,x1);
205 
206  if ((eq20 == RT_FALSE) && (eq21 == RT_FALSE))
207  return ES_FAILED;
208 
209  if (eq20 == RT_FALSE) {
210  GECODE_ME_CHECK(b.zero_none(home));
211  if (eq21 == RT_TRUE)
212  return home.ES_SUBSUMED(*this);
213  else
214  GECODE_REWRITE(*this,
215  (Rel::EqDom<View,View>::post(home(*this),x2,x1)));
216  }
217 
218  if (eq21 == RT_FALSE) {
219  GECODE_ME_CHECK(b.one_none(home));
220  if (eq20 == RT_TRUE)
221  return home.ES_SUBSUMED(*this);
222  else
223  GECODE_REWRITE(*this,
224  (Rel::EqDom<View,View>::post(home(*this),x2,x0)));
225  }
226 
227  if ((eq20 == RT_TRUE) && (eq21 == RT_TRUE))
228  return home.ES_SUBSUMED(*this);
229 
230  return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
231  }
232 
233  RelTest eq20 = rtest_eq_dom(x2,x0);
234  RelTest eq21 = rtest_eq_dom(x2,x1);
235 
236  if ((eq20 == RT_FALSE) && (eq21 == RT_FALSE))
237  return ES_FAILED;
238 
239  if (eq20 == RT_FALSE) {
240  GECODE_ME_CHECK(b.zero_none(home));
241  if (eq21 == RT_TRUE)
242  return home.ES_SUBSUMED(*this);
243  else
244  GECODE_REWRITE(*this,
245  (Rel::EqDom<View,View>::post(home(*this),x2,x1)));
246  }
247 
248  if (eq21 == RT_FALSE) {
249  GECODE_ME_CHECK(b.one_none(home));
250  if (eq20 == RT_TRUE)
251  return home.ES_SUBSUMED(*this);
252  else
253  GECODE_REWRITE(*this,
254  (Rel::EqDom<View,View>::post(home(*this),x2,x0)));
255  }
256 
257  assert((eq20 != RT_TRUE) || (eq21 != RT_TRUE));
258 
259  ViewRanges<View> r0(x0), r1(x1);
261 
262  if (!same(x0,x2) && !same(x1,x2))
263  GECODE_ME_CHECK(x2.inter_r(home,u,false));
264  else
265  GECODE_ME_CHECK(x2.inter_r(home,u,true));
266 
267  return ES_FIX;
268  }
269 
270 }}}
271 
272 // STATISTICS: int-prop