Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
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 * 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/float/rel.hh>
35
36namespace Gecode { namespace Float { namespace Bool {
37
38 template<class View>
40 Ite<View>::Ite(Home home, Int::BoolView b0, View y0, View y1, View y2)
41 : Propagator(home), b(b0), x0(y0), x1(y1), x2(y2) {
42 b.subscribe(home,*this,Int::PC_BOOL_VAL);
43 x0.subscribe(home,*this,PC_FLOAT_BND);
44 x1.subscribe(home,*this,PC_FLOAT_BND);
45 x2.subscribe(home,*this,PC_FLOAT_BND);
46 }
47
48 template<class View>
51 : Propagator(home,p) {
52 b.update(home,p.b);
53 x0.update(home,p.x0);
54 x1.update(home,p.x1);
55 x2.update(home,p.x2);
56 }
57
58 template<class View>
60 Ite<View>::cost(const Space&, const ModEventDelta&) const {
62 }
63
64 template<class View>
65 void
67 b.reschedule(home,*this,Int::PC_BOOL_VAL);
68 x0.reschedule(home,*this,PC_FLOAT_BND);
69 x1.reschedule(home,*this,PC_FLOAT_BND);
70 x2.reschedule(home,*this,PC_FLOAT_BND);
71 }
72
73 template<class View>
74 forceinline size_t
76 b.cancel(home,*this,Int::PC_BOOL_VAL);
77 x0.cancel(home,*this,PC_FLOAT_BND);
78 x1.cancel(home,*this,PC_FLOAT_BND);
79 x2.cancel(home,*this,PC_FLOAT_BND);
80 (void) Propagator::dispose(home);
81 return sizeof(*this);
82 }
83
84
85
86 template<class View>
87 Actor*
89 return new (home) Ite<View>(home,*this);
90 }
91
92 template<class View>
93 inline ExecStatus
94 Ite<View>::post(Home home, Int::BoolView b, View x0, View x1, View x2) {
95 if (b.one())
96 return Rel::Eq<View,View>::post(home,x2,x0);
97 if (b.zero())
98 return Rel::Eq<View,View>::post(home,x2,x1);
99 GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
100 GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
101 (void) new (home) Ite<View>(home,b,x0,x1,x2);
102 return ES_OK;
103 }
104
105 template<class View>
108 if (b.one())
109 GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x0)));
110 if (b.zero())
111 GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x1)));
112
113 GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
114 GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
115
116 RelTest eq20 = rtest_eq(x2,x0);
117 RelTest eq21 = rtest_eq(x2,x1);
118
119 if ((eq20 == RT_FALSE) && (eq21 == RT_FALSE))
120 return ES_FAILED;
121
122 if (eq20 == RT_FALSE) {
123 GECODE_ME_CHECK(b.zero_none(home));
124 if (eq21 == RT_TRUE)
125 return home.ES_SUBSUMED(*this);
126 else
127 GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x1)));
128 }
129
130 if (eq21 == RT_FALSE) {
131 GECODE_ME_CHECK(b.one_none(home));
132 if (eq20 == RT_TRUE)
133 return home.ES_SUBSUMED(*this);
134 else
135 GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x0)));
136 }
137
138 if ((eq20 == RT_TRUE) && (eq21 == RT_TRUE))
139 return home.ES_SUBSUMED(*this);
140
141 return ES_FIX;
142 }
143
144}}}
145
146// STATISTICS: float-prop
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int p
Number of positive literals for node type.
Base-class for both propagators and branchers.
Definition core.hpp:628
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition core.hpp:3252
If-then-else propagator.
Definition bool.hh:53
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low ternary)
Definition ite.hpp:60
virtual void reschedule(Space &home)
Schedule function.
Definition ite.hpp:66
static ExecStatus post(Home home, Int::BoolView b, View x0, View x1, View x2)
Post if-then-else propagator.
Definition ite.hpp:94
Int::BoolView b
View for condition.
Definition bool.hh:56
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition ite.hpp:88
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition ite.hpp:75
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition ite.hpp:107
Ite(Space &home, Ite &p)
Constructor for cloning p.
Definition ite.hpp:50
Binary bounds consistent equality propagator.
Definition rel.hh:67
static ExecStatus post(Home home, View0 x0, View1 x1)
Post bounds consistent propagator .
Definition eq.hpp:50
Home class for posting propagators
Definition core.hpp:856
Boolean view for Boolean variables.
Definition view.hpp:1380
Propagation cost.
Definition core.hpp:486
static PropCost ternary(PropCost::Mod m)
Three variables for modifier pcm.
Definition core.hpp:4805
Base-class for propagators.
Definition core.hpp:1064
Computation spaces.
Definition core.hpp:1742
void update(Space &home, VarImpView< Var > &y)
Update this view to be a clone of view y.
Definition view.hpp:567
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition view.hpp:521
ExecStatus ES_SUBSUMED(Propagator &p)
Definition core.hpp:3563
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition macros.hpp:52
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition macros.hpp:116
RelTest
Result of testing relation.
Definition view.hpp:533
@ RT_TRUE
Relation does hold.
Definition view.hpp:536
@ RT_FALSE
Relation does not hold.
Definition view.hpp:534
RelTest rtest_eq(View x, View y)
Test whether views x and y are equal.
Definition rel-test.hpp:40
const Gecode::PropCond PC_FLOAT_BND
Propagate when minimum or maximum of a view changes.
Definition var-type.hpp:292
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value)
Definition var-type.hpp:126
Gecode toplevel namespace
ExecStatus
Definition core.hpp:472
@ ES_OK
Execution is okay.
Definition core.hpp:476
@ ES_FIX
Propagation has computed fixpoint.
Definition core.hpp:477
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:474
#define forceinline
Definition config.hpp:187