Generated on Mon Aug 25 11:35:36 2008 for Gecode by doxygen 1.5.6

distinct.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  *  Contributing authors:
00008  *     Gabor Szokoli <szokoli@gecode.org>
00009  *
00010  *  Copyright:
00011  *     Christian Schulte, 2002
00012  *     Guido Tack, 2004
00013  *     Gabor Szokoli, 2003
00014  *
00015  *  Last modified:
00016  *     $Date: 2008-07-11 09:28:48 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $
00017  *     $Revision: 7285 $
00018  *
00019  *  This file is part of Gecode, the generic constraint
00020  *  development environment:
00021  *     http://www.gecode.org
00022  *
00023  *  Permission is hereby granted, free of charge, to any person obtaining
00024  *  a copy of this software and associated documentation files (the
00025  *  "Software"), to deal in the Software without restriction, including
00026  *  without limitation the rights to use, copy, modify, merge, publish,
00027  *  distribute, sublicense, and/or sell copies of the Software, and to
00028  *  permit persons to whom the Software is furnished to do so, subject to
00029  *  the following conditions:
00030  *
00031  *  The above copyright notice and this permission notice shall be
00032  *  included in all copies or substantial portions of the Software.
00033  *
00034  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00035  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00036  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00037  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00038  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00039  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00040  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00041  *
00042  */
00043 
00044 #ifndef __GECODE_INT_DISTINCT_HH__
00045 #define __GECODE_INT_DISTINCT_HH__
00046 
00047 #include "gecode/int.hh"
00048 
00049 #include "gecode/int/rel.hh"
00050 
00056 namespace Gecode { namespace Int { namespace Distinct {
00057 
00066   template <class View>
00067   class Val : public NaryPropagator<View,PC_INT_VAL> {
00068   protected:
00069     using NaryPropagator<View,PC_INT_VAL>::x;
00070 
00072     Val(Space* home, ViewArray<View>& x);
00074     Val(Space* home, bool share, Val<View>& p);
00075   public:
00077     virtual Actor*     copy(Space* home, bool share);
00079     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00081     virtual Reflection::ActorSpec spec(const Space* home,
00082                                         Reflection::VarMap& m) const;
00084     static Support::Symbol ati(void);
00086     static void post(Space* home, Reflection::VarMap& vars,
00087                      const Reflection::ActorSpec& spec);
00089     static ExecStatus post(Space* home, ViewArray<View>& x);
00090   };
00091 
00105   template <class View, bool complete>
00106   ExecStatus prop_val(Space* home, ViewArray<View>&);
00107 
00108 
00109 
00135   template <class View>
00136   class Bnd : public Propagator {
00137   protected:
00139     ViewArray<View> x;
00141     ViewArray<View> y;
00143     Bnd(Space* home, ViewArray<View>& x);
00145     Bnd(Space* home, bool share, Bnd<View>& p);
00146   public:
00148     static ExecStatus post(Space* home, ViewArray<View>& x);
00150     static void post(Space* home, Reflection::VarMap& vars,
00151                      const Reflection::ActorSpec& spec);
00153     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00160     virtual PropCost cost(ModEventDelta med) const;
00162     virtual Actor* copy(Space* home, bool share);
00164     virtual size_t dispose(Space* home);
00166     virtual Reflection::ActorSpec spec(const Space* home,
00167                                         Reflection::VarMap& m) const;
00169     static Support::Symbol ati(void);
00170   };
00171 
00180   template <class View>
00181   ExecStatus prop_bnd(Space* home, ViewArray<View>& x, int m);
00182 
00183   template <class View> class ViewNode;
00184   template <class View> class ValNode;
00185 
00196   template <class View>
00197   class DomCtrl {
00198   protected:
00200     class ViewValGraph {
00201     public:
00203       ViewNode<View>** view; 
00205       int n_view;
00207       ValNode<View>* val;
00209       int n_val;
00211       unsigned int count;
00212     public:
00214       ViewValGraph(void);
00216       bool initialized(void) const;
00218       ExecStatus init(Space* home, int n, View* x);
00220       void mark(void);
00222       ExecStatus tell(Space* home, bool& assigned);
00224       void purge(void);
00226       bool sync(void);
00227     public:
00229       typedef Support::SentinelStack<ViewNode<View>*> MatchStack;
00231       bool match(MatchStack& m, ViewNode<View>* x);
00232     };
00234     ViewValGraph vvg;
00235   public:
00237     DomCtrl(void);
00239     bool available(void);
00241     ExecStatus init(Space* home, int n, View* x);
00243     ExecStatus sync(void);
00245     ExecStatus propagate(Space* home, bool& assigned);
00246   };
00247 
00263   template <class View>
00264   class Dom : public NaryPropagator<View,PC_INT_DOM> {
00265   protected:
00266     using NaryPropagator<View,PC_INT_DOM>::x;
00268     DomCtrl<View> dc;
00270     Dom(Space* home, bool share, Dom<View>& p);
00272     Dom(Space* home, ViewArray<View>& x);
00273   public:
00275     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00282     virtual PropCost cost(ModEventDelta med) const;
00284     virtual Actor* copy(Space* home, bool share);
00286     virtual Reflection::ActorSpec spec(const Space* home,
00287                                         Reflection::VarMap& m) const;
00289     static Support::Symbol ati(void);
00291     static  ExecStatus post(Space* home, ViewArray<View>& x);
00293     static void post(Space* home, Reflection::VarMap& vars,
00294                      const Reflection::ActorSpec& spec);
00295   };
00296 
00303   template <class View>
00304   class TerDom : public TernaryPropagator<View,PC_INT_DOM> {
00305   protected:
00306     using TernaryPropagator<View,PC_INT_DOM>::x0;
00307     using TernaryPropagator<View,PC_INT_DOM>::x1;
00308     using TernaryPropagator<View,PC_INT_DOM>::x2;
00309 
00311     TerDom(Space* home, bool share, TerDom<View>& p);
00313     TerDom(Space* home, View x0, View x1, View x2);
00314   public:
00316     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00318     virtual Actor* copy(Space* home, bool share);
00320     virtual Reflection::ActorSpec spec(const Space* home,
00321                                         Reflection::VarMap& m) const;
00323     static Support::Symbol ati(void);
00325     static  ExecStatus post(Space* home, View x0, View x1, View x2);
00327     static void post(Space* home, Reflection::VarMap& vars,
00328                      const Reflection::ActorSpec& spec);
00329   };
00330 
00331 }}}
00332 
00333 #include "gecode/int/distinct/val.icc"
00334 #include "gecode/int/distinct/bnd.icc"
00335 #include "gecode/int/distinct/ter-dom.icc"
00336 #include "gecode/int/distinct/dom.icc"
00337 
00338 #endif
00339 
00340 // STATISTICS: int-prop
00341