Generated on Mon May 10 06:46:36 2010 for Gecode by doxygen 1.6.3

element.hh

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  *     Guido Tack <tack@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2004
00009  *     Guido Tack, 2004
00010  *
00011  *  Last modified:
00012  *     $Date: 2009-11-03 11:29:41 +0100 (Tue, 03 Nov 2009) $ by $Author: schulte $
00013  *     $Revision: 10026 $
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_INT_ELEMENT_HH__
00041 #define __GECODE_INT_ELEMENT_HH__
00042 
00043 #include <gecode/int.hh>
00044 #include <gecode/int/rel.hh>
00045 
00051 namespace Gecode { namespace Int { namespace Element {
00052 
00059   template<class V0, class V1, class Idx, class Val>
00060   class Int : public Propagator {
00061   protected:
00070     class IdxVal  {
00071     public:
00072       Idx idx_next; 
00073       Idx val_next; 
00074       Idx idx; 
00075       Val val; 
00076 
00077       void mark(void);
00079       bool marked(void) const;
00080     };
00087     class IterIdx {
00088     private:
00089       IdxVal* iv; 
00090       Idx i; 
00091     public:
00093       IterIdx(IdxVal* iv);
00095       bool operator ()(void) const;
00097       void operator ++(void);
00099       Idx val(void) const;
00100     };
00107     class IterVal {
00108     private:
00109       IdxVal* iv; 
00110       Idx i; 
00111     public:
00113       IterVal(IdxVal* iv);
00115       bool operator ()(void) const;
00117       void operator ++(void);
00119       Val val(void) const;
00120     };
00122     class ByVal {
00123     protected:
00124       const IdxVal* iv; 
00125     public:
00127       ByVal(const IdxVal* iv);
00129       bool operator ()(Idx& i, Idx& j);
00130     };
00131 
00133     V0 x0;
00135     V1 x1;
00137     IntSharedArray c;
00139     IdxVal* iv;
00141     Int(Space& home, bool shared, Int& p);
00143     Int(Home home, IntSharedArray& i, V0 x0, V1 x1);
00144   public:
00146     virtual Actor* copy(Space& home, bool share);
00148     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00150     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00152     static  ExecStatus post(Home home, IntSharedArray& i, V0 x0, V1 x1);
00154     virtual size_t dispose(Space& home);
00155   };
00156 
00158   template<class V0, class V1>
00159   ExecStatus post_int(Home home, IntSharedArray& c, V0 x0, V1 x1);
00160 
00161 
00166   template<class ViewB> class IdxView;
00167 
00169   template<class View>
00170   class ViewToVarArg {};
00171 
00176   template<class View>
00177   class IdxViewArray {
00178   private:
00180     IdxView<View>* xs;
00182     int n;
00183   public:
00185     IdxViewArray(void);
00187     IdxViewArray(const IdxViewArray<View>&);
00189     IdxViewArray(Space& home, const typename ViewToVarArg<View>::argtype& x);
00191     IdxViewArray(Space& home, int n);
00192 
00194     int size(void) const;
00196     void size(int n);
00197 
00199     IdxView<View>& operator [](int n);
00201     const IdxView<View>& operator [](int) const;
00202 
00207     void subscribe(Space& home, Propagator& p, PropCond pc, bool process=true);
00212     void cancel(Space& home, Propagator& p, PropCond pc);
00213 
00215     void update(Space& home, bool share, IdxViewArray<View>& x);
00216   };
00217 
00222   template<class VA, class VB, class VC, PropCond pc_ac>
00223   class View : public Propagator {
00224   protected:
00226     IdxViewArray<VA> iv;
00228     VB x0;
00230     VC x1;
00232     View(Space& home, bool share, View& p);
00234     View(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
00235   public:
00236     // Cost function (defined as low linear)
00237     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00239     virtual size_t dispose(Space& home);
00240   };
00241 
00242 
00249   template<class VA, class VB, class VC>
00250   class ViewBnd : public View<VA,VB,VC,PC_INT_BND> {
00251   protected:
00252     using View<VA,VB,VC,PC_INT_BND>::iv;
00253     using View<VA,VB,VC,PC_INT_BND>::x0;
00254     using View<VA,VB,VC,PC_INT_BND>::x1;
00255 
00257     ViewBnd(Space& home, bool share, ViewBnd& p);
00259     ViewBnd(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
00260   public:
00262     virtual Actor* copy(Space& home, bool share);
00264     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00266     static  ExecStatus post(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
00267   };
00268 
00279   template<class VA, class VB, class VC>
00280   class ViewDom : public View<VA,VB,VC,PC_INT_DOM> {
00281   protected:
00282     using View<VA,VB,VC,PC_INT_DOM>::iv;
00283     using View<VA,VB,VC,PC_INT_DOM>::x0;
00284     using View<VA,VB,VC,PC_INT_DOM>::x1;
00285 
00287     ViewDom(Space& home, bool share, ViewDom& p);
00289     ViewDom(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
00290   public:
00292     virtual Actor* copy(Space& home, bool share);
00300     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00302     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00304     static  ExecStatus post(Home home, IdxViewArray<VA>& iv,
00305                             VB x0, VC x1);
00306   };
00307 
00315   class GECODE_VTABLE_EXPORT Pair 
00316     : public TernaryPropagator<IntView,PC_INT_DOM> {
00317   protected:
00318     using TernaryPropagator<IntView,PC_INT_DOM>::x0;
00319     using TernaryPropagator<IntView,PC_INT_DOM>::x1;
00320     using TernaryPropagator<IntView,PC_INT_DOM>::x2;
00322     int w;
00324     Pair(Space& home, bool share, Pair& p);
00325   public:
00327     Pair(Home home, IntView x0, IntView x1, IntView x2, int w);
00329     static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2, 
00330                            int w, int h);
00332     GECODE_INT_EXPORT virtual Actor* copy(Space& home, bool share);
00334     GECODE_INT_EXPORT virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00335   };
00336 
00337 }}}
00338 
00339 #include <gecode/int/element/int.hpp>
00340 #include <gecode/int/element/view.hpp>
00341 #include <gecode/int/element/pair.hpp>
00342 
00343 #endif
00344 
00345 
00346 // STATISTICS: int-prop
00347