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

view.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *
00005  *  Contributing authors:
00006  *     Christian Schulte <schulte@gecode.org>
00007  *
00008  *  Copyright:
00009  *     Guido Tack, 2004
00010  *     Christian Schulte, 2004
00011  *
00012  *  Last modified:
00013  *     $Date: 2006-08-24 11:25:05 +0200 (Thu, 24 Aug 2006) $ by $Author: schulte $
00014  *     $Revision: 3559 $
00015  *
00016  *  This file is part of Gecode, the generic constraint
00017  *  development environment:
00018  *     http://www.gecode.org
00019  *
00020  *  See the file "LICENSE" for information on usage and
00021  *  redistribution of this file, and for a
00022  *     DISCLAIMER OF ALL WARRANTIES.
00023  *
00024  */
00025 
00026 #include <iostream>
00027 #include "gecode/iter.hh"
00028 
00029 namespace Gecode { 
00030 
00031   namespace Set {
00032 
00047     class SetView : public VariableViewBase<SetVarImp> {
00048     protected:
00049       using VariableViewBase<SetVarImp>::var;
00050     public:
00052 
00053 
00054       SetView(void);
00056       SetView(const SetVar& x);
00058 
00060 
00061 
00063       unsigned int cardMin(void) const;
00065       unsigned int cardMax(void) const;
00067       int lubMin(void) const;
00069       int lubMax(void) const;
00071       int lubMinN(int n) const;
00073       int lubMaxN(int n) const;
00075       int glbMin(void) const;
00077       int glbMax(void) const;
00078 
00080       unsigned int glbSize(void) const;
00082       unsigned int lubSize(void) const;
00084       unsigned int unknownSize(void) const;
00086 
00088 
00089 
00090       bool assigned(void) const;
00092       bool contains(int i) const;
00094       bool notContains(int i) const;
00096 
00097 
00099 
00100 
00101       ModEvent cardMin(Space* home, unsigned int m);
00103       ModEvent cardMax(Space* home, unsigned int m);
00108       ModEvent include(Space* home,int i,int j);
00113       ModEvent exclude(Space* home,int i,int j);
00115       ModEvent include(Space* home,int i);
00117       ModEvent exclude(Space* home,int i);
00122       ModEvent intersect(Space* home,int i,int j);
00124       ModEvent intersect(Space* home,int i);
00126 
00128 
00129 
00131       template <class I> ModEvent excludeI(Space* home, I& i);
00133       template <class I> ModEvent includeI(Space* home, I& i);
00135       template <class I> ModEvent intersectI(Space* home, I& iter);
00137 
00139 
00140 
00141       void update(Space* home, bool share, SetView& x);
00143     };
00144 
00145   }
00146 
00153   template<>
00154   class ViewVarTraits<Set::SetView> {
00155   public:
00157     typedef Set::SetVarImp Var;
00158   };
00159 
00160   // Forward declarations for friends
00161   namespace Set { class ConstantView;  }
00162   bool same(const Set::ConstantView&, const Set::ConstantView&);
00163   bool before(const Set::ConstantView&, const Set::ConstantView&);
00164 
00165   namespace Set {
00166     
00174     class ConstantView : public ConstantViewBase {
00175       friend class LubRanges<ConstantView>;
00176       friend class GlbRanges<ConstantView>;
00177       friend bool Gecode::same(const Gecode::Set::ConstantView&, 
00178                                const Gecode::Set::ConstantView&);
00179       friend bool Gecode::before(const Gecode::Set::ConstantView&, 
00180                                  const Gecode::Set::ConstantView&);
00181     private:
00182       int *ranges;
00183       unsigned int size;
00184       unsigned int domSize;
00185     public:
00187 
00188 
00189       ConstantView(void);
00191       ConstantView(Space* home, const IntSet& s);
00193 
00195 
00196 
00197       unsigned int cardMin(void) const;
00199       unsigned int cardMax(void) const;
00201       int lubMin(void) const;
00203       int lubMax(void) const;
00205       int lubMinN(int n) const;
00207       int lubMaxN(int n) const;
00209       int glbMin(void) const;
00211       int glbMax(void) const;
00212 
00214       unsigned int glbSize(void) const;
00216       unsigned int lubSize(void) const;
00218       unsigned int unknownSize(void) const;
00220 
00222 
00223 
00224       bool assigned(void) const;
00226       bool contains(int i) const;
00228       bool notContains(int i) const;
00230 
00231 
00233 
00234 
00235       ModEvent cardMin(Space* home, unsigned int m);
00237       ModEvent cardMax(Space* home, unsigned int m);
00242       ModEvent include(Space* home,int i,int j);
00247       ModEvent exclude(Space* home,int i,int j);
00249       ModEvent include(Space* home,int i);
00251       ModEvent exclude(Space* home,int i);
00256       ModEvent intersect(Space* home,int i,int j);
00258       ModEvent intersect(Space* home,int i);
00260 
00262 
00263 
00265       template <class I> ModEvent excludeI(Space* home, I& i);
00267       template <class I> ModEvent includeI(Space* home, I& i);
00269       template <class I> ModEvent intersectI(Space* home, I& iter);
00271 
00273 
00274 
00275       static ModEvent     pme(const Propagator* p);
00277       static PropModEvent pme(ModEvent);
00279 
00281 
00282 
00289       void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00291       void cancel(Space* home, Propagator* p, PropCond pc);
00293 
00295 
00296 
00297       void update(Space* home, bool share, ConstantView& x);
00299     };
00300 
00301   }
00302 
00307 
00308   bool same(const Set::ConstantView& x, const Set::ConstantView& y);
00310   bool before(const Set::ConstantView& x, const Set::ConstantView& y);
00312 
00319   template<>
00320   class ViewVarTraits<Set::ConstantView> {
00321   public:
00323     typedef VarBase Var;
00324   };
00325 
00326   namespace Set {
00327 
00336     class EmptyView : public ConstantViewBase {
00337     public:
00339 
00340 
00341       EmptyView(void);
00343 
00345 
00346 
00348       unsigned int cardMin(void) const;
00350       unsigned int cardMax(void) const;
00352       int lubMin(void) const;
00354       int lubMax(void) const;
00356       int lubMinN(int n) const;
00358       int lubMaxN(int n) const;
00360       int glbMin(void) const;
00362       int glbMax(void) const;
00363 
00365       unsigned int glbSize(void) const;
00367       unsigned int lubSize(void) const;
00369       unsigned int unknownSize(void) const;
00371 
00373 
00374 
00375       bool assigned(void) const;
00377       bool contains(int i) const;
00379       bool notContains(int i) const;
00381 
00382 
00384 
00385 
00386       ModEvent cardMin(Space* home, unsigned int m);
00388       ModEvent cardMax(Space* home, unsigned int m);
00393       ModEvent include(Space* home,int i,int j);
00398       ModEvent exclude(Space* home,int i,int j);
00400       ModEvent include(Space* home,int i);
00402       ModEvent exclude(Space* home,int i);
00407       ModEvent intersect(Space* home,int i,int j);
00409       ModEvent intersect(Space* home,int i);
00411 
00413 
00414 
00416       template <class I> ModEvent excludeI(Space* home, I& i);
00418       template <class I> ModEvent includeI(Space* home, I& i);
00420       template <class I> ModEvent intersectI(Space* home, I& iter);
00422 
00424 
00425 
00426       static ModEvent     pme(const Propagator* p);
00428       static PropModEvent pme(ModEvent);
00430 
00432 
00433 
00440       void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00442       void cancel(Space* home, Propagator* p, PropCond pc);
00444 
00446 
00447 
00448       void update(Space* home, bool share, EmptyView& x);
00450     };
00451 
00452   }
00453 
00458 
00459   bool same(const Set::EmptyView& x, const Set::EmptyView& y);
00461   bool before(const Set::EmptyView& x, const Set::EmptyView& y);
00463 
00470   template<>
00471   class ViewVarTraits<Set::EmptyView> {
00472   public:
00474     typedef VarBase Var;
00475   };
00476 
00477   namespace Set {
00478 
00479 
00488     class UniverseView : public ConstantViewBase {
00489     public:
00491 
00492 
00493       UniverseView(void);
00495 
00497 
00498 
00500       unsigned int cardMin(void) const;
00502       unsigned int cardMax(void) const;
00504       int lubMin(void) const;
00506       int lubMax(void) const;
00508       int lubMinN(int n) const;
00510       int lubMaxN(int n) const;
00512       int glbMin(void) const;
00514       int glbMax(void) const;
00515 
00517       unsigned int glbSize(void) const;
00519       unsigned int lubSize(void) const;
00521       unsigned int unknownSize(void) const;
00523 
00525 
00526 
00527       bool assigned(void) const;
00529       bool contains(int i) const;
00531       bool notContains(int i) const;
00533 
00534 
00536 
00537 
00538       ModEvent cardMin(Space* home, unsigned int m);
00540       ModEvent cardMax(Space* home, unsigned int m);
00545       ModEvent include(Space* home,int i,int j);
00550       ModEvent exclude(Space* home,int i,int j);
00552       ModEvent include(Space* home,int i);
00554       ModEvent exclude(Space* home,int i);
00559       ModEvent intersect(Space* home,int i,int j);
00561       ModEvent intersect(Space* home,int i);
00563 
00565 
00566 
00568       template <class I> ModEvent excludeI(Space* home, I& i);
00570       template <class I> ModEvent includeI(Space* home, I& i);
00572       template <class I> ModEvent intersectI(Space* home, I& iter);
00574 
00576 
00577 
00578       static ModEvent     pme(const Propagator* p);
00580       static PropModEvent pme(ModEvent);
00582 
00584 
00585 
00592       void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00594       void cancel(Space* home, Propagator* p, PropCond pc);
00596 
00598 
00599 
00600       void update(Space* home, bool share, UniverseView& x);
00602     };
00603 
00604   }
00605 
00610 
00611   bool same(const Set::UniverseView& x, const Set::UniverseView& y);
00613   bool before(const Set::UniverseView& x, const Set::UniverseView& y);
00615 
00622   template<>
00623   class ViewVarTraits<Set::UniverseView> {
00624   public:
00626     typedef VarBase Var;
00627   };
00628 
00629   namespace Set {
00630 
00631 
00632 
00641     class SingletonView :
00642       public DerivedViewBase<Gecode::Int::IntView> {
00643     protected:
00644       using DerivedViewBase<Gecode::Int::IntView>::view;;
00645 
00647       static PropCond pc_settoint(PropCond pc);
00649       static ModEvent me_inttoset(ModEvent me);
00650 
00651     public:
00653 
00654 
00655       SingletonView(void);
00657       SingletonView(Gecode::Int::IntView& x);
00659 
00661 
00662 
00664       unsigned int cardMin(void) const;
00666       unsigned int cardMax(void) const;
00668       int lubMin(void) const;
00670       int lubMax(void) const;
00672       int lubMinN(int n) const;
00674       int lubMaxN(int n) const;
00676       int glbMin(void) const;
00678       int glbMax(void) const;
00679 
00681       unsigned int glbSize(void) const;
00683       unsigned int lubSize(void) const;
00685       unsigned int unknownSize(void) const;
00687 
00689 
00690 
00691       bool assigned(void) const;
00693       bool contains(int i) const;
00695       bool notContains(int i) const;
00697 
00698 
00700 
00701 
00702       ModEvent cardMin(Space* home, unsigned int m);
00704       ModEvent cardMax(Space* home, unsigned int m);
00709       ModEvent include(Space* home,int i,int j);
00714       ModEvent exclude(Space* home,int i,int j);
00716       ModEvent include(Space* home,int i);
00718       ModEvent exclude(Space* home,int i);
00723       ModEvent intersect(Space* home,int i,int j);
00725       ModEvent intersect(Space* home,int i);
00727 
00729 
00730 
00732       template <class I> ModEvent excludeI(Space* home, I& i);
00734       template <class I> ModEvent includeI(Space* home, I& i);
00736       template <class I> ModEvent intersectI(Space* home, I& iter);
00738 
00740 
00741 
00742       static ModEvent     pme(const Propagator* p);
00744       static PropModEvent pme(ModEvent);
00746 
00748 
00749 
00756       void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00758       void cancel(Space* home, Propagator* p, PropCond pc);
00760 
00761 
00763 
00764 
00765       void update(Space* home, bool share, SingletonView& x);
00767     };
00768 
00769   }
00770 
00775 
00776   bool same(const Set::SingletonView& x, const Set::SingletonView& y);
00778   bool before(const Set::SingletonView& x, const Set::SingletonView& y);
00780 
00787   template<>
00788   class ViewVarTraits<Set::SingletonView> {
00789   public:
00791     typedef Int::IntVarImp Var;
00792   };
00793 
00794   namespace Set {
00795 
00796 
00806     template <class View>
00807     class ComplementView 
00808       : public DerivedViewBase<View> {
00809     protected:
00810       using DerivedViewBase<View>::view;
00811 
00812     public:
00814       static PropCond pc_negateset(PropCond pc);
00816       static ModEvent me_negateset(ModEvent me);
00817 
00819 
00820 
00821       ComplementView(void);
00823       ComplementView(View& x);
00825 
00827 
00828 
00830       unsigned int cardMin(void) const;
00832       unsigned int cardMax(void) const;
00834       int lubMin(void) const;
00836       int lubMax(void) const;
00838       int lubMinN(int n) const;
00840       int lubMaxN(int n) const;
00842       int glbMin(void) const;
00844       int glbMax(void) const;
00845 
00847       unsigned int glbSize(void) const;
00849       unsigned int lubSize(void) const;
00851       unsigned int unknownSize(void) const;
00853 
00855 
00856 
00857       bool assigned(void) const;
00859       bool contains(int i) const;
00861       bool notContains(int i) const;
00863 
00864 
00866 
00867 
00868       ModEvent cardMin(Space* home, unsigned int m);
00870       ModEvent cardMax(Space* home, unsigned int m);
00875       ModEvent include(Space* home,int i,int j);
00880       ModEvent exclude(Space* home,int i,int j);
00882       ModEvent include(Space* home,int i);
00884       ModEvent exclude(Space* home,int i);
00889       ModEvent intersect(Space* home,int i,int j);
00891       ModEvent intersect(Space* home,int i);
00893 
00895 
00896 
00898       template <class I> ModEvent excludeI(Space* home, I& i);
00900       template <class I> ModEvent includeI(Space* home, I& i);
00902       template <class I> ModEvent intersectI(Space* home, I& iter);
00904 
00906 
00907 
00908       static ModEvent     pme(const Propagator* p);
00910       static PropModEvent pme(ModEvent);
00912 
00914 
00915 
00922       void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00924       void cancel(Space* home, Propagator* p, PropCond pc);
00926 
00927 
00929 
00930 
00931       void update(Space* home, bool share, ComplementView& x);
00933     };
00934 
00935   }
00936 
00941 
00942   template <class View>
00943   bool same(const Set::ComplementView<View>& x, 
00944             const Set::ComplementView<View>& y);
00946   template <class View>
00947   bool before(const Set::ComplementView<View>& x, 
00948               const Set::ComplementView<View>& y);
00950 
00951 
00958   template <class View>
00959   class ViewVarTraits<Set::ComplementView<View> > {
00960   public:
00962     typedef typename ViewVarTraits<View>::Var Var;
00963   };
00964 
00965   namespace Set {
00966 
00975     template <class View>
00976     class ComplementView<ComplementView<View> > : public View {
00977     public:
00979 
00980 
00981       ComplementView(void);
00983       ComplementView(ComplementView<View>& x);
00985     };
00986 
00987   }
00988 
00993 
00994   template <class View>
00995   bool same(const Set::ComplementView<Set::ComplementView<View> >& x, 
00996             const Set::ComplementView<Set::ComplementView<View> >& y);
00998   template <class View>
00999   bool before(const Set::ComplementView<Set::ComplementView<View> >& x, 
01000               const Set::ComplementView<Set::ComplementView<View> >& y);
01002 
01003 
01011   template <class View>
01012   class ViewVarTraits<Set::ComplementView<Set::ComplementView<View> > > {
01013   public:
01015     typedef typename ViewVarTraits<View>::Var Var;
01016   };
01017 
01018 }
01019 
01020 #include "gecode/set/view/set.icc"
01021 #include "gecode/set/view/const.icc"
01022 #include "gecode/set/view/singleton.icc"
01023 #include "gecode/set/view/complement.icc"
01024 
01029 GECODE_SET_EXPORT std::ostream&
01030 operator<<(std::ostream&, const Gecode::Set::SetView&);
01031 
01032 
01037 GECODE_SET_EXPORT std::ostream&
01038 operator<<(std::ostream&, const Gecode::Set::EmptyView&);
01039 
01044 GECODE_SET_EXPORT std::ostream&
01045 operator<<(std::ostream&, const Gecode::Set::UniverseView&);
01046 
01051 GECODE_SET_EXPORT std::ostream&
01052 operator<<(std::ostream&, const Gecode::Set::ConstantView&);
01053 
01058 GECODE_SET_EXPORT std::ostream&
01059 operator<<(std::ostream&, const Gecode::Set::SingletonView&);
01060 
01065 template <class View>
01066 std::ostream&
01067 operator<<(std::ostream&, const Gecode::Set::ComplementView<View>&);
01068 
01069 inline std::ostream&
01070 operator<<(std::ostream& os, const Gecode::SetVar& x) {
01071   Gecode::Set::SetView vx(x);
01072   return os << vx;
01073 }
01074 
01075 // STATISTICS: set-var