Generated on Wed Jan 1 2020 10:37:59 for Gecode by doxygen 1.8.16
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  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 #include <gecode/int/rel.hh>
35 
36 #include <algorithm>
37 
38 namespace Gecode { namespace Int { namespace Bool {
39 
40  template<class V0, class V1, class V2, PropCond pc>
42  IteBase<V0,V1,V2,pc>::IteBase(Home home, BoolView b0, V0 y0, V1 y1, V2 y2)
43  : Propagator(home), b(b0), x0(y0), x1(y1), x2(y2) {
44  b.subscribe(home,*this,PC_BOOL_VAL);
45  x0.subscribe(home,*this,pc);
46  x1.subscribe(home,*this,pc);
47  x2.subscribe(home,*this,pc);
48  }
49 
50  template<class V0, class V1, class V2, PropCond pc>
53  : Propagator(home,p) {
54  b.update(home,p.b);
55  x0.update(home,p.x0);
56  x1.update(home,p.x1);
57  x2.update(home,p.x2);
58  }
59 
60  template<class V0, class V1, class V2, PropCond pc>
61  PropCost
63  return PropCost::ternary(PropCost::LO);
64  }
65 
66  template<class V0, class V1, class V2, PropCond pc>
67  void
69  b.reschedule(home,*this,PC_BOOL_VAL);
70  x0.reschedule(home,*this,pc);
71  x1.reschedule(home,*this,pc);
72  x2.reschedule(home,*this,pc);
73  }
74 
75  template<class V0, class V1, class V2, PropCond pc>
76  forceinline size_t
78  b.cancel(home,*this,PC_BOOL_VAL);
79  x0.cancel(home,*this,pc);
80  x1.cancel(home,*this,pc);
81  x2.cancel(home,*this,pc);
82  (void) Propagator::dispose(home);
83  return sizeof(*this);
84  }
85 
86 
87 
88  template<class V0, class V1, class V2>
90  IteBnd<V0,V1,V2>::IteBnd(Home home, BoolView b, V0 x0, V1 x1, V2 x2)
91  : IteBase<V0,V1,V2,PC_INT_BND>(home,b,x0,x1,x2) {}
92 
93  template<class V0, class V1, class V2>
96  : IteBase<V0,V1,V2,PC_INT_BND>(home,p) {}
97 
98  template<class V0, class V1, class V2>
99  Actor*
101  return new (home) IteBnd<V0,V1,V2>(home,*this);
102  }
103 
104  template<class V0, class V1, class V2>
105  inline ExecStatus
106  IteBnd<V0,V1,V2>::post(Home home, BoolView b, V0 x0, V1 x1, V2 x2) {
107  if (b.one())
108  return Rel::EqBnd<V2,V0>::post(home,x2,x0);
109  if (b.zero())
110  return Rel::EqBnd<V2,V1>::post(home,x2,x1);
111  GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
112  GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
113  (void) new (home) IteBnd<V0,V1,V2>(home,b,x0,x1,x2);
114  return ES_OK;
115  }
116 
117  template<class V0, class V1, class V2>
118  ExecStatus
120  if (b.one())
121  GECODE_REWRITE(*this,(Rel::EqBnd<V2,V0>::post(home(*this),x2,x0)));
122  if (b.zero())
123  GECODE_REWRITE(*this,(Rel::EqBnd<V2,V1>::post(home(*this),x2,x1)));
124 
125  GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
126  GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
127 
128  RelTest eq20 = rtest_eq_bnd(x2,x0);
129  RelTest eq21 = rtest_eq_bnd(x2,x1);
130 
131  if ((eq20 == RT_FALSE) && (eq21 == RT_FALSE))
132  return ES_FAILED;
133 
134  if (eq20 == RT_FALSE) {
135  GECODE_ME_CHECK(b.zero_none(home));
136  if (eq21 == RT_TRUE)
137  return home.ES_SUBSUMED(*this);
138  else
139  GECODE_REWRITE(*this,(Rel::EqBnd<V2,V1>::post(home(*this),x2,x1)));
140  }
141 
142  if (eq21 == RT_FALSE) {
143  GECODE_ME_CHECK(b.one_none(home));
144  if (eq20 == RT_TRUE)
145  return home.ES_SUBSUMED(*this);
146  else
147  GECODE_REWRITE(*this,(Rel::EqBnd<V2,V0>::post(home(*this),x2,x0)));
148  }
149 
150  if ((eq20 == RT_TRUE) && (eq21 == RT_TRUE))
151  return home.ES_SUBSUMED(*this);
152 
153  return ES_FIX;
154  }
155 
156 
157 
158  template<class V0, class V1, class V2>
160  IteDom<V0,V1,V2>::IteDom(Home home, BoolView b, V0 x0, V1 x1, V2 x2)
161  : IteBase<V0,V1,V2,PC_INT_DOM>(home,b,x0,x1,x2) {}
162 
163  template<class V0, class V1, class V2>
166  : IteBase<V0,V1,V2,PC_INT_DOM>(home,p) {}
167 
168  template<class V0, class V1, class V2>
169  Actor*
171  return new (home) IteDom<V0,V1,V2>(home,*this);
172  }
173 
174  template<class V0, class V1, class V2>
175  inline ExecStatus
176  IteDom<V0,V1,V2>::post(Home home, BoolView b, V0 x0, V1 x1, V2 x2) {
177  if (b.one())
178  return Rel::EqDom<V2,V0>::post(home,x2,x0);
179  if (b.zero())
180  return Rel::EqDom<V2,V1>::post(home,x2,x1);
181  GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
182  GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
183  (void) new (home) IteDom<V0,V1,V2>(home,b,x0,x1,x2);
184  return ES_OK;
185  }
186 
187  template<class V0, class V1, class V2>
188  PropCost
189  IteDom<V0,V1,V2>::cost(const Space&, const ModEventDelta& med) const {
190  if (V0::me(med) == ME_INT_DOM)
192  else
194  }
195 
196  template<class V0, class V1, class V2>
197  ExecStatus
199  if (b.one())
200  GECODE_REWRITE(*this,(Rel::EqDom<V2,V0>::post(home(*this),x2,x0)));
201  if (b.zero())
202  GECODE_REWRITE(*this,(Rel::EqDom<V2,V1>::post(home(*this),x2,x1)));
203 
204  GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
205  GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
206 
207  if (V0::me(med) != ME_INT_DOM) {
208  RelTest eq20 = rtest_eq_bnd(x2,x0);
209  RelTest eq21 = rtest_eq_bnd(x2,x1);
210 
211  if ((eq20 == RT_FALSE) && (eq21 == RT_FALSE))
212  return ES_FAILED;
213 
214  if (eq20 == RT_FALSE) {
215  GECODE_ME_CHECK(b.zero_none(home));
216  if (eq21 == RT_TRUE)
217  return home.ES_SUBSUMED(*this);
218  else
219  GECODE_REWRITE(*this,
220  (Rel::EqDom<V2,V1>::post(home(*this),x2,x1)));
221  }
222 
223  if (eq21 == RT_FALSE) {
224  GECODE_ME_CHECK(b.one_none(home));
225  if (eq20 == RT_TRUE)
226  return home.ES_SUBSUMED(*this);
227  else
228  GECODE_REWRITE(*this,
229  (Rel::EqDom<V2,V0>::post(home(*this),x2,x0)));
230  }
231 
232  if ((eq20 == RT_TRUE) && (eq21 == RT_TRUE))
233  return home.ES_SUBSUMED(*this);
234 
235  return home.ES_FIX_PARTIAL(*this,V0::med(ME_INT_DOM));
236  }
237 
238  RelTest eq20 = rtest_eq_dom(x2,x0);
239  RelTest eq21 = rtest_eq_dom(x2,x1);
240 
241  if ((eq20 == RT_FALSE) && (eq21 == RT_FALSE))
242  return ES_FAILED;
243 
244  if (eq20 == RT_FALSE) {
245  GECODE_ME_CHECK(b.zero_none(home));
246  if (eq21 == RT_TRUE)
247  return home.ES_SUBSUMED(*this);
248  else
249  GECODE_REWRITE(*this,
250  (Rel::EqDom<V2,V1>::post(home(*this),x2,x1)));
251  }
252 
253  if (eq21 == RT_FALSE) {
254  GECODE_ME_CHECK(b.one_none(home));
255  if (eq20 == RT_TRUE)
256  return home.ES_SUBSUMED(*this);
257  else
258  GECODE_REWRITE(*this,
259  (Rel::EqDom<V2,V0>::post(home(*this),x2,x0)));
260  }
261 
262  assert((eq20 != RT_TRUE) || (eq21 != RT_TRUE));
263 
264  ViewRanges<V0> r0(x0);
265  ViewRanges<V1> r1(x1);
267 
268  if (!shared<V0,V2>(x0,x2) && !shared<V1,V2>(x1,x2))
269  GECODE_ME_CHECK(x2.inter_r(home,u,false));
270  else
271  GECODE_ME_CHECK(x2.inter_r(home,u,true));
272 
273  return ES_FIX;
274  }
275 
276 }}}
277 
278 // STATISTICS: int-prop
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:126
If-then-else bounds-consistent propagator.
Definition: bool.hh:606
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3563
RelTest rtest_eq_bnd(VX x, VY y)
Test whether views x and y are equal (use bounds information)
Definition: rel-test.hpp:43
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: ite.hpp:100
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: ite.hpp:198
Cheap.
Definition: core.hpp:513
const FloatNum min
Smallest allowed float value.
Definition: float.hh:846
Computation spaces.
Definition: core.hpp:1742
Base-class for both propagators and branchers.
Definition: core.hpp:628
Relation does hold.
Definition: view.hpp:1737
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: ite.hpp:119
Boolean view for Boolean variables.
Definition: view.hpp:1380
union Gecode::@602::NNF::@65 u
Union depending on nodetype t.
Gecode toplevel namespace
Base-class for propagators.
Definition: core.hpp:1064
Range iterator for integer views.
Definition: view.hpp:54
static ExecStatus post(Home home, BoolView b, V0 x0, V1 x1, V2 x2)
Post if-then-else propagator.
Definition: ite.hpp:106
Binary domain consistent equality propagator.
Definition: rel.hh:67
RelTest rtest_eq_dom(VX x, VY y)
Test whether views x and y are equal (use full domain information)
Definition: rel-test.hpp:65
Relation does not hold.
Definition: view.hpp:1735
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:92
If-then-else propagator base-class.
Definition: bool.hh:580
Home class for posting propagators
Definition: core.hpp:856
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: ite.hpp:170
const Gecode::PropCond PC_INT_BND
Propagate when minimum or maximum of a view changes.
Definition: var-type.hpp:91
IteBase(Space &home, IteBase &p)
Constructor for cloning p.
Definition: ite.hpp:52
static ExecStatus post(Home home, BoolView b, V0 x0, V1 x1, V2 x2)
Post if-then-else propagator.
Definition: ite.hpp:176
Range iterator for computing union (binary)
static PropCost ternary(PropCost::Mod m)
Three variables for modifier pcm.
Definition: core.hpp:4805
Propagation cost.
Definition: core.hpp:486
Propagation has computed fixpoint.
Definition: core.hpp:477
IteDom(Space &home, IteDom &p)
Constructor for cloning p.
Definition: ite.hpp:165
If-then-else domain-consistent propagator.
Definition: bool.hh:632
Binary bounds consistent equality propagator.
Definition: rel.hh:133
#define forceinline
Definition: config.hpp:185
RelTest
Result of testing relation.
Definition: view.hpp:1734
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as high ternary)
Definition: ite.hpp:189
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:52
Expensive.
Definition: core.hpp:514
IteBnd(Space &home, IteBnd &p)
Constructor for cloning p.
Definition: ite.hpp:95
Execution has resulted in failure.
Definition: core.hpp:474
ExecStatus ES_FIX_PARTIAL(Propagator &p, const ModEventDelta &med)
Propagator p has computed partial fixpoint
Definition: core.hpp:3569
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
const Gecode::ModEvent ME_INT_DOM
Domain operation has changed the domain.
Definition: var-type.hpp:72
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:116
Execution is okay.
Definition: core.hpp:476
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
const FloatNum max
Largest allowed float value.
Definition: float.hh:844
ExecStatus
Definition: core.hpp:472