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

set-expr.icc

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-17 16:58:48 +0200 (Thu, 17 Aug 2006) $ by $Author: tack $
00010  *     $Revision: 3548 $
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 namespace Gecode {
00023 
00024   /*
00025    * Operations for set expression code
00026    *
00027    */
00028 
00029   forceinline
00030   SetExprCode::SetExprCode(void) : c(5), n(0) {}
00031 
00032   forceinline
00033   SetExprCode::SetExprCode(const SetExprCode& sc) : c(sc.c), n(sc.n) {}
00034 
00035   forceinline void
00036   SetExprCode::update(bool share, SetExprCode& sc) {
00037     n=sc.n; c.update(share, sc.c);
00038   }
00039   
00040   forceinline void
00041   SetExprCode::add(int i) {
00042     c.ensure(n+1);
00043     c[n] = i;
00044     n++;
00045   }
00046 
00047   forceinline int
00048   SetExprCode::size(void) const { return n; }
00049 
00050   forceinline int
00051   SetExprCode::operator[](int i) const { return c[i]; }
00052 
00053   /*
00054    * Operations for expressions
00055    *
00056    */
00057 
00058   forceinline
00059   SetExpr::SetExpr(void) : ax(NULL), sign(1) {}
00060 
00061   forceinline SetExpr
00062   operator-(const SetExpr& s) { return SetExpr(s, -1); }
00063 
00064   forceinline SetExpr
00065   operator||(const SetExpr& s, const SetExpr& t) {
00066     return SetExpr(s, 1, SetExpr::REL_UNION, t, 1);
00067   }
00068 
00069   forceinline SetExpr
00070   operator&&(const SetExpr& s, const SetExpr& t) {
00071     return SetExpr(s, 1, SetExpr::REL_INTER, t, 1);
00072   }
00073 
00074   forceinline SetExpr
00075   operator-(const SetExpr& s, const SetExpr& t) {
00076     return SetExpr(s, 1, SetExpr::REL_INTER, t, -1);
00077   }
00078 
00082   class SetExprRanges {
00083   private:
00085     class Iter;
00087     Iter *i;
00088     const SetExprRanges& operator=(const SetExprRanges&);
00089   public:
00091 
00092 
00093     SetExprRanges(const SetExprRanges&);
00098     SetExprRanges(const ViewArray<Set::SetView>& x, SetExpr& s,
00099                   bool monotone);
00104     SetExprRanges(const ViewArray<Set::SetView>& x,
00105                   const SetExprCode& s,
00106                   bool monotone);
00108     ~SetExprRanges(void);
00110 
00112 
00113 
00114     bool operator()(void);
00116     void operator++(void);
00118 
00120 
00121 
00122     int min(void) const;
00124     int max(void) const;
00126     unsigned int width(void) const;
00128   };
00129 
00134   class SetExprRanges::Iter {
00135   public:
00137     Gecode::Iter::Ranges::Virt::Iterator* i;
00139     int num;
00140 
00142     Iter(Gecode::Iter::Ranges::Virt::Iterator*);
00144     ~Iter(void);
00146     void increment(void);
00148     bool decrement(void);
00149   };
00150 
00151   forceinline
00152   SetExprRanges::Iter::Iter(Gecode::Iter::Ranges::Virt::Iterator* i0)
00153     : i(i0), num(1) {}
00154   
00155   forceinline
00156   SetExprRanges::Iter::~Iter(void) { delete i; }
00157 
00158   forceinline void
00159   SetExprRanges::Iter::increment(void) { ++num; }
00160 
00161   forceinline bool
00162   SetExprRanges::Iter::decrement(void) { return --num==0; }
00163 
00164   forceinline
00165   SetExprRanges::SetExprRanges(const SetExprRanges& s) : i(s.i) {
00166     i->increment();
00167   }
00168 
00169   forceinline
00170   SetExprRanges::~SetExprRanges(void) {
00171     if (i->decrement())
00172       delete i;
00173   }
00174 
00175   forceinline bool
00176   SetExprRanges::operator()(void) { return (*(i->i))(); }
00177   
00178   forceinline void
00179   SetExprRanges::operator++(void) { ++(*(i->i)); }
00180 
00181   forceinline int
00182   SetExprRanges::min(void) const { return i->i->min(); }
00183 
00184   forceinline int
00185   SetExprRanges::max(void) const { return i->i->max(); }
00186 
00187   forceinline unsigned int
00188   SetExprRanges::width(void) const { return i->i->width(); }
00189 
00190 }
00191 
00192 // STATISTICS: set-prop