Generated on Mon Nov 30 23:53:29 2009 for Gecode by doxygen 1.6.1

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  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2004, 2005
00008  *
00009  *  Last modified:
00010  *     $Date: 2009-09-08 21:10:29 +0200 (Tue, 08 Sep 2009) $ by $Author: schulte $
00011  *     $Revision: 9692 $
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 
00049 
00050 
00057   template<class View, PropCond pcs, PropCond pci>
00058   class IntSetPropagator : public Propagator {
00059   protected:
00060     View x0;
00061     Gecode::Int::IntView x1;
00063     IntSetPropagator(Space& home,bool,IntSetPropagator&);
00065     IntSetPropagator(Space& home,View,Gecode::Int::IntView);
00066   public:
00068     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00070     virtual size_t dispose(Space& home);
00071   };
00072 
00079   template<class View, PropCond pcs, PropCond pci>
00080   class IntSetRePropagator : public Propagator {
00081   protected:
00082     View x0;
00083     Gecode::Int::IntView x1;
00084     Gecode::Int::BoolView b;
00086     IntSetRePropagator(Space& home,bool,IntSetRePropagator&);
00088     IntSetRePropagator(Space& home,View,Gecode::Int::IntView,
00089                        Gecode::Int::BoolView);
00090   public:
00092     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00094     virtual size_t dispose(Space& home);
00095   };
00096 
00098 
00099   template<class View, PropCond pcs, PropCond pci>
00100   IntSetPropagator<View,pcs,pci>::IntSetPropagator
00101   (Space& home, View y0, Gecode::Int::IntView y1)
00102     : Propagator(home), x0(y0), x1(y1) {
00103     x0.subscribe(home,*this,pcs);
00104     x1.subscribe(home,*this,pci);
00105   }
00106 
00107   template<class View, PropCond pcs, PropCond pci>
00108   forceinline
00109   IntSetPropagator<View,pcs,pci>::IntSetPropagator
00110   (Space& home, bool share, IntSetPropagator<View,pcs,pci>& p)
00111     : Propagator(home,share,p) {
00112     x0.update(home,share,p.x0);
00113     x1.update(home,share,p.x1);
00114   }
00115 
00116   template<class View, PropCond pcs, PropCond pci>
00117   PropCost
00118   IntSetPropagator<View,pcs,pci>::cost(const Space&,
00119                                        const ModEventDelta&) const {
00120     return PropCost::binary(PropCost::LO);
00121   }
00122 
00123   template<class View, PropCond pcs, PropCond pci>
00124   size_t
00125   IntSetPropagator<View,pcs,pci>::dispose(Space& home) {
00126     if (!home.failed()) {
00127       x0.cancel(home,*this,pcs);
00128       x1.cancel(home,*this,pci);
00129     }
00130     (void) Propagator::dispose(home);
00131     return sizeof(*this);
00132   }
00133 
00134   template<class View, PropCond pcs, PropCond pci>
00135   IntSetRePropagator<View,pcs,pci>::IntSetRePropagator
00136   (Space& home, View y0, Gecode::Int::IntView y1, Gecode::Int::BoolView b2)
00137     : Propagator(home), x0(y0), x1(y1), b(b2) {
00138     x0.subscribe(home,*this,pcs);
00139     x1.subscribe(home,*this,pci);
00140     b.subscribe(home,*this,Gecode::Int::PC_INT_VAL);
00141   }
00142 
00143   template<class View, PropCond pcs, PropCond pci>
00144   forceinline
00145   IntSetRePropagator<View,pcs,pci>::IntSetRePropagator
00146   (Space& home, bool share, IntSetRePropagator<View,pcs,pci>& p)
00147     : Propagator(home,share,p) {
00148     x0.update(home,share,p.x0);
00149     x1.update(home,share,p.x1);
00150     b.update(home,share,p.b);
00151   }
00152 
00153   template<class View, PropCond pcs, PropCond pci>
00154   PropCost
00155   IntSetRePropagator<View,pcs,pci>
00156   ::cost(const Space&, const ModEventDelta&) const {
00157     return PropCost::ternary(PropCost::LO);
00158   }
00159 
00160   template<class View, PropCond pcs, PropCond pci>
00161   size_t
00162   IntSetRePropagator<View,pcs,pci>::dispose(Space& home) {
00163     if (!home.failed()) {
00164       x0.cancel(home,*this,pcs);
00165       x1.cancel(home,*this,pci);
00166       b.cancel(home,*this,Gecode::Int::PC_INT_VAL);
00167     }
00168     (void) Propagator::dispose(home);
00169     return sizeof(*this);
00170   }
00171 
00172 }
00173 
00174 // STATISTICS: set-prop
00175