Generated on Wed Jan 24 2018 21:22:26 for Gecode by doxygen 1.8.13
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, 2016
8  *
9  * Last modified:
10  * $Date: 2016-12-02 13:20:09 +0100 (Fri, 02 Dec 2016) $ by $Author: schulte $
11  * $Revision: 15304 $
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/float/rel.hh>
39 
40 namespace Gecode { namespace Float { namespace Bool {
41 
42  template<class View>
44  Ite<View>::Ite(Home home, Int::BoolView b0, View y0, View y1, View y2)
45  : Propagator(home), b(b0), x0(y0), x1(y1), x2(y2) {
46  b.subscribe(home,*this,Int::PC_BOOL_VAL);
47  x0.subscribe(home,*this,PC_FLOAT_BND);
48  x1.subscribe(home,*this,PC_FLOAT_BND);
49  x2.subscribe(home,*this,PC_FLOAT_BND);
50  }
51 
52  template<class View>
54  Ite<View>::Ite(Space& home, bool share, Ite<View>& p)
55  : Propagator(home,share,p) {
56  b.update(home,share,p.b);
57  x0.update(home,share,p.x0);
58  x1.update(home,share,p.x1);
59  x2.update(home,share,p.x2);
60  }
61 
62  template<class View>
63  PropCost
64  Ite<View>::cost(const Space&, const ModEventDelta&) const {
66  }
67 
68  template<class View>
69  void
71  b.reschedule(home,*this,Int::PC_BOOL_VAL);
72  x0.reschedule(home,*this,PC_FLOAT_BND);
73  x1.reschedule(home,*this,PC_FLOAT_BND);
74  x2.reschedule(home,*this,PC_FLOAT_BND);
75  }
76 
77  template<class View>
78  forceinline size_t
80  b.cancel(home,*this,Int::PC_BOOL_VAL);
81  x0.cancel(home,*this,PC_FLOAT_BND);
82  x1.cancel(home,*this,PC_FLOAT_BND);
83  x2.cancel(home,*this,PC_FLOAT_BND);
84  (void) Propagator::dispose(home);
85  return sizeof(*this);
86  }
87 
88 
89 
90  template<class View>
91  Actor*
92  Ite<View>::copy(Space& home, bool share) {
93  return new (home) Ite<View>(home,share,*this);
94  }
95 
96  template<class View>
97  inline ExecStatus
98  Ite<View>::post(Home home, Int::BoolView b, View x0, View x1, View x2) {
99  if (b.one())
100  return Rel::Eq<View,View>::post(home,x2,x0);
101  if (b.zero())
102  return Rel::Eq<View,View>::post(home,x2,x1);
103  GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
104  GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
105  (void) new (home) Ite<View>(home,b,x0,x1,x2);
106  return ES_OK;
107  }
108 
109  template<class View>
110  ExecStatus
112  if (b.one())
113  GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x0)));
114  if (b.zero())
115  GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x1)));
116 
117  GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
118  GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
119 
120  RelTest eq20 = rtest_eq(x2,x0);
121  RelTest eq21 = rtest_eq(x2,x1);
122 
123  if ((eq20 == RT_FALSE) && (eq21 == RT_FALSE))
124  return ES_FAILED;
125 
126  if (eq20 == RT_FALSE) {
127  GECODE_ME_CHECK(b.zero_none(home));
128  if (eq21 == RT_TRUE)
129  return home.ES_SUBSUMED(*this);
130  else
131  GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x1)));
132  }
133 
134  if (eq21 == RT_FALSE) {
135  GECODE_ME_CHECK(b.one_none(home));
136  if (eq20 == RT_TRUE)
137  return home.ES_SUBSUMED(*this);
138  else
139  GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x0)));
140  }
141 
142  if ((eq20 == RT_TRUE) && (eq21 == RT_TRUE))
143  return home.ES_SUBSUMED(*this);
144 
145  return ES_FIX;
146  }
147 
148 }}}
149 
150 // STATISTICS: float-prop
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition: view.hpp:489
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:120
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low ternary)
Definition: ite.hpp:64
bool zero(void) const
Test whether view is assigned to be zero.
Definition: bool.hpp:214
static ExecStatus post(Home home, Int::BoolView b, View x0, View x1, View x2)
Post if-then-else propagator.
Definition: ite.hpp:98
RelTest
Result of testing relation.
Definition: view.hpp:495
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3614
const FloatNum max
Largest allowed float value.
Definition: float.hh:848
View x0
Views.
Definition: bool.hh:62
bool one(void) const
Test whether view is assigned to be one.
Definition: bool.hpp:218
Binary bounds consistent equality propagator.
Definition: rel.hh:70
Relation does hold.
Definition: view.hpp:498
Base-class for propagators.
Definition: core.hpp:1092
Relation does not hold.
Definition: view.hpp:496
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition: view.hpp:494
Propagation has computed fixpoint.
Definition: core.hpp:545
Computation spaces.
Definition: core.hpp:1748
Base-class for both propagators and branchers.
Definition: core.hpp:696
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: ite.hpp:111
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition: view.hpp:483
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
const FloatNum min
Smallest allowed float value.
Definition: float.hh:850
Ite(Space &home, bool share, Ite &p)
Constructor for cloning p.
Definition: ite.hpp:54
Execution has resulted in failure.
Definition: core.hpp:542
ModEvent zero_none(Space &home)
Assign not yet assigned view to zero.
Definition: bool.hpp:232
Int::BoolView b
View for condition.
Definition: bool.hh:60
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
If-then-else propagator.
Definition: bool.hh:57
void update(Space &home, bool share, VarImpView< Var > &y)
Update this view to be a clone of view y.
Definition: view.hpp:529
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:56
RelTest rtest_eq(View x, View y)
Test whether views x and y are equal.
Definition: rel-test.hpp:44
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: ite.hpp:92
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition: core.hpp:3354
virtual void reschedule(Space &home)
Schedule function.
Definition: ite.hpp:70
Propagation cost.
Definition: core.hpp:554
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: ite.hpp:79
ExecStatus
Definition: core.hpp:540
#define forceinline
Definition: config.hpp:173
Execution is okay.
Definition: core.hpp:544
const Gecode::PropCond PC_FLOAT_BND
Propagate when minimum or maximum of a view changes.
Definition: var-type.hpp:292
static PropCost ternary(PropCost::Mod m)
Three variables for modifier pcm.
Definition: core.hpp:4850
Gecode toplevel namespace
ModEvent one_none(Space &home)
Assign not yet assigned view to one.
Definition: bool.hpp:236
int ModEventDelta
Modification event deltas.
Definition: core.hpp:169
Home class for posting propagators
Definition: core.hpp:922
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