ite.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2016
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <gecode/float/rel.hh>
namespace Gecode { namespace Float { namespace Bool {
template<class View>
forceinline
Ite<View>::Ite(Home home, Int::BoolView b0, View y0, View y1, View y2)
: Propagator(home), b(b0), x0(y0), x1(y1), x2(y2) {
b.subscribe(home,*this,Int::PC_BOOL_VAL);
x0.subscribe(home,*this,PC_FLOAT_BND);
x1.subscribe(home,*this,PC_FLOAT_BND);
x2.subscribe(home,*this,PC_FLOAT_BND);
}
template<class View>
forceinline
Ite<View>::Ite(Space& home, Ite<View>& p)
: Propagator(home,p) {
b.update(home,p.b);
x0.update(home,p.x0);
x1.update(home,p.x1);
x2.update(home,p.x2);
}
template<class View>
PropCost
Ite<View>::cost(const Space&, const ModEventDelta&) const {
return PropCost::ternary(PropCost::LO);
}
template<class View>
void
Ite<View>::reschedule(Space& home) {
b.reschedule(home,*this,Int::PC_BOOL_VAL);
x0.reschedule(home,*this,PC_FLOAT_BND);
x1.reschedule(home,*this,PC_FLOAT_BND);
x2.reschedule(home,*this,PC_FLOAT_BND);
}
template<class View>
forceinline size_t
Ite<View>::dispose(Space& home) {
b.cancel(home,*this,Int::PC_BOOL_VAL);
x0.cancel(home,*this,PC_FLOAT_BND);
x1.cancel(home,*this,PC_FLOAT_BND);
x2.cancel(home,*this,PC_FLOAT_BND);
(void) Propagator::dispose(home);
return sizeof(*this);
}
template<class View>
Actor*
Ite<View>::copy(Space& home) {
return new (home) Ite<View>(home,*this);
}
template<class View>
inline ExecStatus
Ite<View>::post(Home home, Int::BoolView b, View x0, View x1, View x2) {
if (b.one())
return Rel::Eq<View,View>::post(home,x2,x0);
if (b.zero())
return Rel::Eq<View,View>::post(home,x2,x1);
GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
(void) new (home) Ite<View>(home,b,x0,x1,x2);
return ES_OK;
}
template<class View>
ExecStatus
Ite<View>::propagate(Space& home, const ModEventDelta&) {
if (b.one())
GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x0)));
if (b.zero())
GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x1)));
GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
RelTest eq20 = rtest_eq(x2,x0);
RelTest eq21 = rtest_eq(x2,x1);
if ((eq20 == RT_FALSE) && (eq21 == RT_FALSE))
return ES_FAILED;
if (eq20 == RT_FALSE) {
GECODE_ME_CHECK(b.zero_none(home));
if (eq21 == RT_TRUE)
return home.ES_SUBSUMED(*this);
else
GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x1)));
}
if (eq21 == RT_FALSE) {
GECODE_ME_CHECK(b.one_none(home));
if (eq20 == RT_TRUE)
return home.ES_SUBSUMED(*this);
else
GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x0)));
}
if ((eq20 == RT_TRUE) && (eq21 == RT_TRUE))
return home.ES_SUBSUMED(*this);
return ES_FIX;
}
}}}
// STATISTICS: float-prop
Gecode::Actor
Base-class for both propagators and branchers.
Definition core.hpp:628
Gecode::Actor::dispose
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition core.hpp:3252
Gecode::Float::Bool::Ite
If-then-else propagator.
Definition bool.hh:53
Gecode::Float::Bool::Ite::x2
View x2
Definition bool.hh:58
Gecode::Float::Bool::Ite::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low ternary).
Definition ite.hpp:60
Gecode::Float::Bool::Ite::reschedule
virtual void reschedule(Space &home)
Schedule function.
Definition ite.hpp:66
Gecode::Float::Bool::Ite::x0
View x0
Views.
Definition bool.hh:58
Gecode::Float::Bool::Ite::post
static ExecStatus post(Home home, Int::BoolView b, View x0, View x1, View x2)
Post if-then-else propagator.
Definition ite.hpp:94
Gecode::Float::Bool::Ite::b
Int::BoolView b
View for condition.
Definition bool.hh:56
Gecode::Float::Bool::Ite::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition ite.hpp:88
Gecode::Float::Bool::Ite::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition ite.hpp:75
Gecode::Float::Bool::Ite::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition ite.hpp:107
Gecode::Float::Bool::Ite::Ite
Ite(Space &home, Ite &p)
Constructor for cloning p.
Gecode::Float::Bool::Ite::x1
View x1
Definition bool.hh:58
Gecode::Float::Rel::Eq::post
static ExecStatus post(Home home, View0 x0, View1 x1)
Post bounds consistent propagator .
Definition eq.hpp:50
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::Int::BoolView
Boolean view for Boolean variables.
Definition view.hpp:1380
Gecode::PropCost
Propagation cost.
Definition core.hpp:486
Gecode::PropCost::ternary
static PropCost ternary(PropCost::Mod m)
Three variables for modifier pcm.
Definition core.hpp:4805
Gecode::PropCost::LO
@ LO
Cheap.
Definition core.hpp:513
Gecode::Propagator
Base-class for propagators.
Definition core.hpp:1064
Gecode::Propagator::Space
friend class Space
Definition core.hpp:1066
Gecode::Propagator::Propagator
Propagator(Home home)
Constructor for posting.
Definition core.hpp:3498
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::View
Gecode::VarImpView::update
void update(Space &home, VarImpView< Var > &y)
Update this view to be a clone of view y.
Definition view.hpp:567
rel.hh
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition core.hpp:3563
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
GECODE_ME_CHECK
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition macros.hpp:52
GECODE_REWRITE
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition macros.hpp:116
Gecode::Float::Bool
Boolean propagators.
Gecode::Float
Floating point numbers.
Gecode::Float::RelTest
RelTest
Result of testing relation.
Definition view.hpp:533
Gecode::Float::RT_TRUE
@ RT_TRUE
Relation does hold.
Definition view.hpp:536
Gecode::Float::RT_FALSE
@ RT_FALSE
Relation does not hold.
Definition view.hpp:534
Gecode::Float::rtest_eq
RelTest rtest_eq(View x, View y)
Test whether views x and y are equal.
Definition rel-test.hpp:40
Gecode::Float::PC_FLOAT_BND
const Gecode::PropCond PC_FLOAT_BND
Propagate when minimum or maximum of a view changes.
Definition var-type.hpp:292
Gecode::Int::PC_BOOL_VAL
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value).
Definition var-type.hpp:126
Gecode
Gecode toplevel namespace
Gecode::ExecStatus
ExecStatus
Definition core.hpp:472
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition core.hpp:476
Gecode::ES_FIX
@ ES_FIX
Propagation has computed fixpoint.
Definition core.hpp:477
Gecode::ES_FAILED
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:474
forceinline
#define forceinline
Definition config.hpp:187