Generated on Fri Jul 13 2018 06:08:23 for Gecode by doxygen 1.8.14
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: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
11  * $Revision: 15137 $
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 V0, class V1, class V2, PropCond pc>
46  IteBase<V0,V1,V2,pc>::IteBase(Home home, BoolView b0, V0 y0, V1 y1, V2 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 V0, class V1, class V2, PropCond pc>
58  : Propagator(home,share,p) {
59  b.update(home,share,p.b);
60  x0.update(home,share,p.x0);
61  x1.update(home,share,p.x1);
62  x2.update(home,share,p.x2);
63  }
64 
65  template<class V0, class V1, class V2, PropCond pc>
66  PropCost
68  return PropCost::ternary(PropCost::LO);
69  }
70 
71  template<class V0, class V1, class V2, PropCond pc>
72  void
74  b.reschedule(home,*this,PC_BOOL_VAL);
75  x0.reschedule(home,*this,pc);
76  x1.reschedule(home,*this,pc);
77  x2.reschedule(home,*this,pc);
78  }
79 
80  template<class V0, class V1, class V2, PropCond pc>
81  forceinline size_t
83  b.cancel(home,*this,PC_BOOL_VAL);
84  x0.cancel(home,*this,pc);
85  x1.cancel(home,*this,pc);
86  x2.cancel(home,*this,pc);
87  (void) Propagator::dispose(home);
88  return sizeof(*this);
89  }
90 
91 
92 
93  template<class V0, class V1, class V2>
95  IteBnd<V0,V1,V2>::IteBnd(Home home, BoolView b, V0 x0, V1 x1, V2 x2)
96  : IteBase<V0,V1,V2,PC_INT_BND>(home,b,x0,x1,x2) {}
97 
98  template<class V0, class V1, class V2>
101  : IteBase<V0,V1,V2,PC_INT_BND>(home,share,p) {}
102 
103  template<class V0, class V1, class V2>
104  Actor*
105  IteBnd<V0,V1,V2>::copy(Space& home, bool share) {
106  return new (home) IteBnd<V0,V1,V2>(home,share,*this);
107  }
108 
109  template<class V0, class V1, class V2>
110  inline ExecStatus
111  IteBnd<V0,V1,V2>::post(Home home, BoolView b, V0 x0, V1 x1, V2 x2) {
112  if (b.one())
113  return Rel::EqBnd<V2,V0>::post(home,x2,x0);
114  if (b.zero())
115  return Rel::EqBnd<V2,V1>::post(home,x2,x1);
116  GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
117  GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
118  (void) new (home) IteBnd<V0,V1,V2>(home,b,x0,x1,x2);
119  return ES_OK;
120  }
121 
122  template<class V0, class V1, class V2>
123  ExecStatus
125  if (b.one())
126  GECODE_REWRITE(*this,(Rel::EqBnd<V2,V0>::post(home(*this),x2,x0)));
127  if (b.zero())
128  GECODE_REWRITE(*this,(Rel::EqBnd<V2,V1>::post(home(*this),x2,x1)));
129 
130  GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
131  GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
132 
133  RelTest eq20 = rtest_eq_bnd(x2,x0);
134  RelTest eq21 = rtest_eq_bnd(x2,x1);
135 
136  if ((eq20 == RT_FALSE) && (eq21 == RT_FALSE))
137  return ES_FAILED;
138 
139  if (eq20 == RT_FALSE) {
140  GECODE_ME_CHECK(b.zero_none(home));
141  if (eq21 == RT_TRUE)
142  return home.ES_SUBSUMED(*this);
143  else
144  GECODE_REWRITE(*this,(Rel::EqBnd<V2,V1>::post(home(*this),x2,x1)));
145  }
146 
147  if (eq21 == RT_FALSE) {
148  GECODE_ME_CHECK(b.one_none(home));
149  if (eq20 == RT_TRUE)
150  return home.ES_SUBSUMED(*this);
151  else
152  GECODE_REWRITE(*this,(Rel::EqBnd<V2,V0>::post(home(*this),x2,x0)));
153  }
154 
155  if ((eq20 == RT_TRUE) && (eq21 == RT_TRUE))
156  return home.ES_SUBSUMED(*this);
157 
158  return ES_FIX;
159  }
160 
161 
162 
163  template<class V0, class V1, class V2>
165  IteDom<V0,V1,V2>::IteDom(Home home, BoolView b, V0 x0, V1 x1, V2 x2)
166  : IteBase<V0,V1,V2,PC_INT_DOM>(home,b,x0,x1,x2) {}
167 
168  template<class V0, class V1, class V2>
171  : IteBase<V0,V1,V2,PC_INT_DOM>(home,share,p) {}
172 
173  template<class V0, class V1, class V2>
174  Actor*
175  IteDom<V0,V1,V2>::copy(Space& home, bool share) {
176  return new (home) IteDom<V0,V1,V2>(home,share,*this);
177  }
178 
179  template<class V0, class V1, class V2>
180  inline ExecStatus
181  IteDom<V0,V1,V2>::post(Home home, BoolView b, V0 x0, V1 x1, V2 x2) {
182  if (b.one())
183  return Rel::EqDom<V2,V0>::post(home,x2,x0);
184  if (b.zero())
185  return Rel::EqDom<V2,V1>::post(home,x2,x1);
186  GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
187  GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
188  (void) new (home) IteDom<V0,V1,V2>(home,b,x0,x1,x2);
189  return ES_OK;
190  }
191 
192  template<class V0, class V1, class V2>
193  PropCost
194  IteDom<V0,V1,V2>::cost(const Space&, const ModEventDelta& med) const {
195  if (V0::me(med) == ME_INT_DOM)
197  else
199  }
200 
201  template<class V0, class V1, class V2>
202  ExecStatus
204  if (b.one())
205  GECODE_REWRITE(*this,(Rel::EqDom<V2,V0>::post(home(*this),x2,x0)));
206  if (b.zero())
207  GECODE_REWRITE(*this,(Rel::EqDom<V2,V1>::post(home(*this),x2,x1)));
208 
209  GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
210  GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
211 
212  if (V0::me(med) != ME_INT_DOM) {
213  RelTest eq20 = rtest_eq_bnd(x2,x0);
214  RelTest eq21 = rtest_eq_bnd(x2,x1);
215 
216  if ((eq20 == RT_FALSE) && (eq21 == RT_FALSE))
217  return ES_FAILED;
218 
219  if (eq20 == RT_FALSE) {
220  GECODE_ME_CHECK(b.zero_none(home));
221  if (eq21 == RT_TRUE)
222  return home.ES_SUBSUMED(*this);
223  else
224  GECODE_REWRITE(*this,
225  (Rel::EqDom<V2,V1>::post(home(*this),x2,x1)));
226  }
227 
228  if (eq21 == RT_FALSE) {
229  GECODE_ME_CHECK(b.one_none(home));
230  if (eq20 == RT_TRUE)
231  return home.ES_SUBSUMED(*this);
232  else
233  GECODE_REWRITE(*this,
234  (Rel::EqDom<V2,V0>::post(home(*this),x2,x0)));
235  }
236 
237  if ((eq20 == RT_TRUE) && (eq21 == RT_TRUE))
238  return home.ES_SUBSUMED(*this);
239 
240  return home.ES_FIX_PARTIAL(*this,V0::med(ME_INT_DOM));
241  }
242 
243  RelTest eq20 = rtest_eq_dom(x2,x0);
244  RelTest eq21 = rtest_eq_dom(x2,x1);
245 
246  if ((eq20 == RT_FALSE) && (eq21 == RT_FALSE))
247  return ES_FAILED;
248 
249  if (eq20 == RT_FALSE) {
250  GECODE_ME_CHECK(b.zero_none(home));
251  if (eq21 == RT_TRUE)
252  return home.ES_SUBSUMED(*this);
253  else
254  GECODE_REWRITE(*this,
255  (Rel::EqDom<V2,V1>::post(home(*this),x2,x1)));
256  }
257 
258  if (eq21 == RT_FALSE) {
259  GECODE_ME_CHECK(b.one_none(home));
260  if (eq20 == RT_TRUE)
261  return home.ES_SUBSUMED(*this);
262  else
263  GECODE_REWRITE(*this,
264  (Rel::EqDom<V2,V0>::post(home(*this),x2,x0)));
265  }
266 
267  assert((eq20 != RT_TRUE) || (eq21 != RT_TRUE));
268 
269  ViewRanges<V0> r0(x0);
270  ViewRanges<V1> r1(x1);
272 
273  if (!shared<V0,V2>(x0,x2) && !shared<V1,V2>(x1,x2))
274  GECODE_ME_CHECK(x2.inter_r(home,u,false));
275  else
276  GECODE_ME_CHECK(x2.inter_r(home,u,true));
277 
278  return ES_FIX;
279  }
280 
281 }}}
282 
283 // STATISTICS: int-prop
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:120
If-then-else bounds-consistent propagator.
Definition: bool.hh:610
IteBnd(Space &home, bool share, IteBnd &p)
Constructor for cloning p.
Definition: ite.hpp:100
IteDom(Space &home, bool share, IteDom &p)
Constructor for cloning p.
Definition: ite.hpp:170
union Gecode::@579::NNF::@61 u
Union depending on nodetype t.
Binary domain consistent equality propagator.
Definition: rel.hh:71
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3614
const FloatNum max
Largest allowed float value.
Definition: float.hh:848
RelTest rtest_eq_dom(VX x, VY y)
Test whether views x and y are equal (use full domain information)
Definition: rel-test.hpp:69
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: ite.hpp:105
Base-class for propagators.
Definition: core.hpp:1092
Propagation has computed fixpoint.
Definition: core.hpp:545
Computation spaces.
Definition: core.hpp:1748
static ExecStatus post(Home home, BoolView b, V0 x0, V1 x1, V2 x2)
Post if-then-else propagator.
Definition: ite.hpp:181
Base-class for both propagators and branchers.
Definition: core.hpp:696
Range iterator for integer views.
Definition: view.hpp:54
IteBase(Space &home, bool share, IteBase &p)
Constructor for cloning p.
Definition: ite.hpp:56
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
If-then-else propagator base-class.
Definition: bool.hh:584
const FloatNum min
Smallest allowed float value.
Definition: float.hh:850
Execution has resulted in failure.
Definition: core.hpp:542
Relation does not hold.
Definition: view.hpp:1615
RelTest
Result of testing relation.
Definition: view.hpp:1614
const Gecode::PropCond PC_INT_BND
Propagate when minimum or maximum of a view changes.
Definition: var-type.hpp:91
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
Binary bounds consistent equality propagator.
Definition: rel.hh:137
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as high ternary)
Definition: ite.hpp:194
static ExecStatus post(Home home, BoolView b, V0 x0, V1 x1, V2 x2)
Post if-then-else propagator.
Definition: ite.hpp:111
Expensive.
Definition: core.hpp:582
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: ite.hpp:124
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:56
ExecStatus ES_FIX_PARTIAL(Propagator &p, const ModEventDelta &med)
Propagator p has computed partial fixpoint
Definition: core.hpp:3620
RelTest rtest_eq_bnd(VX x, VY y)
Test whether views x and y are equal (use bounds information)
Definition: rel-test.hpp:47
Range iterator for computing union (binary)
If-then-else domain-consistent propagator.
Definition: bool.hh:636
Propagation cost.
Definition: core.hpp:554
const Gecode::ModEvent ME_INT_DOM
Domain operation has changed the domain.
Definition: var-type.hpp:72
ExecStatus
Definition: core.hpp:540
#define forceinline
Definition: config.hpp:173
Execution is okay.
Definition: core.hpp:544
static PropCost ternary(PropCost::Mod m)
Three variables for modifier pcm.
Definition: core.hpp:4850
Gecode toplevel namespace
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:96
int ModEventDelta
Modification event deltas.
Definition: core.hpp:169
Home class for posting propagators
Definition: core.hpp:922
Relation does hold.
Definition: view.hpp:1617
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: ite.hpp:203
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: ite.hpp:175
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:126
Boolean view for Boolean variables.
Definition: view.hpp:1315