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

ranges-compl.icc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *     Guido Tack <tack@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Guido Tack, 2004
00009  *     Christian Schulte, 2005
00010  *
00011  *  Last modified:
00012  *     $Date: 2007-09-11 15:58:22 +0200 (Tue, 11 Sep 2007) $ by $Author: schulte $
00013  *     $Revision: 4973 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 namespace Gecode { namespace Iter { namespace Ranges {
00041 
00052   template <int UMIN, int UMAX, class I>
00053   class Compl : public MinMax {
00054   protected:
00056     I i;
00058     void start(void);
00059   public:
00061 
00062 
00063     Compl(void);
00065     Compl(I& i);
00067     void init(I& i);
00069 
00071 
00072 
00073     void operator++(void);
00075   };
00076 
00077 
00088   template <class I>
00089   class ComplVal : public MinMax {
00090   protected:
00092     int UMIN, UMAX;
00094     I i;
00096     void start(void);
00097   public:
00099 
00100 
00101     ComplVal(void);
00103     ComplVal(int umin, int umax, I& i);
00105     void init(int umin, int umax, I& i);
00107 
00109 
00110 
00111     void operator++(void);
00113   };
00114 
00115 
00116   template <int UMIN, int UMAX, class I>
00117   forceinline void
00118   Compl<UMIN,UMAX,I>::start(void) {
00119     if (i()) {
00120       assert((i.min() >= UMIN) && (i.max() <= UMAX));
00121       if (i.min() > UMIN) {
00122         mi = UMIN;
00123         ma = i.min()-1;
00124       } else if (i.max() < UMAX) {
00125         mi = i.max()+1;
00126         ++i;
00127         ma = i() ? (i.min()-1) : UMAX;
00128       } else {
00129         finish();
00130       }
00131     } else {
00132       mi = UMIN;
00133       ma = UMAX;
00134     }
00135   }
00136 
00137   template <int UMIN, int UMAX, class I>
00138   forceinline
00139   Compl<UMIN,UMAX,I>::Compl(void) {}
00140 
00141   template <int UMIN, int UMAX, class I>
00142   forceinline
00143   Compl<UMIN,UMAX,I>::Compl(I& i0) : i(i0) {
00144     start();
00145   }
00146 
00147   template <int UMIN, int UMAX, class I>
00148   forceinline void
00149   Compl<UMIN,UMAX,I>::init(I& i0) {
00150     i=i0; start();
00151   }
00152 
00153   template <int UMIN, int UMAX, class I>
00154   forceinline void
00155   Compl<UMIN,UMAX,I>::operator++(void) {
00156     assert(!i() || (i.max() <= UMAX));
00157     if (i() && (i.max() < UMAX)) {
00158       mi = i.max()+1;
00159       ++i;
00160       ma = i() ? (i.min()-1) : UMAX;
00161     } else {
00162       finish();
00163     }
00164   }
00165 
00166   template <class I>
00167   forceinline void
00168   ComplVal<I>::start(void) {
00169     if (i()) {
00170       assert((i.min() >= UMIN) && (i.max() <= UMAX));
00171       if (i.min() > UMIN) {
00172         mi = UMIN;
00173         ma = i.min()-1;
00174       } else if (i.max() < UMAX) {
00175         mi = i.max()+1;
00176         ++i;
00177         ma = i() ? (i.min()-1) : UMAX;
00178       } else {
00179         finish();
00180       }
00181     } else {
00182       mi = UMIN;
00183       ma = UMAX;
00184     }
00185   }
00186 
00187   template <class I>
00188   forceinline
00189   ComplVal<I>::ComplVal(void) {}
00190 
00191   template <class I>
00192   forceinline
00193   ComplVal<I>::ComplVal(int umin, int umax, I& i0)
00194     : UMIN(umin), UMAX(umax), i(i0) {
00195     start();
00196   }
00197 
00198   template <class I>
00199   forceinline void
00200   ComplVal<I>::init(int umin, int umax, I& i0) {
00201     UMIN=umin; UMAX=umax; i=i0; start();
00202   }
00203 
00204   template <class I>
00205   forceinline void
00206   ComplVal<I>::operator++(void) {
00207     assert(!i() || (i.max() <= UMAX));
00208     if (i() && (i.max() < UMAX)) {
00209       mi = i.max()+1;
00210       ++i;
00211       ma = i() ? (i.min()-1) : UMAX;
00212     } else {
00213       finish();
00214     }
00215   }
00216 
00217 }}}
00218 
00219 // STATISTICS: iter-any
00220