Generated on Thu Apr 11 13:59:13 2019 for Gecode by doxygen 1.6.3

ranges-compl.hpp

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  *  This file is part of Gecode, the generic constraint
00012  *  development environment:
00013  *     http://www.gecode.org
00014  *
00015  *  Permission is hereby granted, free of charge, to any person obtaining
00016  *  a copy of this software and associated documentation files (the
00017  *  "Software"), to deal in the Software without restriction, including
00018  *  without limitation the rights to use, copy, modify, merge, publish,
00019  *  distribute, sublicense, and/or sell copies of the Software, and to
00020  *  permit persons to whom the Software is furnished to do so, subject to
00021  *  the following conditions:
00022  *
00023  *  The above copyright notice and this permission notice shall be
00024  *  included in all copies or substantial portions of the Software.
00025  *
00026  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00030  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00031  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00032  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00033  *
00034  */
00035 
00036 namespace Gecode { namespace Iter { namespace Ranges {
00037 
00048   template<int UMIN, int UMAX, class I>
00049   class Compl : public MinMax {
00050   protected:
00052     I i;
00054     void start(void);
00055   public:
00057 
00058 
00059     Compl(void);
00061     Compl(I& i);
00063     void init(I& i);
00065 
00067 
00068 
00069     void operator ++(void);
00071   };
00072 
00073 
00084   template<class I>
00085   class ComplVal : public MinMax {
00086   protected:
00088     int UMIN, UMAX;
00090     I i;
00092     void start(void);
00093   public:
00095 
00096 
00097     ComplVal(void);
00099     ComplVal(int umin, int umax, I& i);
00101     void init(int umin, int umax, I& i);
00103 
00105 
00106 
00107     void operator ++(void);
00109   };
00110 
00111 
00112   template<int UMIN, int UMAX, class I>
00113   forceinline void
00114   Compl<UMIN,UMAX,I>::start(void) {
00115     if (i()) {
00116       assert((i.min() >= UMIN) && (i.max() <= UMAX));
00117       if (i.min() > UMIN) {
00118         mi = UMIN;
00119         ma = i.min()-1;
00120       } else if (i.max() < UMAX) {
00121         mi = i.max()+1;
00122         ++i;
00123         ma = i() ? (i.min()-1) : UMAX;
00124       } else {
00125         finish();
00126       }
00127     } else {
00128       mi = UMIN;
00129       ma = UMAX;
00130     }
00131   }
00132 
00133   template<int UMIN, int UMAX, class I>
00134   forceinline
00135   Compl<UMIN,UMAX,I>::Compl(void) {}
00136 
00137   template<int UMIN, int UMAX, class I>
00138   forceinline
00139   Compl<UMIN,UMAX,I>::Compl(I& i0) : i(i0) {
00140     start();
00141   }
00142 
00143   template<int UMIN, int UMAX, class I>
00144   forceinline void
00145   Compl<UMIN,UMAX,I>::init(I& i0) {
00146     i=i0; start();
00147   }
00148 
00149   template<int UMIN, int UMAX, class I>
00150   forceinline void
00151   Compl<UMIN,UMAX,I>::operator ++(void) {
00152     assert(!i() || (i.max() <= UMAX));
00153     if (i() && (i.max() < UMAX)) {
00154       mi = i.max()+1;
00155       ++i;
00156       ma = i() ? (i.min()-1) : UMAX;
00157     } else {
00158       finish();
00159     }
00160   }
00161 
00162   template<class I>
00163   forceinline void
00164   ComplVal<I>::start(void) {
00165     if (i()) {
00166       assert((i.min() >= UMIN) && (i.max() <= UMAX));
00167       if (i.min() > UMIN) {
00168         mi = UMIN;
00169         ma = i.min()-1;
00170       } else if (i.max() < UMAX) {
00171         mi = i.max()+1;
00172         ++i;
00173         ma = i() ? (i.min()-1) : UMAX;
00174       } else {
00175         finish();
00176       }
00177     } else {
00178       mi = UMIN;
00179       ma = UMAX;
00180     }
00181   }
00182 
00183   template<class I>
00184   forceinline
00185   ComplVal<I>::ComplVal(void) {}
00186 
00187   template<class I>
00188   forceinline
00189   ComplVal<I>::ComplVal(int umin, int umax, I& i0)
00190     : UMIN(umin), UMAX(umax), i(i0) {
00191     start();
00192   }
00193 
00194   template<class I>
00195   forceinline void
00196   ComplVal<I>::init(int umin, int umax, I& i0) {
00197     UMIN=umin; UMAX=umax; i=i0; start();
00198   }
00199 
00200   template<class I>
00201   forceinline void
00202   ComplVal<I>::operator ++(void) {
00203     assert(!i() || (i.max() <= UMAX));
00204     if (i() && (i.max() < UMAX)) {
00205       mi = i.max()+1;
00206       ++i;
00207       ma = i() ? (i.min()-1) : UMAX;
00208     } else {
00209       finish();
00210     }
00211   }
00212 
00213 }}}
00214 
00215 // STATISTICS: iter-any
00216