Generated on Mon Aug 25 11:35:38 2008 for Gecode by doxygen 1.5.6

propagator.icc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2002
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-01-29 13:37:51 +0100 (Tue, 29 Jan 2008) $ by $Author: tack $
00011  *     $Revision: 5993 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode {
00039 
00057   template <class View, PropCond pc, class CtrlView>
00058   class ReUnaryPropagator : public Propagator {
00059   protected:
00061     View x0;
00063     CtrlView b;
00065     ReUnaryPropagator(Space* home, bool share, ReUnaryPropagator& p);
00067     ReUnaryPropagator(Space* home, bool share, Propagator& p,
00068                       View x0, CtrlView b);
00070     ReUnaryPropagator(Space* home, View x0, CtrlView b);
00071   public:
00073     virtual PropCost cost(ModEventDelta med) const;
00075     virtual size_t dispose(Space* home);
00077     Reflection::ActorSpec spec(const Space* home, Reflection::VarMap& m,
00078                                 const Support::Symbol& name) const;
00079   };
00080 
00091   template <class View, PropCond pc, class CtrlView>
00092   class ReBinaryPropagator : public Propagator {
00093   protected:
00095     View x0, x1;
00097     CtrlView b;
00099     ReBinaryPropagator(Space* home, bool share, ReBinaryPropagator& p);
00101     ReBinaryPropagator(Space* home, bool share, Propagator& p,
00102                        View x0, View x1, CtrlView b);
00104     ReBinaryPropagator(Space* home, View x0, View x1, CtrlView b);
00105   public:
00107     virtual PropCost cost(ModEventDelta med) const;
00109     virtual size_t dispose(Space* home);
00111     Reflection::ActorSpec spec(const Space* home, Reflection::VarMap& m,
00112                                 const Support::Symbol& name) const;
00113   };
00115 
00116 
00117 
00118   /*
00119    * Reified unary propagators
00120    *
00121    */
00122   template <class View, PropCond pc, class CtrlView>
00123   ReUnaryPropagator<View,pc,CtrlView>::ReUnaryPropagator
00124   (Space* home, View y0, CtrlView b0)
00125     : Propagator(home), x0(y0), b(b0) {
00126     if (pc != PC_GEN_NONE)
00127       x0.subscribe(home,this,pc);
00128     b.subscribe(home,this,Int::PC_INT_VAL);
00129   }
00130 
00131   template <class View, PropCond pc, class CtrlView>
00132   forceinline
00133   ReUnaryPropagator<View,pc,CtrlView>::ReUnaryPropagator
00134   (Space* home, bool share, ReUnaryPropagator<View,pc,CtrlView>& p)
00135     : Propagator(home,share,p) {
00136     x0.update(home,share,p.x0);
00137     b.update(home,share,p.b);
00138   }
00139 
00140   template <class View, PropCond pc, class CtrlView>
00141   forceinline
00142   ReUnaryPropagator<View,pc,CtrlView>::ReUnaryPropagator
00143   (Space* home, bool share, Propagator& p, View y0, CtrlView b0)
00144     : Propagator(home,share,p) {
00145     x0.update(home,share,y0);
00146     b.update(home,share,b0);
00147   }
00148 
00149   template <class View, PropCond pc, class CtrlView>
00150   PropCost
00151   ReUnaryPropagator<View,pc,CtrlView>::cost(ModEventDelta) const {
00152     return PC_UNARY_LO;
00153   }
00154 
00155   template <class View, PropCond pc, class CtrlView>
00156   forceinline size_t
00157   ReUnaryPropagator<View,pc,CtrlView>::dispose(Space* home) {
00158     if (pc != PC_GEN_NONE)
00159       x0.cancel(home,this,pc);
00160     b.cancel(home,this,Int::PC_INT_VAL);
00161     (void) Propagator::dispose(home);
00162     return sizeof(*this);
00163   }
00164 
00165   template <class View, PropCond pc, class CtrlView>
00166   Reflection::ActorSpec
00167   ReUnaryPropagator<View,pc,CtrlView>::spec(const Space* home,
00168     Reflection::VarMap& m, const Support::Symbol& name) const {
00169     Reflection::ActorSpec s(name);
00170     return s << x0.spec(home, m)
00171              << b.spec(home, m);
00172   }
00173 
00174   /*
00175    * Reified binary propagators
00176    *
00177    */
00178   template <class View, PropCond pc, class CtrlView>
00179   ReBinaryPropagator<View,pc,CtrlView>::ReBinaryPropagator
00180   (Space* home, View y0, View y1, CtrlView b1)
00181     : Propagator(home), x0(y0), x1(y1), b(b1) {
00182     if (pc != PC_GEN_NONE) {
00183       x0.subscribe(home,this,pc);
00184       x1.subscribe(home,this,pc);
00185     }
00186     b.subscribe(home,this,Int::PC_INT_VAL);
00187   }
00188 
00189   template <class View, PropCond pc, class CtrlView>
00190   forceinline
00191   ReBinaryPropagator<View,pc,CtrlView>::ReBinaryPropagator
00192   (Space* home, bool share, ReBinaryPropagator<View,pc,CtrlView>& p)
00193     : Propagator(home,share,p) {
00194     x0.update(home,share,p.x0);
00195     x1.update(home,share,p.x1);
00196     b.update(home,share,p.b);
00197   }
00198 
00199   template <class View, PropCond pc, class CtrlView>
00200   forceinline
00201   ReBinaryPropagator<View,pc,CtrlView>::ReBinaryPropagator
00202   (Space* home, bool share, Propagator& p, View y0, View y1, CtrlView b0)
00203     : Propagator(home,share,p) {
00204     x0.update(home,share,y0);
00205     x1.update(home,share,y1);
00206     b.update(home,share,b0);
00207   }
00208 
00209   template <class View, PropCond pc, class CtrlView>
00210   PropCost
00211   ReBinaryPropagator<View,pc,CtrlView>::cost(ModEventDelta) const {
00212     return PC_BINARY_LO;
00213   }
00214 
00215   template <class View, PropCond pc, class CtrlView>
00216   forceinline size_t
00217   ReBinaryPropagator<View,pc,CtrlView>::dispose(Space* home) {
00218     if (pc != PC_GEN_NONE) {
00219       x0.cancel(home,this,pc);
00220       x1.cancel(home,this,pc);
00221     }
00222     b.cancel(home,this,Int::PC_INT_VAL);
00223     (void) Propagator::dispose(home);
00224     return sizeof(*this);
00225   }
00226 
00227   template <class View, PropCond pc, class CtrlView>
00228   Reflection::ActorSpec
00229   ReBinaryPropagator<View,pc,CtrlView>::spec(const Space* home,
00230     Reflection::VarMap& m, const Support::Symbol& name) const {
00231     Reflection::ActorSpec s(name);
00232     return s << x0.spec(home, m)
00233              << x1.spec(home, m)
00234              << b.spec(home, m);
00235   }
00236 
00237 }
00238 
00239 // STATISTICS: int-prop
00240