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

virtual-ranges-compl.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2004
00008  *     Christian Schulte, 2005
00009  *
00010  *  Last modified:
00011  *     $Date: 2006-08-17 13:00:10 +0200 (Thu, 17 Aug 2006) $ by $Author: tack $
00012  *     $Revision: 3545 $
00013  *
00014  *  This file is part of Gecode, the generic constraint
00015  *  development environment:
00016  *     http://www.gecode.org
00017  *
00018  *  See the file "LICENSE" for information on usage and
00019  *  redistribution of this file, and for a
00020  *     DISCLAIMER OF ALL WARRANTIES.
00021  *
00022  */
00023 
00024 namespace Gecode { namespace Iter { namespace Ranges { namespace Virt {
00025 
00037   template <int UMIN, int UMAX>
00038   class Compl : public MinMax, public Iterator {
00039   protected:
00041     Iterator* i;
00043     void start(void);
00044   public:
00046 
00047 
00048     Compl(void);
00050     Compl(Iterator* i);
00052     ~Compl(void);
00054 
00056 
00057 
00058     virtual int min(void) const;
00060     virtual int max(void) const;
00062     virtual unsigned int width(void) const;
00064 
00066 
00067 
00068     void operator++(void);
00070     virtual bool operator()(void);
00072   };
00073 
00074 
00086   class ComplVal : public MinMax, public Iterator {
00087   protected:
00089     int UMIN, UMAX;
00091     Iterator* i;
00093     void start(void);
00094   public:
00096 
00097 
00098     ComplVal(void);
00100     ComplVal(int umin, int umax, Iterator* i);
00102     ~ComplVal(void);
00104 
00106 
00107 
00108     virtual int min(void) const;
00110     virtual int max(void) const;
00112     virtual unsigned int width(void) const;
00114 
00116 
00117 
00118     void operator++(void);
00120     virtual bool operator()(void);
00122   };
00123 
00124 
00125   template <int UMIN, int UMAX>
00126   forceinline void
00127   Compl<UMIN,UMAX>::start(void) {
00128     if ((*i)()) {
00129       assert((i->min() >= UMIN) && (i->max() <= UMAX));
00130       if (i->min() > UMIN) {
00131         mi = UMIN;
00132         ma = i->min()-1;
00133       } else if (i->max() < UMAX) {
00134         mi = i->max()+1;
00135         ++(*i);
00136         ma = (*i)() ? (i->min()-1) : UMAX;
00137       } else {
00138         finish();
00139       }
00140     } else {
00141       mi = UMIN;
00142       ma = UMAX;
00143     }
00144   }
00145 
00146   template <int UMIN, int UMAX>
00147   forceinline
00148   Compl<UMIN,UMAX>::Compl(void) {}
00149 
00150   template <int UMIN, int UMAX>
00151   forceinline
00152   Compl<UMIN,UMAX>::Compl(Iterator* i0) : i(i0) {
00153     start();
00154   }
00155 
00156   template <int UMIN, int UMAX>
00157   Compl<UMIN,UMAX>::~Compl(void) { delete i; }
00158 
00159   template <int UMIN, int UMAX>
00160   forceinline void
00161   Compl<UMIN,UMAX>::operator++(void) {
00162     assert(!(*i)() || (i->max() <= UMAX));
00163     if ((*i)() && (i->max() < UMAX)) {
00164       mi = i->max()+1;
00165       ++(*i);
00166       ma = (*i)() ? (i->min()-1) : UMAX;
00167     } else {
00168       finish();
00169     }
00170   }
00171 
00172   template <int UMIN, int UMAX>
00173   forceinline bool
00174   Compl<UMIN,UMAX>::operator()(void) { return MinMax::operator()(); }
00175 
00176   template <int UMIN, int UMAX>
00177   forceinline int
00178   Compl<UMIN,UMAX>::min(void) const { return MinMax::min(); }
00179 
00180   template <int UMIN, int UMAX>
00181   forceinline int
00182   Compl<UMIN,UMAX>::max(void) const { return MinMax::max(); }
00183 
00184   template <int UMIN, int UMAX>
00185   forceinline unsigned int
00186   Compl<UMIN,UMAX>::width(void) const { return MinMax::width(); }
00187 
00188   forceinline void
00189   ComplVal::start(void) {
00190     if ((*i)()) {
00191       assert((i->min() >= UMIN) && (i->max() <= UMAX));
00192       if (i->min() > UMIN) {
00193         mi = UMIN;
00194         ma = i->min()-1;
00195       } else if (i->max() < UMAX) {
00196         mi = i->max()+1;
00197         ++(*i);
00198         ma = (*i)() ? (i->min()-1) : UMAX;
00199       } else {
00200         finish();
00201       }
00202     } else {
00203       mi = UMIN;
00204       ma = UMAX;
00205     }
00206   }
00207 
00208   forceinline
00209   ComplVal::ComplVal(void) {}
00210 
00211   forceinline
00212   ComplVal::ComplVal(int umin, int umax, Iterator* i0)
00213     : UMIN(umin), UMAX(umax), i(i0) {
00214     start();
00215   }
00216 
00217   forceinline
00218   ComplVal::~ComplVal(void) { delete i; }
00219 
00220   forceinline void
00221   ComplVal::operator++(void) {
00222     assert(!(*i)() || (i->max() <= UMAX));
00223     if ((*i)() && (i->max() < UMAX)) {
00224       mi = i->max()+1;
00225       ++(*i);
00226       ma = (*i)() ? (i->min()-1) : UMAX;
00227     } else {
00228       finish();
00229     }
00230   }
00231 
00232   forceinline bool
00233   ComplVal::operator()(void) { return MinMax::operator()(); }
00234 
00235   forceinline int
00236   ComplVal::min(void) const { return MinMax::min(); }
00237 
00238   forceinline int
00239   ComplVal::max(void) const { return MinMax::max(); }
00240 
00241   forceinline unsigned int
00242   ComplVal::width(void) const { return MinMax::width(); }
00243 
00244 }}}}
00245 
00246 // STATISTICS: iter-any
00247