/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * * Copyright: * Christian Schulte, 2002 * * Last modified: * $Date: 2008-01-29 13:37:51 +0100 (Tue, 29 Jan 2008) $ by $Author: tack $ * $Revision: 5993 $ * * 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 { /** * \defgroup TaskPropRePat Reified propagator patterns * * \ingroup TaskActor */ //@{ /** * \brief Reified unary propagator * * Stores single view of type \a View with propagation condition \a pc * and a Boolean control view of type \a CtrlView. * * If the propagation condition \a pc has the value PC_GEN_NONE, no * subscriptions are created for \a View. * */ template class ReUnaryPropagator : public Propagator { protected: /// Single view View x0; /// Boolean control view CtrlView b; /// Constructor for cloning \a p ReUnaryPropagator(Space* home, bool share, ReUnaryPropagator& p); /// Constructor for rewriting \a p during cloning ReUnaryPropagator(Space* home, bool share, Propagator& p, View x0, CtrlView b); /// Constructor for creation ReUnaryPropagator(Space* home, View x0, CtrlView b); public: /// Cost function (defined as PC_UNARY_LO) virtual PropCost cost(ModEventDelta med) const; /// Delete propagator and return its size virtual size_t dispose(Space* home); /// Return specification given a variable map \a m and a \a name Reflection::ActorSpec spec(const Space* home, Reflection::VarMap& m, const Support::Symbol& name) const; }; /** * \brief Reified binary propagator * * Stores two views of type \a View with propagation condition \a pc * and a Boolean control view of type \a CtrlView. * * If the propagation condition \a pc has the value PC_GEN_NONE, no * subscriptions are created for \a View. * */ template class ReBinaryPropagator : public Propagator { protected: /// Two views View x0, x1; /// Boolean control view CtrlView b; /// Constructor for cloning \a p ReBinaryPropagator(Space* home, bool share, ReBinaryPropagator& p); /// Constructor for rewriting \a p during cloning ReBinaryPropagator(Space* home, bool share, Propagator& p, View x0, View x1, CtrlView b); /// Constructor for creation ReBinaryPropagator(Space* home, View x0, View x1, CtrlView b); public: /// Cost function (defined as PC_BINARY_LO) virtual PropCost cost(ModEventDelta med) const; /// Delete propagator and return its size virtual size_t dispose(Space* home); /// Return specification given a variable map \a m and a \a name Reflection::ActorSpec spec(const Space* home, Reflection::VarMap& m, const Support::Symbol& name) const; }; //@} /* * Reified unary propagators * */ template ReUnaryPropagator::ReUnaryPropagator (Space* 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 forceinline ReUnaryPropagator::ReUnaryPropagator (Space* home, bool share, ReUnaryPropagator& p) : Propagator(home,share,p) { x0.update(home,share,p.x0); b.update(home,share,p.b); } template forceinline ReUnaryPropagator::ReUnaryPropagator (Space* home, bool share, Propagator& p, View y0, CtrlView b0) : Propagator(home,share,p) { x0.update(home,share,y0); b.update(home,share,b0); } template PropCost ReUnaryPropagator::cost(ModEventDelta) const { return PC_UNARY_LO; } template forceinline size_t ReUnaryPropagator::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); } template Reflection::ActorSpec ReUnaryPropagator::spec(const Space* home, Reflection::VarMap& m, const Support::Symbol& name) const { Reflection::ActorSpec s(name); return s << x0.spec(home, m) << b.spec(home, m); } /* * Reified binary propagators * */ template ReBinaryPropagator::ReBinaryPropagator (Space* 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 forceinline ReBinaryPropagator::ReBinaryPropagator (Space* home, bool share, ReBinaryPropagator& p) : Propagator(home,share,p) { x0.update(home,share,p.x0); x1.update(home,share,p.x1); b.update(home,share,p.b); } template forceinline ReBinaryPropagator::ReBinaryPropagator (Space* home, bool share, Propagator& p, View y0, View y1, CtrlView b0) : Propagator(home,share,p) { x0.update(home,share,y0); x1.update(home,share,y1); b.update(home,share,b0); } template PropCost ReBinaryPropagator::cost(ModEventDelta) const { return PC_BINARY_LO; } template forceinline size_t ReBinaryPropagator::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); } template Reflection::ActorSpec ReBinaryPropagator::spec(const Space* home, Reflection::VarMap& m, const Support::Symbol& name) const { Reflection::ActorSpec s(name); return s << x0.spec(home, m) << x1.spec(home, m) << b.spec(home, m); } } // STATISTICS: int-prop