Generated on Wed Nov 1 15:04:44 2006 for Gecode by doxygen 1.4.5

projectors.hh

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Guido Tack, 2006
00007  *
00008  *  Last modified:
00009  *     $Date: 2006-08-25 17:31:32 +0200 (Fri, 25 Aug 2006) $ by $Author: tack $
00010  *     $Revision: 3573 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 #ifndef __GECODE_GENERATOR_PROJECOTRS_HH
00023 #define __GECODE_GENERATOR_PROJECTORS_HH
00024 
00025 #include "gecode/set.hh"
00026 #include "gecode/support/dynamic-array.hh"
00027 #include "gecode/support/shared-array.hh"
00028 
00029 namespace Gecode {
00030 
00038 
00045   class SetExprCode {
00046   private:
00048     Support::SharedArray<int> c;
00050     int n;
00051   public:
00053     enum Instruction {
00054       COMPLEMENT, 
00055       INTER,      
00056       UNION,      
00057       GLB,        
00058       LUB,        
00059       EMPTY,      
00060       UNIVERSE,   
00061       LAST        
00062     };
00063 
00065 
00066         
00068     SetExprCode(void);
00069 
00071     SetExprCode(const SetExprCode& sc);
00072 
00074 
00076     void update(bool share, SetExprCode& sc);
00077     
00079     void add(int i);
00080 
00082     int size(void) const;
00083 
00085     int operator[](int i) const;
00086 
00087   };
00088   
00092   class SetExpr {
00093   public:
00095     typedef int var_idx;
00096 
00098     enum RelType {
00099       REL_INTER, 
00100       REL_UNION  
00101     };
00102     
00103   private:
00105     class Node;
00106 
00107     Node* ax; 
00108     int sign; 
00109   public:
00110 
00112     SetExpr(void);
00114     GECODE_SET_EXPORT SetExpr(const SetExpr& s);
00116     GECODE_SET_EXPORT SetExpr(var_idx v);
00118     GECODE_SET_EXPORT SetExpr(const SetExpr& s, int sign);
00120     GECODE_SET_EXPORT SetExpr(const SetExpr& s, int ssign,
00121                               RelType r,
00122                               const SetExpr& t, int tsign);
00124     GECODE_SET_EXPORT const SetExpr& operator=(const SetExpr& e);
00126     GECODE_SET_EXPORT int arity(void) const;
00128     GECODE_SET_EXPORT SetExprCode encode(void) const;
00130     GECODE_SET_EXPORT ~SetExpr(void);
00131   };
00132 
00134 
00135 
00137   SetExpr operator-(const SetExpr& s);
00139   SetExpr operator||(const SetExpr& s, const SetExpr& t);
00141   SetExpr operator&&(const SetExpr&, const SetExpr&);
00143   SetExpr operator-(const SetExpr&, const SetExpr&);
00144 
00146 
00150   class Projector {
00151   private:
00152     SetExpr::var_idx i; 
00153     SetExprCode glb; 
00154     SetExprCode lub; 
00155     int _arity; 
00156   public:
00158     Projector(void);
00160     Projector(SetExpr::var_idx x, const SetExpr& sglb, const SetExpr& slub);
00161 
00163     GECODE_SET_EXPORT void scope(Support::DynamicArray<int>&) const;
00164 
00166     GECODE_SET_EXPORT int arity(void) const;
00167               
00169     template <bool negated>
00170     ExecStatus propagate(Space* home, ViewArray<Set::SetView>& x);
00171 
00173     GECODE_SET_EXPORT ExecStatus check(Space* home,
00174                                        ViewArray<Set::SetView>& x);
00175 
00177     unsigned int glbSize(ViewArray<Set::SetView>& x);
00178     
00180     unsigned int lubSize(ViewArray<Set::SetView>& x);
00181 
00183     const SetExprCode& getGlb(void) const;
00184 
00186     const SetExprCode& getLub(void) const;
00187 
00189     SetExpr::var_idx getIdx(void) const;
00190 
00191   };
00192   
00196   class ProjectorSet {
00197   private:
00198     Support::SharedArray<Projector,true> _ps; 
00199     int _count; 
00200     int _arity; 
00201   public:
00202     
00204     ProjectorSet(void);
00205 
00207     void update(Space* home, bool share, ProjectorSet& p);
00208 
00210     GECODE_SET_EXPORT void add(const Projector& p);
00211 
00213     int arity(void) const;
00214 
00216     GECODE_SET_EXPORT void scope(Support::DynamicArray<int>&) const;
00217     
00219     template <bool negated>
00220     ExecStatus propagate(Space* home, ViewArray<Set::SetView>& x);
00221 
00223     GECODE_SET_EXPORT ExecStatus check(Space* home,
00224                                        ViewArray<Set::SetView>& x);
00225 
00227     int size(void) const;
00228 
00230     const Projector& operator[](int i) const;
00231 
00232   };
00233 
00235 
00236 
00244   GECODE_SET_EXPORT void
00245   projector(Space* home, const SetVar& xa, const SetVar& ya,
00246             ProjectorSet& ps, bool negated=false);
00247 
00254   GECODE_SET_EXPORT void
00255   projector(Space* home, const SetVar& xa, const SetVar& ya,
00256             const BoolVar& bv,
00257             ProjectorSet& ps);
00258 
00266   GECODE_SET_EXPORT void
00267   projector(Space* home,
00268             const SetVar& xa, const SetVar& ya, const SetVar& za,
00269             ProjectorSet& ps, bool negated=false);
00270 
00277   GECODE_SET_EXPORT void
00278   projector(Space* home,
00279             const SetVar& xa, const SetVar& ya, const SetVar& za,
00280             const BoolVar& bv,
00281             ProjectorSet& ps);
00282   
00290   GECODE_SET_EXPORT void
00291   projector(Space* home, const SetVar& xa, const SetVar& ya,
00292             const IntVar& i,
00293             Projector& p);
00294 
00302   GECODE_SET_EXPORT void
00303   projector(Space* home, const SetVar& xa, const SetVar& ya,
00304             const SetVar& za, const IntVar& i,
00305             Projector& p);
00306 
00308 
00310 
00311 }
00312 
00313 #include "gecode/set/projectors/set-expr.icc"
00314 #include "gecode/set/projectors/projector.icc"
00315 #include "gecode/set/projectors/projector-set.icc"
00316   
00317 #endif
00318 
00319 // STATISTICS: set-prop