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

projectors.hh

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Contributing authors:
00007  *     Christian Schulte <schulte@gecode.org>
00008  *
00009  *  Copyright:
00010  *     Guido Tack, 2006
00011  *     Christian Schulte, 2007
00012  *
00013  *  Last modified:
00014  *     $Date: 2008-08-07 16:04:08 +0200 (Thu, 07 Aug 2008) $ by $Author: tack $
00015  *     $Revision: 7536 $
00016  *
00017  *  This file is part of Gecode, the generic constraint
00018  *  development environment:
00019  *     http://www.gecode.org
00020  *
00021  *  Permission is hereby granted, free of charge, to any person obtaining
00022  *  a copy of this software and associated documentation files (the
00023  *  "Software"), to deal in the Software without restriction, including
00024  *  without limitation the rights to use, copy, modify, merge, publish,
00025  *  distribute, sublicense, and/or sell copies of the Software, and to
00026  *  permit persons to whom the Software is furnished to do so, subject to
00027  *  the following conditions:
00028  *
00029  *  The above copyright notice and this permission notice shall be
00030  *  included in all copies or substantial portions of the Software.
00031  *
00032  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00033  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00034  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00035  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00036  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00037  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00038  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00039  *
00040  */
00041 
00042 #ifndef __GECODE_GENERATOR_PROJECOTRS_HH
00043 #define __GECODE_GENERATOR_PROJECTORS_HH
00044 
00045 #include "gecode/set.hh"
00046 
00047 namespace Gecode {
00048 
00056 
00063   class SetExprCode {
00064   private:
00066     SharedArray<int> c;
00067   public:
00069     enum Instruction {
00070       COMPLEMENT, 
00071       INTER,      
00072       UNION,      
00073       GLB,        
00074       LUB,        
00075       EMPTY,      
00076       UNIVERSE,   
00077       LAST        
00078     };
00079 
00081     class Stream {
00082     private:
00084       Support::DynamicArray<int> is;
00086       int n;
00087     public:
00089       Stream(void);
00091       void add(int i);
00093       int size(void) const;
00095       int operator[](int i) const;
00096     };
00097  
00099 
00100 
00101     SetExprCode(void);
00103     SetExprCode(const Stream& s);
00105     SetExprCode(const SetExprCode& sc);
00107 
00109     void update(Space* home, bool share, SetExprCode& sc);
00110     
00112     int size(void) const;
00113 
00115     int operator[](int i) const;
00116 
00117   };
00118   
00122   class SetExpr {
00123   public:
00125     typedef int var_idx;
00126 
00128     enum RelType {
00129       REL_INTER, 
00130       REL_UNION  
00131     };
00132     
00133   private:
00135     class Node;
00136 
00137     Node* ax; 
00138     int sign; 
00139   public:
00140 
00142     SetExpr(void);
00144     GECODE_SET_EXPORT SetExpr(const SetExpr& s);
00146     GECODE_SET_EXPORT SetExpr(var_idx v);
00148     GECODE_SET_EXPORT SetExpr(const SetExpr& s, int sign);
00150     GECODE_SET_EXPORT SetExpr(const SetExpr& s, int ssign,
00151                               RelType r,
00152                               const SetExpr& t, int tsign);
00154     GECODE_SET_EXPORT const SetExpr& operator=(const SetExpr& e);
00156     GECODE_SET_EXPORT int arity(void) const;
00158     GECODE_SET_EXPORT SetExprCode encode(void) const;
00160     GECODE_SET_EXPORT ~SetExpr(void);
00161   };
00162 
00163 }
00164 
00166 
00167 
00169 Gecode::SetExpr operator-(const Gecode::SetExpr& s);
00171 Gecode::SetExpr operator||(const Gecode::SetExpr& s,
00172                            const Gecode::SetExpr& t);
00174 Gecode::SetExpr operator&&(const Gecode::SetExpr& s,
00175                            const Gecode::SetExpr& t);
00177 Gecode::SetExpr operator-(const Gecode::SetExpr& s,
00178                           const Gecode::SetExpr& t);
00179 
00181 
00182 namespace Gecode {
00183 
00187   class Projector {
00188   private:
00189     SetExpr::var_idx i; 
00190     SetExprCode glb; 
00191     SetExprCode lub; 
00192     int _arity; 
00193   public:
00195     Projector(void);
00197     Projector(SetExpr::var_idx x, const SetExpr& sglb, const SetExpr& slub);
00198 
00200     GECODE_SET_EXPORT void scope(Support::DynamicArray<int>& scope) const;
00201 
00203     GECODE_SET_EXPORT int arity(void) const;
00204               
00206     template <bool negated>
00207     ExecStatus propagate(Space* home, ViewArray<Set::SetView>& x);
00208 
00210     GECODE_SET_EXPORT ExecStatus check(Space* home,
00211                                        ViewArray<Set::SetView>& x);
00212 
00214     unsigned int glbSize(ViewArray<Set::SetView>& x);
00215     
00217     unsigned int lubSize(ViewArray<Set::SetView>& x);
00218 
00220     const SetExprCode& getGlb(void) const;
00221 
00223     const SetExprCode& getLub(void) const;
00224 
00226     SetExpr::var_idx getIdx(void) const;
00227 
00228   };
00229   
00233   class ProjectorSet {
00234   private:
00235     SharedArray<Projector> _ps; 
00236     int _count; 
00237     int _arity; 
00238     
00239   public:
00240     
00242     ProjectorSet(void);
00243     
00245     ProjectorSet(int n);
00246 
00248     void update(Space* home, bool share, ProjectorSet& p);
00249 
00251     GECODE_SET_EXPORT void add(const Projector& p);
00252 
00254     int arity(void) const;
00255 
00257     GECODE_SET_EXPORT void scope(Support::DynamicArray<int>& scope,
00258                                  unsigned int size) const;
00259     
00261     template <bool negated>
00262     ExecStatus propagate(Space* home, ViewArray<Set::SetView>& x);
00263 
00265     GECODE_SET_EXPORT ExecStatus check(Space* home,
00266                                        ViewArray<Set::SetView>& x);
00267 
00269     int size(void) const;
00270 
00272     const Projector& operator[](int i) const;
00273 
00274   };
00275 
00277 
00278 
00280   class Formula {
00281   public:
00282     enum Operator { AND, OR, IMPL, EQUIV };
00283   private:
00285     class Node;
00286     Node* ax; 
00287     int sign; 
00288   public:
00290     GECODE_SET_EXPORT Formula(const Formula& f);
00292     GECODE_SET_EXPORT const Formula& operator=(const Formula& f);
00294     GECODE_SET_EXPORT ~Formula(void);
00296     GECODE_SET_EXPORT Formula(int var);
00298     GECODE_SET_EXPORT Formula(bool b);
00300     GECODE_SET_EXPORT Formula(const Formula& f, int sign);
00302     GECODE_SET_EXPORT Formula(const Formula& f, int fs,
00303                               Operator o,
00304                               const Formula& g, int gs);
00306     GECODE_SET_EXPORT ProjectorSet projectors(void);
00307     
00308   };
00309 
00310 }
00311 
00313 
00314 
00316 Gecode::Formula operator&(const Gecode::Formula& f, const Gecode::Formula& g);
00318 Gecode::Formula operator|(const Gecode::Formula& f, const Gecode::Formula& g);
00320 Gecode::Formula operator-(const Gecode::Formula& f);
00322 Gecode::Formula operator>>(const Gecode::Formula& f,
00323                            const Gecode::Formula& g);
00325 Gecode::Formula operator==(const Gecode::Formula& f,
00326                            const Gecode::Formula& g);
00327 
00329 
00330 namespace Gecode {
00331   
00333 
00334 
00342   GECODE_SET_EXPORT void
00343   projector(Space* home, const SetVarArgs& xa,
00344             ProjectorSet& ps, bool negated=false);
00345 
00353   GECODE_SET_EXPORT void
00354   projector(Space* home, const SetVar& xa, const SetVar& ya,
00355             ProjectorSet& ps, bool negated=false);
00356 
00363   GECODE_SET_EXPORT void
00364   projector(Space* home, const SetVar& xa, const SetVar& ya,
00365             const BoolVar& bv,
00366             ProjectorSet& ps);
00367 
00375   GECODE_SET_EXPORT void
00376   projector(Space* home,
00377             const SetVar& xa, const SetVar& ya, const SetVar& za,
00378             ProjectorSet& ps, bool negated=false);
00379 
00386   GECODE_SET_EXPORT void
00387   projector(Space* home,
00388             const SetVar& xa, const SetVar& ya, const SetVar& za,
00389             const BoolVar& bv,
00390             ProjectorSet& ps);
00391   
00399   GECODE_SET_EXPORT void
00400   projector(Space* home, const SetVar& xa, const SetVar& ya,
00401             const IntVar& i,
00402             Projector& p);
00403 
00411   GECODE_SET_EXPORT void
00412   projector(Space* home, const SetVar& xa, const SetVar& ya,
00413             const SetVar& za, const IntVar& i,
00414             Projector& p);
00415 
00417 
00419 
00420 }
00421 
00422 GECODE_SET_EXPORT std::ostream&
00423 operator<<(std::ostream&, const Gecode::SetExprCode& sec);
00424 
00425 GECODE_SET_EXPORT std::ostream&
00426 operator<<(std::ostream&, const Gecode::Projector& p);
00427 
00428 GECODE_SET_EXPORT std::ostream&
00429 operator<<(std::ostream&, const Gecode::ProjectorSet& ps);
00430 
00431 #include "gecode/set/projectors/set-expr.icc"
00432 #include "gecode/set/projectors/projector.icc"
00433 #include "gecode/set/projectors/projector-set.icc"
00434 #include "gecode/set/projectors/formula.icc"
00435 
00436 #endif
00437 
00438 // STATISTICS: set-prop