Generated on Thu Apr 11 13:59:12 2019 for Gecode by doxygen 1.6.3

propagator.hpp

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  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 namespace Gecode { namespace Int {
00035 
00053   template<class View, PropCond pc, class CtrlView>
00054   class ReUnaryPropagator : public Propagator {
00055   protected:
00057     View x0;
00059     CtrlView b;
00061     ReUnaryPropagator(Space& home, ReUnaryPropagator& p);
00063     ReUnaryPropagator(Space& home, Propagator& p,
00064                       View x0, CtrlView b);
00066     ReUnaryPropagator(Home home, View x0, CtrlView b);
00067   public:
00069     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00071     virtual void reschedule(Space& home);
00073     virtual size_t dispose(Space& home);
00074   };
00075 
00086   template<class View, PropCond pc, class CtrlView>
00087   class ReBinaryPropagator : public Propagator {
00088   protected:
00090     View x0, x1;
00092     CtrlView b;
00094     ReBinaryPropagator(Space& home, ReBinaryPropagator& p);
00096     ReBinaryPropagator(Space& home, Propagator& p,
00097                        View x0, View x1, CtrlView b);
00099     ReBinaryPropagator(Home home, View x0, View x1, CtrlView b);
00100   public:
00102     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00104     virtual void reschedule(Space& home);
00106     virtual size_t dispose(Space& home);
00107   };
00109 
00110 
00122   template<class View0, PropCond pc0, class View1, PropCond pc1,
00123            class CtrlView>
00124   class ReMixBinaryPropagator : public Propagator {
00125   protected:
00127     View0 x0;
00129     View1 x1;
00131     CtrlView b;
00133     ReMixBinaryPropagator(Space& home, ReMixBinaryPropagator& p);
00135     ReMixBinaryPropagator(Home home, View0 x0, View1 x1, CtrlView b);
00137     ReMixBinaryPropagator(Space& home, Propagator& p,
00138                           View0 x0, View1 x1, CtrlView b);
00139   public:
00141     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00143     virtual void reschedule(Space& home);
00145     virtual size_t dispose(Space& home);
00146   };
00147 
00148 
00149   /*
00150    * Reified unary propagators
00151    *
00152    */
00153   template<class View, PropCond pc, class CtrlView>
00154   ReUnaryPropagator<View,pc,CtrlView>::ReUnaryPropagator
00155   (Home home, View y0, CtrlView b0)
00156     : Propagator(home), x0(y0), b(b0) {
00157     if (pc != PC_GEN_NONE)
00158       x0.subscribe(home,*this,pc);
00159     b.subscribe(home,*this,Int::PC_INT_VAL);
00160   }
00161 
00162   template<class View, PropCond pc, class CtrlView>
00163   forceinline
00164   ReUnaryPropagator<View,pc,CtrlView>::ReUnaryPropagator
00165   (Space& home, ReUnaryPropagator<View,pc,CtrlView>& p)
00166     : Propagator(home,p) {
00167     x0.update(home,p.x0);
00168     b.update(home,p.b);
00169   }
00170 
00171   template<class View, PropCond pc, class CtrlView>
00172   forceinline
00173   ReUnaryPropagator<View,pc,CtrlView>::ReUnaryPropagator
00174   (Space& home, Propagator& p, View y0, CtrlView b0)
00175     : Propagator(home,p) {
00176     x0.update(home,y0);
00177     b.update(home,b0);
00178   }
00179 
00180   template<class View, PropCond pc, class CtrlView>
00181   PropCost
00182   ReUnaryPropagator<View,pc,CtrlView>::cost(const Space&, const ModEventDelta&) const {
00183     return PropCost::unary(PropCost::LO);
00184   }
00185 
00186   template<class View, PropCond pc, class CtrlView>
00187   void
00188   ReUnaryPropagator<View,pc,CtrlView>::reschedule(Space& home) {
00189     if (pc != PC_GEN_NONE)
00190       x0.reschedule(home,*this,pc);
00191     b.reschedule(home,*this,Int::PC_INT_VAL);
00192   }
00193 
00194   template<class View, PropCond pc, class CtrlView>
00195   forceinline size_t
00196   ReUnaryPropagator<View,pc,CtrlView>::dispose(Space& home) {
00197     if (pc != PC_GEN_NONE)
00198       x0.cancel(home,*this,pc);
00199     b.cancel(home,*this,Int::PC_INT_VAL);
00200     (void) Propagator::dispose(home);
00201     return sizeof(*this);
00202   }
00203 
00204   /*
00205    * Reified binary propagators
00206    *
00207    */
00208   template<class View, PropCond pc, class CtrlView>
00209   ReBinaryPropagator<View,pc,CtrlView>::ReBinaryPropagator
00210   (Home home, View y0, View y1, CtrlView b1)
00211     : Propagator(home), x0(y0), x1(y1), b(b1) {
00212     if (pc != PC_GEN_NONE) {
00213       x0.subscribe(home,*this,pc);
00214       x1.subscribe(home,*this,pc);
00215     }
00216     b.subscribe(home,*this,Int::PC_INT_VAL);
00217   }
00218 
00219   template<class View, PropCond pc, class CtrlView>
00220   forceinline
00221   ReBinaryPropagator<View,pc,CtrlView>::ReBinaryPropagator
00222   (Space& home, ReBinaryPropagator<View,pc,CtrlView>& p)
00223     : Propagator(home,p) {
00224     x0.update(home,p.x0);
00225     x1.update(home,p.x1);
00226     b.update(home,p.b);
00227   }
00228 
00229   template<class View, PropCond pc, class CtrlView>
00230   forceinline
00231   ReBinaryPropagator<View,pc,CtrlView>::ReBinaryPropagator
00232   (Space& home, Propagator& p, View y0, View y1, CtrlView b0)
00233     : Propagator(home,p) {
00234     x0.update(home,y0);
00235     x1.update(home,y1);
00236     b.update(home,b0);
00237   }
00238 
00239   template<class View, PropCond pc, class CtrlView>
00240   PropCost
00241   ReBinaryPropagator<View,pc,CtrlView>::cost(const Space&, const ModEventDelta&) const {
00242     return PropCost::binary(PropCost::LO);
00243   }
00244 
00245   template<class View, PropCond pc, class CtrlView>
00246   void
00247   ReBinaryPropagator<View,pc,CtrlView>::reschedule(Space& home) {
00248     if (pc != PC_GEN_NONE) {
00249       x0.reschedule(home,*this,pc);
00250       x1.reschedule(home,*this,pc);
00251     }
00252     b.reschedule(home,*this,Int::PC_INT_VAL);
00253   }
00254 
00255   template<class View, PropCond pc, class CtrlView>
00256   forceinline size_t
00257   ReBinaryPropagator<View,pc,CtrlView>::dispose(Space& home) {
00258     if (pc != PC_GEN_NONE) {
00259       x0.cancel(home,*this,pc);
00260       x1.cancel(home,*this,pc);
00261     }
00262     b.cancel(home,*this,Int::PC_INT_VAL);
00263     (void) Propagator::dispose(home);
00264     return sizeof(*this);
00265   }
00266 
00267   /*
00268    * Reified mixed binary propagator
00269    *
00270    */
00271   template<class View0, PropCond pc0, class View1, PropCond pc1,
00272             class CtrlView>
00273   ReMixBinaryPropagator<View0,pc0,View1,pc1,CtrlView>
00274   ::ReMixBinaryPropagator(Home home, View0 y0, View1 y1, CtrlView b1)
00275     : Propagator(home), x0(y0), x1(y1), b(b1) {
00276     if (pc0 != PC_GEN_NONE)
00277       x0.subscribe(home,*this,pc0);
00278     if (pc1 != PC_GEN_NONE)
00279       x1.subscribe(home,*this,pc1);
00280     b.subscribe(home,*this,Int::PC_INT_VAL);
00281   }
00282 
00283   template<class View0, PropCond pc0, class View1, PropCond pc1,
00284             class CtrlView>
00285   forceinline
00286   ReMixBinaryPropagator<View0,pc0,View1,pc1,CtrlView>::ReMixBinaryPropagator
00287   (Space& home,
00288    ReMixBinaryPropagator<View0,pc0,View1,pc1,CtrlView>& p)
00289     : Propagator(home,p) {
00290     x0.update(home,p.x0);
00291     x1.update(home,p.x1);
00292     b.update(home,p.b);
00293   }
00294 
00295   template<class View0, PropCond pc0, class View1, PropCond pc1,
00296             class CtrlView>
00297   forceinline
00298   ReMixBinaryPropagator<View0,pc0,View1,pc1,CtrlView>
00299   ::ReMixBinaryPropagator
00300   (Space& home, Propagator& p, View0 y0, View1 y1, CtrlView b0)
00301     : Propagator(home,p) {
00302     x0.update(home,y0);
00303     x1.update(home,y1);
00304     b.update(home,b0);
00305   }
00306 
00307   template<class View0, PropCond pc0, class View1, PropCond pc1,
00308             class CtrlView>
00309   PropCost
00310   ReMixBinaryPropagator<View0,pc0,View1,pc1,CtrlView>
00311   ::cost(const Space&, const ModEventDelta&) const {
00312     return PropCost::binary(PropCost::LO);
00313   }
00314 
00315   template<class View0, PropCond pc0, class View1, PropCond pc1,
00316             class CtrlView>
00317   void
00318   ReMixBinaryPropagator<View0,pc0,View1,pc1,CtrlView>::reschedule(Space& home) {
00319     if (pc0 != PC_GEN_NONE)
00320       x0.reschedule(home,*this,pc0);
00321     if (pc1 != PC_GEN_NONE)
00322       x1.reschedule(home,*this,pc1);
00323     b.reschedule(home,*this,Int::PC_INT_VAL);
00324   }
00325 
00326   template<class View0, PropCond pc0, class View1, PropCond pc1,
00327             class CtrlView>
00328   forceinline size_t
00329   ReMixBinaryPropagator<View0,pc0,View1,pc1,CtrlView>::dispose(Space& home) {
00330     if (pc0 != PC_GEN_NONE)
00331       x0.cancel(home,*this,pc0);
00332     if (pc1 != PC_GEN_NONE)
00333       x1.cancel(home,*this,pc1);
00334     b.cancel(home,*this,Int::PC_INT_VAL);
00335     (void) Propagator::dispose(home);
00336     return sizeof(*this);
00337   }
00338 
00339 }}
00340 
00341 // STATISTICS: int-prop
00342