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

set-expr.icc

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-02-26 11:08:59 +0100 (Tue, 26 Feb 2008) $ by $Author: tack $
00015  *     $Revision: 6312 $
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 namespace Gecode {
00043 
00044   /*
00045    * Operations for set expression code
00046    *
00047    */
00048 
00049   forceinline
00050   SetExprCode::Stream::Stream(void) : n(0) {}
00051 
00052   forceinline void 
00053   SetExprCode::Stream::add(int i) {
00054     is[n++] = i;
00055   }
00056 
00057   forceinline int 
00058   SetExprCode::Stream::size(void) const {
00059     return n;
00060   }
00061 
00062   forceinline int 
00063   SetExprCode::Stream::operator[](int i) const {
00064     return is[i];
00065   }
00066 
00067  
00068 
00069   forceinline
00070   SetExprCode::SetExprCode(void) {}
00071 
00072   forceinline
00073   SetExprCode::SetExprCode(const SetExprCode::Stream& s) 
00074     : c(s.size()) {
00075     for (int i=s.size(); i--; )
00076       c[i]=s[i];
00077   }
00078 
00079   forceinline
00080   SetExprCode::SetExprCode(const SetExprCode& sc) : c(sc.c) {}
00081 
00082   forceinline void
00083   SetExprCode::update(Space* home, bool share, SetExprCode& sc) {
00084     c.update(home, share, sc.c);
00085   }
00086   
00087   forceinline int
00088   SetExprCode::size(void) const { return c.size(); }
00089 
00090   forceinline int
00091   SetExprCode::operator[](int i) const { return c[i]; }
00092 
00093 
00094   /*
00095    * Operations for expressions
00096    *
00097    */
00098 
00099   forceinline
00100   SetExpr::SetExpr(void) : ax(NULL), sign(1) {}
00101 
00102 }
00103 
00104 inline Gecode::SetExpr
00105 operator-(const Gecode::SetExpr& s) { return Gecode::SetExpr(s, -1); }
00106 
00107 inline Gecode::SetExpr
00108 operator||(const Gecode::SetExpr& s, const Gecode::SetExpr& t) {
00109   return Gecode::SetExpr(s, 1, Gecode::SetExpr::REL_UNION, t, 1);
00110 }
00111 
00112 inline Gecode::SetExpr
00113 operator&&(const Gecode::SetExpr& s, const Gecode::SetExpr& t) {
00114   return Gecode::SetExpr(s, 1, Gecode::SetExpr::REL_INTER, t, 1);
00115 }
00116 
00117 inline Gecode::SetExpr
00118 operator-(const Gecode::SetExpr& s, const Gecode::SetExpr& t) {
00119   return Gecode::SetExpr(s, 1, Gecode::SetExpr::REL_INTER, t, -1);
00120 }
00121 
00122 namespace Gecode {
00123 
00127   class SetExprRanges {
00128   private:
00130     class Iter;
00132     Iter *i;
00133     const SetExprRanges& operator=(const SetExprRanges&);
00134   public:
00136 
00137 
00138     SetExprRanges(const SetExprRanges&);
00143     SetExprRanges(const ViewArray<Set::SetView>& x, SetExpr& s,
00144                   bool monotone);
00149     SetExprRanges(const ViewArray<Set::SetView>& x,
00150                   const SetExprCode& s,
00151                   bool monotone);
00153     ~SetExprRanges(void);
00155 
00157 
00158 
00159     bool operator()(void);
00161     void operator++(void);
00163 
00165 
00166 
00167     int min(void) const;
00169     int max(void) const;
00171     unsigned int width(void) const;
00173   };
00174 
00179   class SetExprRanges::Iter {
00180   public:
00182     Gecode::Iter::Ranges::Virt::Iterator* i;
00184     int num;
00185 
00187     Iter(Gecode::Iter::Ranges::Virt::Iterator*);
00189     ~Iter(void);
00191     void increment(void);
00193     bool decrement(void);
00194   };
00195 
00196   forceinline
00197   SetExprRanges::Iter::Iter(Gecode::Iter::Ranges::Virt::Iterator* i0)
00198     : i(i0), num(1) {}
00199   
00200   forceinline
00201   SetExprRanges::Iter::~Iter(void) { delete i; }
00202 
00203   forceinline void
00204   SetExprRanges::Iter::increment(void) { ++num; }
00205 
00206   forceinline bool
00207   SetExprRanges::Iter::decrement(void) { return --num==0; }
00208 
00209   forceinline
00210   SetExprRanges::SetExprRanges(const SetExprRanges& s) : i(s.i) {
00211     i->increment();
00212   }
00213 
00214   forceinline
00215   SetExprRanges::~SetExprRanges(void) {
00216     if (i->decrement())
00217       delete i;
00218   }
00219 
00220   forceinline bool
00221   SetExprRanges::operator()(void) { return (*(i->i))(); }
00222   
00223   forceinline void
00224   SetExprRanges::operator++(void) { ++(*(i->i)); }
00225 
00226   forceinline int
00227   SetExprRanges::min(void) const { return i->i->min(); }
00228 
00229   forceinline int
00230   SetExprRanges::max(void) const { return i->i->max(); }
00231 
00232   forceinline unsigned int
00233   SetExprRanges::width(void) const { return i->i->width(); }
00234 
00235 }
00236 
00237 // STATISTICS: set-prop