Generated on Thu Mar 22 10:39:32 2012 for Gecode by doxygen 1.6.3

int.hh

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  *     Christian Schulte <schulte@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Guido Tack, 2004
00009  *     Christian Schulte, 2004
00010  *
00011  *  Last modified:
00012  *     $Date: 2011-05-02 00:24:42 +0200 (Mon, 02 May 2011) $ by $Author: tack $
00013  *     $Revision: 11973 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 #ifndef __GECODE_SET_INT_HH__
00041 #define __GECODE_SET_INT_HH__
00042 
00043 #include <gecode/set.hh>
00044 
00045 namespace Gecode { namespace Set { namespace Int {
00046 
00058   template<class View>
00059   class MinElement :
00060     public MixBinaryPropagator<View,PC_SET_ANY,
00061       Gecode::Int::IntView,Gecode::Int::PC_INT_BND> {
00062   protected:
00063     using MixBinaryPropagator<View,PC_SET_ANY,
00064       Gecode::Int::IntView,Gecode::Int::PC_INT_BND>::x0;
00065     using MixBinaryPropagator<View,PC_SET_ANY,
00066       Gecode::Int::IntView,Gecode::Int::PC_INT_BND>::x1;
00068     MinElement(Space& home, bool share,MinElement& p);
00070     MinElement(Home home, View, Gecode::Int::IntView);
00071   public:
00073     virtual Actor* copy(Space& home,bool);
00075     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00077     static ExecStatus post(Home home, View s, Gecode::Int::IntView x);
00078   };
00079 
00086   template<class View>
00087   class NotMinElement :
00088     public MixBinaryPropagator<View,PC_SET_ANY,
00089       Gecode::Int::IntView,Gecode::Int::PC_INT_DOM> {
00090   protected:
00091     using MixBinaryPropagator<View,PC_SET_ANY,
00092       Gecode::Int::IntView,Gecode::Int::PC_INT_DOM>::x0;
00093     using MixBinaryPropagator<View,PC_SET_ANY,
00094       Gecode::Int::IntView,Gecode::Int::PC_INT_DOM>::x1;
00096     NotMinElement(Space& home, bool share,NotMinElement& p);
00098     NotMinElement(Home home, View, Gecode::Int::IntView);
00099   public:
00101     virtual Actor* copy(Space& home,bool);
00103     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00105     static ExecStatus post(Home home, View s, Gecode::Int::IntView x);
00106   };
00107 
00114   template<class View>
00115   class ReMinElement :
00116     public Gecode::Int::ReMixBinaryPropagator<View,PC_SET_ANY,
00117       Gecode::Int::IntView,Gecode::Int::PC_INT_DOM,Gecode::Int::BoolView> {
00118   protected:
00119     using Gecode::Int::ReMixBinaryPropagator<View,PC_SET_ANY,
00120       Gecode::Int::IntView,Gecode::Int::PC_INT_DOM,Gecode::Int::BoolView>::x0;
00121     using Gecode::Int::ReMixBinaryPropagator<View,PC_SET_ANY,
00122       Gecode::Int::IntView,Gecode::Int::PC_INT_DOM,Gecode::Int::BoolView>::x1;
00123     using Gecode::Int::ReMixBinaryPropagator<View,PC_SET_ANY,
00124       Gecode::Int::IntView,Gecode::Int::PC_INT_DOM,Gecode::Int::BoolView>::b;
00126     ReMinElement(Space& home, bool share,ReMinElement& p);
00128     ReMinElement(Home home, View, Gecode::Int::IntView,
00129                  Gecode::Int::BoolView);
00130   public:
00132     virtual Actor* copy(Space& home,bool);
00134     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00136     static ExecStatus post(Home home, View s, Gecode::Int::IntView x,
00137                            Gecode::Int::BoolView b);
00138   };
00139 
00146   template<class View>
00147   class MaxElement :
00148     public MixBinaryPropagator<View,PC_SET_ANY,Gecode::Int::IntView,Gecode::Int::PC_INT_BND> {
00149   protected:
00150     using MixBinaryPropagator<View,PC_SET_ANY,
00151       Gecode::Int::IntView,Gecode::Int::PC_INT_BND>::x0;
00152     using MixBinaryPropagator<View,PC_SET_ANY,
00153       Gecode::Int::IntView,Gecode::Int::PC_INT_BND>::x1;
00155     MaxElement(Space& home, bool share,MaxElement& p);
00157     MaxElement(Home home, View, Gecode::Int::IntView);
00158   public:
00160     virtual Actor* copy(Space& home,bool);
00162     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00164     static ExecStatus post(Home home, View s, Gecode::Int::IntView x);
00165   };
00166 
00173   template<class View>
00174   class NotMaxElement :
00175     public MixBinaryPropagator<View,PC_SET_ANY,
00176       Gecode::Int::IntView,Gecode::Int::PC_INT_DOM> {
00177   protected:
00178     using MixBinaryPropagator<View,PC_SET_ANY,
00179       Gecode::Int::IntView,Gecode::Int::PC_INT_DOM>::x0;
00180     using MixBinaryPropagator<View,PC_SET_ANY,
00181       Gecode::Int::IntView,Gecode::Int::PC_INT_DOM>::x1;
00183     NotMaxElement(Space& home, bool share,NotMaxElement& p);
00185     NotMaxElement(Home home, View, Gecode::Int::IntView);
00186   public:
00188     virtual Actor* copy(Space& home,bool);
00190     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00192     static ExecStatus post(Home home, View s, Gecode::Int::IntView x);
00193   };
00194 
00201   template<class View>
00202   class ReMaxElement :
00203     public Gecode::Int::ReMixBinaryPropagator<View,PC_SET_ANY,
00204       Gecode::Int::IntView,Gecode::Int::PC_INT_DOM,Gecode::Int::BoolView> {
00205   protected:
00206     using Gecode::Int::ReMixBinaryPropagator<View,PC_SET_ANY,
00207       Gecode::Int::IntView,Gecode::Int::PC_INT_DOM,Gecode::Int::BoolView>::x0;
00208     using Gecode::Int::ReMixBinaryPropagator<View,PC_SET_ANY,
00209       Gecode::Int::IntView,Gecode::Int::PC_INT_DOM,Gecode::Int::BoolView>::x1;
00210     using Gecode::Int::ReMixBinaryPropagator<View,PC_SET_ANY,
00211       Gecode::Int::IntView,Gecode::Int::PC_INT_DOM,Gecode::Int::BoolView>::b;
00213     ReMaxElement(Space& home, bool share,ReMaxElement& p);
00215     ReMaxElement(Home home, View, Gecode::Int::IntView, Gecode::Int::BoolView);
00216   public:
00218     virtual Actor* copy(Space& home,bool);
00220     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00222     static ExecStatus post(Home home, View s, Gecode::Int::IntView x,
00223                            Gecode::Int::BoolView b);
00224   };
00225 
00232   template<class View>
00233   class Card :
00234     public MixBinaryPropagator<View,PC_SET_CARD,
00235       Gecode::Int::IntView,Gecode::Int::PC_INT_BND> {
00236   protected:
00237     using MixBinaryPropagator<View,PC_SET_CARD,
00238       Gecode::Int::IntView,Gecode::Int::PC_INT_BND>::x0;
00239     using MixBinaryPropagator<View,PC_SET_CARD,
00240       Gecode::Int::IntView,Gecode::Int::PC_INT_BND>::x1;
00242     Card(Space& home, bool share,Card& p);
00244     Card(Home home, View, Gecode::Int::IntView);
00245   public:
00247     virtual Actor* copy(Space& home,bool);
00249     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00251     static ExecStatus post(Home home, View s, Gecode::Int::IntView x);
00252   };
00253 
00254 
00261   template<class View>
00262   class Match : public Propagator {
00263   protected:
00265     View x0;
00267     ViewArray<Gecode::Int::IntView> xs;
00268 
00270     Match(Space& home, bool share,Match& p);
00272     Match(Home home, View, ViewArray<Gecode::Int::IntView>&);
00273   public:
00275     virtual Actor* copy(Space& home,bool);
00277     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00279     virtual size_t dispose(Space& home);
00281     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00283     static ExecStatus post(Home home, View s,
00284                            ViewArray<Gecode::Int::IntView>& x);
00285   };
00286 
00304   template<class View>
00305   class ChannelInt : public Propagator {
00306   protected:
00308     ViewArray<Gecode::Int::CachedView<Gecode::Int::IntView> > xs;
00310     ViewArray<CachedView<View> > ys;
00311 
00313     ChannelInt(Space& home, bool share,ChannelInt& p);
00315     ChannelInt(Home home,
00316                ViewArray<Gecode::Int::CachedView<Gecode::Int::IntView> >&,
00317                ViewArray<CachedView<View> >&);
00318   public:
00320     virtual Actor*   copy(Space& home,bool);
00322     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00324     virtual size_t dispose(Space& home);
00326     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00328     static ExecStatus post(Home home,
00329                            ViewArray<Gecode::Int::CachedView<
00330                             Gecode::Int::IntView> >& x,
00331                            ViewArray<CachedView<View> >& y);
00332   };
00333 
00345   template<class View>
00346   class ChannelBool
00347     : public MixNaryOnePropagator<Gecode::Int::BoolView,
00348                                   Gecode::Int::PC_BOOL_VAL,
00349                                   View,PC_GEN_NONE> {
00350   protected:
00351     typedef MixNaryOnePropagator<Gecode::Int::BoolView,
00352                                  Gecode::Int::PC_BOOL_VAL,
00353                                  View,PC_GEN_NONE> Super;
00354     using Super::x;
00355     using Super::y;
00356 
00358     ChannelBool(Space& home, bool share,ChannelBool& p);
00360     ChannelBool(Home home,ViewArray<Gecode::Int::BoolView>&,
00361                 View);
00362 
00364     class IndexAdvisor : public Advisor {
00365     protected:
00367       int idx;
00368     public:
00370       template<class A>
00371       IndexAdvisor(Space& home, ChannelBool<View>& p, Council<A>& c,
00372                    int index);
00374       IndexAdvisor(Space& home, bool share, IndexAdvisor& a);
00376       int index(void) const;
00378       template<class A>
00379       void dispose(Space& home, Council<A>& c);
00380     };
00381 
00383     Council<IndexAdvisor> co;
00385     SetDelta delta;
00387     GLBndSet zeros;
00389     GLBndSet ones;
00391     bool running;
00392   public:
00394     virtual Actor*   copy(Space& home,bool);
00396     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00398     virtual size_t dispose(Space& home);
00400     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00402     virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
00404     static ExecStatus post(Home home,ViewArray<Gecode::Int::BoolView>& x,
00405                            View y);
00406   };
00407 
00414   template<class View>
00415   class Weights : public Propagator {
00416   protected:
00418     SharedArray<int> elements;
00420     SharedArray<int> weights;
00421 
00423     View x;
00425     Gecode::Int::IntView y;
00426 
00428     Weights(Space& home, bool share,Weights& p);
00430     Weights(Home home, const SharedArray<int>&, const SharedArray<int>&,
00431             View, Gecode::Int::IntView);
00432   public:
00434     virtual Actor* copy(Space& home,bool);
00436     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00438     virtual size_t dispose(Space& home);
00440     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00442     static ExecStatus post(Home home,
00443                            const SharedArray<int>& elements,
00444                            const SharedArray<int>& weights,
00445                            View x, Gecode::Int::IntView y);
00446   };
00447 
00448 }}}
00449 
00450 #include <gecode/set/int/minmax.hpp>
00451 #include <gecode/set/int/card.hpp>
00452 #include <gecode/set/int/match.hpp>
00453 #include <gecode/set/int/channel-int.hpp>
00454 #include <gecode/set/int/channel-bool.hpp>
00455 #include <gecode/set/int/weights.hpp>
00456 
00457 #endif
00458 
00459 // STATISTICS: set-prop