Generated on Mon Jul 6 18:09:08 2009 for Gecode by doxygen 1.5.9

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-02-26 23:09:33 +0100 (Thu, 26 Feb 2009) $ by $Author: tack $
00013  *     $Revision: 8305 $
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 
00053   /*
00054    * Element constraint for array of integers
00055    *
00056    */
00057 
00058   typedef SharedArray<int> IntSharedArray;
00059 
00066   template <class V0, class V1, class Idx, class Val>
00067   class Int : public Propagator {
00068   protected:
00077     class IdxVal  {
00078     public:
00079       Idx idx_next; 
00080       Idx val_next; 
00081       Idx idx; 
00082       Val val; 
00083 
00084       void mark(void);
00086       bool marked(void) const;
00087     };
00094     class IterIdx {
00095     private:
00096       IdxVal* iv; 
00097       Idx i; 
00098     public:
00100       IterIdx(IdxVal* iv);
00102       bool operator ()(void) const;
00104       void operator ++(void);
00106       Idx val(void) const;
00107     };
00114     class IterVal {
00115     private:
00116       IdxVal* iv; 
00117       Idx i; 
00118     public:
00120       IterVal(IdxVal* iv);
00122       bool operator ()(void) const;
00124       void operator ++(void);
00126       Val val(void) const;
00127     };
00129     class ByVal {
00130     protected:
00131       const IdxVal* iv; 
00132     public:
00134       ByVal(const IdxVal* iv);
00136       bool operator ()(Idx& i, Idx& j);
00137     };
00138 
00140     V0 x0;
00142     V1 x1;
00144     IntSharedArray c;
00146     IdxVal* iv;
00148     Int(Space& home, bool shared, Int& p);
00150     Int(Space& home, IntSharedArray& i, V0 x0, V1 x1);
00151   public:
00153     virtual Actor* copy(Space& home, bool share);
00155     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00157     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00159     static  ExecStatus post(Space& home, IntSharedArray& i, V0 x0, V1 x1);
00161     virtual size_t dispose(Space& home);
00162   };
00163 
00165   template <class V0, class V1>
00166   ExecStatus post_int(Space& home, IntSharedArray& c, V0 x0, V1 x1);
00167 
00168 
00173   template <class ViewB> class IdxView;
00174 
00176   template<class View>
00177   class ViewToVarArg {};
00178 
00183   template <class View>
00184   class IdxViewArray {
00185   private:
00187     IdxView<View>* xs;
00189     int n;
00190   public:
00192     IdxViewArray(void);
00194     IdxViewArray(const IdxViewArray<View>&);
00196     IdxViewArray(Space& home, const typename ViewToVarArg<View>::argtype& x);
00198     IdxViewArray(Space& home, int n);
00199 
00201     int size(void) const;
00203     void size(int n);
00204 
00206     IdxView<View>& operator [](int n);
00208     const IdxView<View>& operator [](int) const;
00209 
00214     void subscribe(Space& home, Propagator& p, PropCond pc, bool process=true);
00219     void cancel(Space& home, Propagator& p, PropCond pc);
00220 
00222     void update(Space& home, bool share, IdxViewArray<View>& x);
00223   };
00224 
00229   template <class VA, class VB, class VC, PropCond pc_ac>
00230   class View : public Propagator {
00231   protected:
00233     IdxViewArray<VA> iv;
00235     VB x0;
00237     VC x1;
00239     View(Space& home, bool share, View& p);
00241     View(Space& home, IdxViewArray<VA>& iv, VB x0, VC x1);
00242   public:
00243     // Cost function (defined as low linear)
00244     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00246     virtual size_t dispose(Space& home);
00247   };
00248 
00249 
00256   template <class VA, class VB, class VC>
00257   class ViewBnd : public View<VA,VB,VC,PC_INT_BND> {
00258   protected:
00259     using View<VA,VB,VC,PC_INT_BND>::iv;
00260     using View<VA,VB,VC,PC_INT_BND>::x0;
00261     using View<VA,VB,VC,PC_INT_BND>::x1;
00262 
00264     ViewBnd(Space& home, bool share, ViewBnd& p);
00266     ViewBnd(Space& home, IdxViewArray<VA>& iv, VB x0, VC x1);
00267   public:
00269     virtual Actor* copy(Space& home, bool share);
00271     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00273     static  ExecStatus post(Space& home, IdxViewArray<VA>& iv, VB x0, VC x1);
00274   };
00275 
00286   template <class VA, class VB, class VC>
00287   class ViewDom : public View<VA,VB,VC,PC_INT_DOM> {
00288   protected:
00289     using View<VA,VB,VC,PC_INT_DOM>::iv;
00290     using View<VA,VB,VC,PC_INT_DOM>::x0;
00291     using View<VA,VB,VC,PC_INT_DOM>::x1;
00292 
00294     ViewDom(Space& home, bool share, ViewDom& p);
00296     ViewDom(Space& home, IdxViewArray<VA>& iv, VB x0, VC x1);
00297   public:
00299     virtual Actor* copy(Space& home, bool share);
00307     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00309     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00311     static  ExecStatus post(Space& home, IdxViewArray<VA>& iv,
00312                             VB x0, VC x1);
00313   };
00314 
00315 }}}
00316 
00317 #include <gecode/int/element/int.hpp>
00318 #include <gecode/int/element/view.hpp>
00319 
00320 #endif
00321 
00322 
00323 // STATISTICS: int-prop
00324