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

var-imp.icc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Patrick Pekczynski <pekczynski@ps.uni-sb.de>
00005  *
00006  *  Copyright:
00007  *     Patrick Pekczynski, 2006
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-02-27 17:49:28 +0100 (Wed, 27 Feb 2008) $ by $Author: tack $
00011  *     $Revision: 6327 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #include <iostream>
00039 
00040 namespace Gecode { namespace CpltSet {
00041 
00042   enum NodeStatus {
00043     INIT = -1,
00044     FIX_GLB = 1,
00045     FIX_NOT_LUB = 0,
00046     FIX_UNKNOWN = 2,
00047     UNDET = 5
00048   };
00049 
00051   template <class T> class GlbValues {
00052   public:
00054 
00055 
00056     GlbValues(void);
00058     GlbValues(const T& x);
00060     void init(const T& x);
00062 
00063 
00064 
00065     bool operator()(void) const;
00067     void operator++(void);
00069 
00070 
00071 
00072     int val(void) const;
00074   };
00075 
00077   template <class T> class LubValues {
00078   public:
00080 
00081 
00082     LubValues(void);
00084     LubValues(const T& x);
00086     void init(const T& x);
00088 
00089 
00090 
00091     bool operator()(void) const;
00093     void operator++(void);
00095 
00096 
00097 
00098     int min(void) const;
00100     int max(void) const;
00102   };
00103 
00105   template <class T> class UnknownValues {
00106   public:
00108 
00109 
00110     UnknownValues(void);
00112     UnknownValues(const T& x);
00114     void init(const T& x);
00116 
00117 
00118 
00119     bool operator()(void) const;
00121     void operator++(void);
00123 
00124 
00125 
00126     int val(void) const;
00128   };
00129 
00136   class CpltSetVarImp : public CpltSetVarImpBase {
00137     friend class BddIterator;
00138     friend class DomBddIterator;
00139 
00140     friend class GlbValues<CpltSetVarImp*>;
00141     friend class LubValues<CpltSetVarImp*>;
00142     friend class UnknownValues<CpltSetVarImp*>;
00143 
00144   public:
00146     static const int MAX_OF_EMPTY = Gecode::Set::Limits::min-1;
00148     static const int MIN_OF_EMPTY = Gecode::Set::Limits::max+1;
00149 
00150     void printdom(void) const;
00151   private:
00153     bdd domain;
00155     int min;
00157     int max;
00161     unsigned int _offset;
00163     bool _assigned;
00164   protected:
00166     GECODE_CPLTSET_EXPORT
00167     CpltSetVarImp(Space* home, bool share, CpltSetVarImp& x);
00169     template <class I>
00170     bdd iterToBdd(I& i);
00171 
00172   public:
00174     GECODE_CPLTSET_EXPORT
00175     CpltSetVarImp(Space* home, int glbMin, int glbMax, int lubMin, int lubMax, 
00176                   unsigned int cardMin, unsigned int cardMax);
00178     GECODE_CPLTSET_EXPORT
00179     CpltSetVarImp(Space* home, const IntSet& glbD, int lubMin, int lubMax, 
00180                   unsigned int cardMin, unsigned int cardMax);
00182     GECODE_CPLTSET_EXPORT
00183     CpltSetVarImp(Space* home, int glbMin, int glbMax, const IntSet& lubD,
00184                   unsigned int cardMin, unsigned int cardMax);
00186     GECODE_CPLTSET_EXPORT
00187     CpltSetVarImp(Space* home, const IntSet& glbD,const IntSet& lubD,
00188                   unsigned int cardMin, unsigned int cardMax);
00189     // Delete a bdd variable
00190     GECODE_CPLTSET_EXPORT
00191     void dispose(Space* home);
00192   public:
00194 
00195 
00196     ModEvent exclude(Space* home, int v);
00198     GECODE_CPLTSET_EXPORT ModEvent exclude(Space* home, int a, int b);
00199 
00201     ModEvent include(Space* home, int v);
00203     GECODE_CPLTSET_EXPORT ModEvent include(Space* home, int a, int b);
00204 
00206     ModEvent intersect(Space* home, int i);
00208     GECODE_CPLTSET_EXPORT ModEvent intersect(Space* home, int a, int b);
00210 
00212 
00213 
00214     template <class I> ModEvent intersectI(Space* home, I& i);
00216     template <class I> ModEvent excludeI(Space* home, I& i);  
00218     template <class I> ModEvent includeI(Space* home, I& i);  
00220 
00222 
00223 
00224     GECODE_CPLTSET_EXPORT ModEvent cardinality(Space* home, int l, int u);
00226     ModEvent cardMin(Space* home,unsigned int n);
00228     ModEvent cardMax(Space* home,unsigned int n);
00230 
00232 
00233 
00234     ModEvent nq(Space* home, int v);
00236     GECODE_CPLTSET_EXPORT ModEvent nq(Space* home, int a, int b);
00237 
00239     ModEvent eq(Space* home, int v);
00241     GECODE_CPLTSET_EXPORT ModEvent eq(Space* home, int a, int b);
00243 
00245 
00246 
00247     template <class I> ModEvent nqI(Space* home, I& i);
00249     template <class I> ModEvent eqI(Space* home, I& i);
00251 
00253 
00254 
00255     GECODE_CPLTSET_EXPORT ModEvent intersect(Space* home, bdd& d);
00257     
00259 
00260 
00262     unsigned int cardMin(void) const;
00264     unsigned int cardMax(void) const;
00265 
00267     GECODE_CPLTSET_EXPORT int glbMin(void) const;
00269     GECODE_CPLTSET_EXPORT int glbMax(void) const;
00271     GECODE_CPLTSET_EXPORT unsigned int glbSize(void) const;
00273     GECODE_CPLTSET_EXPORT int lubMin(void) const;
00275     GECODE_CPLTSET_EXPORT int lubMax(void) const;
00277     GECODE_CPLTSET_EXPORT unsigned int lubSize(void) const;
00279     GECODE_CPLTSET_EXPORT int lubMinN(int n) const;
00281     GECODE_CPLTSET_EXPORT int lubMaxN(int n) const;
00282 
00284     GECODE_CPLTSET_EXPORT int unknownMin(void) const;
00286     GECODE_CPLTSET_EXPORT int unknownMax(void) const;
00288     GECODE_CPLTSET_EXPORT unsigned int unknownSize(void) const;
00289 
00291 
00292 
00294 
00295 
00296     int initialLubMin(void) const;
00298     int initialLubMax(void) const;
00301     unsigned int tableWidth(void) const;
00304     unsigned int offset(void) const;
00307     bdd element(int i) const;
00310     bdd elementNeg(int i) const;
00312     bdd dom(void) const;
00314 
00316 
00317 
00318     GECODE_CPLTSET_EXPORT bool assigned(void) ;
00320     GECODE_CPLTSET_EXPORT bool knownIn(int i) const;
00322     GECODE_CPLTSET_EXPORT bool knownOut(int i) const;
00324     bool range(void) const;
00326     
00328 
00329 
00330     void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00332     void cancel(Space* home, Propagator* p, PropCond pc);
00334 
00335   private:
00337     GECODE_CPLTSET_EXPORT 
00338     CpltSetVarImp* perform_copy(Space* home, bool share);
00339 
00340   public:
00342 
00343 
00344     CpltSetVarImp* copy(Space* home, bool share);
00346 
00348 
00349     GECODE_CPLTSET_EXPORT Reflection::Arg*
00350     spec(const Space* home, Reflection::VarMap& m) const;
00352 
00354 
00355 
00356     static ModEvent modevent(const Delta* d);
00358 
00359   };
00360 
00361 
00369   class BddIterator {
00370   private:
00371     // Stores the bdd to be iterated
00372     bdd c;
00373     // Stores the current sub-bdd under exploration
00374     bdd cur;
00375     // ensure that there are no marked nodes when we leave the iterator
00376     int markref;
00377     // Number of nodes of c
00378     int n;
00379     // Range size of the initial variable domain, i.e. \f$ |[min, max]| \f$
00380     int m;
00381     // Stores for each node whether it is fixed, nonfixed or undetermined
00382     NodeStatus flag;
00383     bool singleton;
00384     // Explores the iterated bdd
00385     SharedArray<bdd> nodes;
00386     // Left end of the nodes array
00387     int l;
00388     // Right end of the nodes array
00389     int r;
00390     // If bypassed is true the current level cannot be fixed
00391     bool bypassed;
00392     // If on the same level an internal node has only leaf childs
00393     // and on another path has at least some internal child
00394     // then this child cannot be fixed
00395     bool onlyleaves;
00396     // The number of the current level in the bdd
00397     int _level;
00398     
00399     // marks all nodes in the cache 
00400     GECODE_CPLTSET_EXPORT void cache_mark(void);
00401     // unmarks all nodes in the cache 
00402     GECODE_CPLTSET_EXPORT void cache_unmark(void);
00403   public:
00405 
00406     BddIterator(void);
00407     BddIterator(const bdd&);
00408     GECODE_CPLTSET_EXPORT void init(const bdd&);
00410 
00411 
00412 
00413     bool operator()(void) const;
00415     GECODE_CPLTSET_EXPORT void operator++(void);
00417 
00418 
00419 
00420     NodeStatus status(void) const;
00422     int level(void) const;
00424     int label(void) const;
00426     bool empty(void) const;
00428     int size(void) const;
00430   };
00431 
00432 
00434   class DomBddIterator : public BddIterator {
00435   private:
00437     int vector_level;
00438     int mi;
00439     int ma;
00440     int off;
00442     int bdd_level;
00443   protected:
00445     bool same(void) const;
00446   public:
00448 
00449     DomBddIterator(void);
00450     DomBddIterator(const CpltSetVarImp* x);
00451     DomBddIterator(const CpltSetVarImp* x, bdd& remain);
00452     void init(const CpltSetVarImp* x);
00453     void init(const CpltSetVarImp* x, bdd& remain);
00455 
00456 
00457 
00458     bool operator()(void) const;
00460     void operator++(void);
00462 
00463 
00464 
00465     NodeStatus status(void) const;
00467     int val(void) const;
00469   };
00470 
00471 }}
00472 
00473 #include "gecode/cpltset/var-imp/cpltset.icc"
00474 
00475 namespace Gecode {
00476 
00477   class CpltSetVar;
00478 
00480   template <>
00481   class VarImpVarTraits<CpltSet::CpltSetVarImp> {
00482   public:
00483     typedef CpltSetVar Var;
00484   };
00485 }
00486 
00487 // STATISTICS: cpltset-var