Generated on Thu Apr 11 13:59:08 2019 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  *  This file is part of Gecode, the generic constraint
00012  *  development environment:
00013  *     http://www.gecode.org
00014  *
00015  *  Permission is hereby granted, free of charge, to any person obtaining
00016  *  a copy of this software and associated documentation files (the
00017  *  "Software"), to deal in the Software without restriction, including
00018  *  without limitation the rights to use, copy, modify, merge, publish,
00019  *  distribute, sublicense, and/or sell copies of the Software, and to
00020  *  permit persons to whom the Software is furnished to do so, subject to
00021  *  the following conditions:
00022  *
00023  *  The above copyright notice and this permission notice shall be
00024  *  included in all copies or substantial portions of the Software.
00025  *
00026  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00030  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00031  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00032  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00033  *
00034  */
00035 
00036 #ifndef __GECODE_INT_ELEMENT_HH__
00037 #define __GECODE_INT_ELEMENT_HH__
00038 
00039 #include <gecode/int.hh>
00040 #include <gecode/int/rel.hh>
00041 #include <gecode/int/idx-view.hh>
00042 
00048 namespace Gecode { namespace Int { namespace Element {
00049 
00056   template<class V0, class V1, class Idx, class Val>
00057   class Int : public Propagator {
00058   protected:
00067     class IdxVal  {
00068     public:
00069       Idx idx_next; 
00070       Idx val_next; 
00071       Idx idx; 
00072       Val val; 
00073 
00074       void mark(void);
00076       bool marked(void) const;
00077     };
00084     class IterIdxUnmark {
00085     private:
00086       IdxVal* iv; 
00087       Idx i; 
00088     public:
00090       IterIdxUnmark(IdxVal* iv);
00092       bool operator ()(void) const;
00094       void operator ++(void);
00096       Idx val(void) const;
00097     };
00104     class IterVal {
00105     private:
00106       IdxVal* iv; 
00107       Idx i; 
00108     public:
00110       IterVal(IdxVal* iv);
00112       bool operator ()(void) const;
00114       void operator ++(void);
00116       Val val(void) const;
00117     };
00126     class IterValUnmark {
00127     private:
00128       IdxVal* iv; 
00129       Idx i; 
00130     public:
00132       IterValUnmark(IdxVal* iv);
00134       bool operator ()(void) const;
00136       void operator ++(void);
00138       Val val(void) const;
00139     };
00141     class ByVal {
00142     protected:
00143       const IdxVal* iv; 
00144     public:
00146       ByVal(const IdxVal* iv);
00148       bool operator ()(Idx& i, Idx& j);
00149     };
00150 
00152     V0 x0;
00154     typedef typename Gecode::Support::IntTypeTraits<Idx>::utype IdxSize;
00156     IdxSize s0;
00158     V1 x1;
00160     typedef typename Gecode::Support::IntTypeTraits<Val>::utype ValSize;
00162     ValSize s1;
00164     IntSharedArray c;
00166     IdxVal* iv;
00168     void prune_idx(void);
00170     void prune_val(void);
00172     static ExecStatus assigned_val(Space& home, IntSharedArray& c,
00173                                    V0 x0, V1 x1);
00175     Int(Space& home, Int& p);
00177     Int(Home home, IntSharedArray& i, V0 x0, V1 x1);
00178   public:
00180     virtual Actor* copy(Space& home);
00182     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00184     virtual void reschedule(Space& home);
00186     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00188     static  ExecStatus post(Home home, IntSharedArray& i, V0 x0, V1 x1);
00190     virtual size_t dispose(Space& home);
00191   };
00192 
00194   template<class V0, class V1>
00195   ExecStatus post_int(Home home, IntSharedArray& c, V0 x0, V1 x1);
00196 
00197 
00202   template<class VA, class VB, class VC, PropCond pc_ac>
00203   class View : public Propagator {
00204   protected:
00206     IdxViewArray<VA> iv;
00208     VB x0;
00210     VC x1;
00212     View(Space& home, View& p);
00214     View(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
00215   public:
00216     // Cost function (defined as low linear)
00217     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00219     virtual void reschedule(Space& home);
00221     virtual size_t dispose(Space& home);
00222   };
00223 
00224 
00231   template<class VA, class VB, class VC>
00232   class ViewBnd : public View<VA,VB,VC,PC_INT_BND> {
00233   protected:
00234     using View<VA,VB,VC,PC_INT_BND>::iv;
00235     using View<VA,VB,VC,PC_INT_BND>::x0;
00236     using View<VA,VB,VC,PC_INT_BND>::x1;
00237 
00239     ViewBnd(Space& home, ViewBnd& p);
00241     ViewBnd(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
00242   public:
00244     virtual Actor* copy(Space& home);
00246     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00248     static  ExecStatus post(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
00249   };
00250 
00261   template<class VA, class VB, class VC>
00262   class ViewDom : public View<VA,VB,VC,PC_INT_DOM> {
00263   protected:
00264     using View<VA,VB,VC,PC_INT_DOM>::iv;
00265     using View<VA,VB,VC,PC_INT_DOM>::x0;
00266     using View<VA,VB,VC,PC_INT_DOM>::x1;
00267 
00269     ViewDom(Space& home, ViewDom& p);
00271     ViewDom(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
00272   public:
00274     virtual Actor* copy(Space& home);
00282     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00284     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00286     static  ExecStatus post(Home home, IdxViewArray<VA>& iv,
00287                             VB x0, VC x1);
00288   };
00289 
00297   class GECODE_VTABLE_EXPORT Pair
00298     : public TernaryPropagator<IntView,PC_INT_DOM> {
00299   protected:
00300     using TernaryPropagator<IntView,PC_INT_DOM>::x0;
00301     using TernaryPropagator<IntView,PC_INT_DOM>::x1;
00302     using TernaryPropagator<IntView,PC_INT_DOM>::x2;
00304     int w;
00306     Pair(Space& home, Pair& p);
00307   public:
00309     Pair(Home home, IntView x0, IntView x1, IntView x2, int w);
00311     static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2,
00312                            int w, int h);
00314     GECODE_INT_EXPORT virtual Actor* copy(Space& home);
00316     GECODE_INT_EXPORT virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00317   };
00318 
00319 }}}
00320 
00321 #include <gecode/int/element/int.hpp>
00322 #include <gecode/int/element/view.hpp>
00323 #include <gecode/int/element/pair.hpp>
00324 
00325 #endif
00326 
00327 
00328 // STATISTICS: int-prop
00329