propagator.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, 2002
*
* 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.
*
*/
namespace Gecode { namespace Int {
template<class View, PropCond pc, class CtrlView>
class ReUnaryPropagator : public Propagator {
protected:
View x0;
CtrlView b;
ReUnaryPropagator(Space& home, ReUnaryPropagator& p);
ReUnaryPropagator(Space& home, Propagator& p,
View x0, CtrlView b);
ReUnaryPropagator(Home home, View x0, CtrlView b);
public:
virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
virtual void reschedule(Space& home);
virtual size_t dispose(Space& home);
};
template<class View, PropCond pc, class CtrlView>
class ReBinaryPropagator : public Propagator {
protected:
View x0, x1;
CtrlView b;
ReBinaryPropagator(Space& home, ReBinaryPropagator& p);
ReBinaryPropagator(Space& home, Propagator& p,
View x0, View x1, CtrlView b);
ReBinaryPropagator(Home home, View x0, View x1, CtrlView b);
public:
virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
virtual void reschedule(Space& home);
virtual size_t dispose(Space& home);
};
template<class View0, PropCond pc0, class View1, PropCond pc1,
class CtrlView>
class ReMixBinaryPropagator : public Propagator {
protected:
View0 x0;
View1 x1;
CtrlView b;
ReMixBinaryPropagator(Space& home, ReMixBinaryPropagator& p);
ReMixBinaryPropagator(Home home, View0 x0, View1 x1, CtrlView b);
ReMixBinaryPropagator(Space& home, Propagator& p,
View0 x0, View1 x1, CtrlView b);
public:
virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
virtual void reschedule(Space& home);
virtual size_t dispose(Space& home);
};
/*
* Reified unary propagators
*
*/
template<class View, PropCond pc, class CtrlView>
ReUnaryPropagator<View,pc,CtrlView>::ReUnaryPropagator
(Home home, View y0, CtrlView b0)
: Propagator(home), x0(y0), b(b0) {
if (pc != PC_GEN_NONE)
x0.subscribe(home,*this,pc);
b.subscribe(home,*this,Int::PC_INT_VAL);
}
template<class View, PropCond pc, class CtrlView>
forceinline
ReUnaryPropagator<View,pc,CtrlView>::ReUnaryPropagator
(Space& home, ReUnaryPropagator<View,pc,CtrlView>& p)
: Propagator(home,p) {
x0.update(home,p.x0);
b.update(home,p.b);
}
template<class View, PropCond pc, class CtrlView>
forceinline
ReUnaryPropagator<View,pc,CtrlView>::ReUnaryPropagator
(Space& home, Propagator& p, View y0, CtrlView b0)
: Propagator(home,p) {
x0.update(home,y0);
b.update(home,b0);
}
template<class View, PropCond pc, class CtrlView>
PropCost
ReUnaryPropagator<View,pc,CtrlView>::cost(const Space&, const ModEventDelta&) const {
return PropCost::unary(PropCost::LO);
}
template<class View, PropCond pc, class CtrlView>
void
ReUnaryPropagator<View,pc,CtrlView>::reschedule(Space& home) {
if (pc != PC_GEN_NONE)
x0.reschedule(home,*this,pc);
b.reschedule(home,*this,Int::PC_INT_VAL);
}
template<class View, PropCond pc, class CtrlView>
forceinline size_t
ReUnaryPropagator<View,pc,CtrlView>::dispose(Space& home) {
if (pc != PC_GEN_NONE)
x0.cancel(home,*this,pc);
b.cancel(home,*this,Int::PC_INT_VAL);
(void) Propagator::dispose(home);
return sizeof(*this);
}
/*
* Reified binary propagators
*
*/
template<class View, PropCond pc, class CtrlView>
ReBinaryPropagator<View,pc,CtrlView>::ReBinaryPropagator
(Home home, View y0, View y1, CtrlView b1)
: Propagator(home), x0(y0), x1(y1), b(b1) {
if (pc != PC_GEN_NONE) {
x0.subscribe(home,*this,pc);
x1.subscribe(home,*this,pc);
}
b.subscribe(home,*this,Int::PC_INT_VAL);
}
template<class View, PropCond pc, class CtrlView>
forceinline
ReBinaryPropagator<View,pc,CtrlView>::ReBinaryPropagator
(Space& home, ReBinaryPropagator<View,pc,CtrlView>& p)
: Propagator(home,p) {
x0.update(home,p.x0);
x1.update(home,p.x1);
b.update(home,p.b);
}
template<class View, PropCond pc, class CtrlView>
forceinline
ReBinaryPropagator<View,pc,CtrlView>::ReBinaryPropagator
(Space& home, Propagator& p, View y0, View y1, CtrlView b0)
: Propagator(home,p) {
x0.update(home,y0);
x1.update(home,y1);
b.update(home,b0);
}
template<class View, PropCond pc, class CtrlView>
PropCost
ReBinaryPropagator<View,pc,CtrlView>::cost(const Space&, const ModEventDelta&) const {
return PropCost::binary(PropCost::LO);
}
template<class View, PropCond pc, class CtrlView>
void
ReBinaryPropagator<View,pc,CtrlView>::reschedule(Space& home) {
if (pc != PC_GEN_NONE) {
x0.reschedule(home,*this,pc);
x1.reschedule(home,*this,pc);
}
b.reschedule(home,*this,Int::PC_INT_VAL);
}
template<class View, PropCond pc, class CtrlView>
forceinline size_t
ReBinaryPropagator<View,pc,CtrlView>::dispose(Space& home) {
if (pc != PC_GEN_NONE) {
x0.cancel(home,*this,pc);
x1.cancel(home,*this,pc);
}
b.cancel(home,*this,Int::PC_INT_VAL);
(void) Propagator::dispose(home);
return sizeof(*this);
}
/*
* Reified mixed binary propagator
*
*/
template<class View0, PropCond pc0, class View1, PropCond pc1,
class CtrlView>
ReMixBinaryPropagator<View0,pc0,View1,pc1,CtrlView>
::ReMixBinaryPropagator(Home home, View0 y0, View1 y1, CtrlView b1)
: Propagator(home), x0(y0), x1(y1), b(b1) {
if (pc0 != PC_GEN_NONE)
x0.subscribe(home,*this,pc0);
if (pc1 != PC_GEN_NONE)
x1.subscribe(home,*this,pc1);
b.subscribe(home,*this,Int::PC_INT_VAL);
}
template<class View0, PropCond pc0, class View1, PropCond pc1,
class CtrlView>
forceinline
ReMixBinaryPropagator<View0,pc0,View1,pc1,CtrlView>::ReMixBinaryPropagator
(Space& home,
ReMixBinaryPropagator<View0,pc0,View1,pc1,CtrlView>& p)
: Propagator(home,p) {
x0.update(home,p.x0);
x1.update(home,p.x1);
b.update(home,p.b);
}
template<class View0, PropCond pc0, class View1, PropCond pc1,
class CtrlView>
forceinline
ReMixBinaryPropagator<View0,pc0,View1,pc1,CtrlView>
::ReMixBinaryPropagator
(Space& home, Propagator& p, View0 y0, View1 y1, CtrlView b0)
: Propagator(home,p) {
x0.update(home,y0);
x1.update(home,y1);
b.update(home,b0);
}
template<class View0, PropCond pc0, class View1, PropCond pc1,
class CtrlView>
PropCost
ReMixBinaryPropagator<View0,pc0,View1,pc1,CtrlView>
::cost(const Space&, const ModEventDelta&) const {
return PropCost::binary(PropCost::LO);
}
template<class View0, PropCond pc0, class View1, PropCond pc1,
class CtrlView>
void
ReMixBinaryPropagator<View0,pc0,View1,pc1,CtrlView>::reschedule(Space& home) {
if (pc0 != PC_GEN_NONE)
x0.reschedule(home,*this,pc0);
if (pc1 != PC_GEN_NONE)
x1.reschedule(home,*this,pc1);
b.reschedule(home,*this,Int::PC_INT_VAL);
}
template<class View0, PropCond pc0, class View1, PropCond pc1,
class CtrlView>
forceinline size_t
ReMixBinaryPropagator<View0,pc0,View1,pc1,CtrlView>::dispose(Space& home) {
if (pc0 != PC_GEN_NONE)
x0.cancel(home,*this,pc0);
if (pc1 != PC_GEN_NONE)
x1.cancel(home,*this,pc1);
b.cancel(home,*this,Int::PC_INT_VAL);
(void) Propagator::dispose(home);
return sizeof(*this);
}
}}
// STATISTICS: int-prop
Gecode::Actor::dispose
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition core.hpp:3252
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::Int::ReBinaryPropagator
Reified binary propagator.
Definition propagator.hpp:87
Gecode::Int::ReBinaryPropagator::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low binary).
Definition propagator.hpp:241
Gecode::Int::ReBinaryPropagator::ReBinaryPropagator
ReBinaryPropagator(Space &home, ReBinaryPropagator &p)
Constructor for cloning p.
Gecode::Int::ReBinaryPropagator::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition propagator.hpp:257
Gecode::Int::ReBinaryPropagator::reschedule
virtual void reschedule(Space &home)
Schedule function.
Definition propagator.hpp:247
Gecode::Int::ReBinaryPropagator::x0
View x0
Two views.
Definition propagator.hpp:90
Gecode::Int::ReBinaryPropagator::b
CtrlView b
Boolean control view.
Definition propagator.hpp:92
Gecode::Int::ReBinaryPropagator::x1
View x1
Definition propagator.hpp:90
Gecode::Int::ReMixBinaryPropagator
Reified mixed binary propagator.
Definition propagator.hpp:124
Gecode::Int::ReMixBinaryPropagator::ReMixBinaryPropagator
ReMixBinaryPropagator(Space &home, ReMixBinaryPropagator &p)
Constructor for cloning p.
Definition propagator.hpp:287
Gecode::Int::ReMixBinaryPropagator::x1
View1 x1
View of type View1.
Definition propagator.hpp:129
Gecode::Int::ReMixBinaryPropagator::reschedule
virtual void reschedule(Space &home)
Schedule function.
Definition propagator.hpp:318
Gecode::Int::ReMixBinaryPropagator::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition propagator.hpp:329
Gecode::Int::ReMixBinaryPropagator::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low binary).
Definition propagator.hpp:311
Gecode::Int::ReMixBinaryPropagator::b
CtrlView b
Boolean control view.
Definition propagator.hpp:131
Gecode::Int::ReMixBinaryPropagator::x0
View0 x0
View of type View0.
Definition propagator.hpp:127
Gecode::Int::ReUnaryPropagator
Reified unary propagator.
Definition propagator.hpp:54
Gecode::Int::ReUnaryPropagator::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low unary).
Definition propagator.hpp:182
Gecode::Int::ReUnaryPropagator::b
CtrlView b
Boolean control view.
Definition propagator.hpp:59
Gecode::Int::ReUnaryPropagator::ReUnaryPropagator
ReUnaryPropagator(Space &home, ReUnaryPropagator &p)
Constructor for cloning p.
Gecode::Int::ReUnaryPropagator::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition propagator.hpp:196
Gecode::Int::ReUnaryPropagator::x0
View x0
Single view.
Definition propagator.hpp:57
Gecode::Int::ReUnaryPropagator::reschedule
virtual void reschedule(Space &home)
Schedule function.
Definition propagator.hpp:188
Gecode::PropCost
Propagation cost.
Definition core.hpp:486
Gecode::PropCost::unary
static PropCost unary(PropCost::Mod m)
Single variable for modifier pcm.
Definition core.hpp:4813
Gecode::PropCost::binary
static PropCost binary(PropCost::Mod m)
Two variables for modifier pcm.
Definition core.hpp:4809
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::med
ModEventDelta med
A set of modification events (used during propagation).
Definition core.hpp:1075
Gecode::Propagator::Propagator
Propagator(Home home)
Constructor for posting.
Definition core.hpp:3498
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::View
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
Gecode::Int
Finite domain integers.
Gecode::Int::PC_INT_VAL
const Gecode::PropCond PC_INT_VAL
Propagate when a view becomes assigned (single value).
Definition var-type.hpp:82
Gecode
Gecode toplevel namespace
Gecode::PropCond
int PropCond
Type for propagation conditions.
Definition core.hpp:72
Gecode::PC_GEN_NONE
const PropCond PC_GEN_NONE
Propagation condition to be ignored (convenience).
Definition core.hpp:74
forceinline
#define forceinline
Definition config.hpp:187