virtual-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 * Last modified: 00012 * $Date: 2009-09-08 21:10:29 +0200 (Tue, 08 Sep 2009) $ by $Author: schulte $ 00013 * $Revision: 9692 $ 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 { namespace Virt { 00041 00052 template<int UMIN, int UMAX> 00053 class Compl : public MinMax, public Iterator { 00054 protected: 00056 Iterator* i; 00058 void start(void); 00059 public: 00061 00062 00063 Compl(void); 00065 Compl(Iterator* i); 00067 ~Compl(void); 00069 00071 00072 00073 virtual int min(void) const; 00075 virtual int max(void) const; 00077 virtual unsigned int width(void) const; 00079 00081 00082 00083 void operator ++(void); 00085 virtual bool operator ()(void); 00087 }; 00088 00089 00100 class ComplVal : public MinMax, public Iterator { 00101 protected: 00103 int UMIN, UMAX; 00105 Iterator* i; 00107 void start(void); 00108 public: 00110 00111 00112 ComplVal(void); 00114 ComplVal(int umin, int umax, Iterator* i); 00116 ~ComplVal(void); 00118 00120 00121 00122 virtual int min(void) const; 00124 virtual int max(void) const; 00126 virtual unsigned int width(void) const; 00128 00130 00131 00132 void operator ++(void); 00134 virtual bool operator ()(void); 00136 }; 00137 00138 00139 template<int UMIN, int UMAX> 00140 forceinline void 00141 Compl<UMIN,UMAX>::start(void) { 00142 if ((*i)()) { 00143 assert((i->min() >= UMIN) && (i->max() <= UMAX)); 00144 if (i->min() > UMIN) { 00145 mi = UMIN; 00146 ma = i->min()-1; 00147 } else if (i->max() < UMAX) { 00148 mi = i->max()+1; 00149 ++(*i); 00150 ma = (*i)() ? (i->min()-1) : UMAX; 00151 } else { 00152 finish(); 00153 } 00154 } else { 00155 mi = UMIN; 00156 ma = UMAX; 00157 } 00158 } 00159 00160 template<int UMIN, int UMAX> 00161 forceinline 00162 Compl<UMIN,UMAX>::Compl(void) {} 00163 00164 template<int UMIN, int UMAX> 00165 forceinline 00166 Compl<UMIN,UMAX>::Compl(Iterator* i0) : i(i0) { 00167 start(); 00168 } 00169 00170 template<int UMIN, int UMAX> 00171 Compl<UMIN,UMAX>::~Compl(void) { delete i; } 00172 00173 template<int UMIN, int UMAX> 00174 forceinline void 00175 Compl<UMIN,UMAX>::operator ++(void) { 00176 assert(!(*i)() || (i->max() <= UMAX)); 00177 if ((*i)() && (i->max() < UMAX)) { 00178 mi = i->max()+1; 00179 ++(*i); 00180 ma = (*i)() ? (i->min()-1) : UMAX; 00181 } else { 00182 finish(); 00183 } 00184 } 00185 00186 template<int UMIN, int UMAX> 00187 forceinline bool 00188 Compl<UMIN,UMAX>::operator ()(void) { return MinMax::operator ()(); } 00189 00190 template<int UMIN, int UMAX> 00191 forceinline int 00192 Compl<UMIN,UMAX>::min(void) const { return MinMax::min(); } 00193 00194 template<int UMIN, int UMAX> 00195 forceinline int 00196 Compl<UMIN,UMAX>::max(void) const { return MinMax::max(); } 00197 00198 template<int UMIN, int UMAX> 00199 forceinline unsigned int 00200 Compl<UMIN,UMAX>::width(void) const { return MinMax::width(); } 00201 00202 forceinline void 00203 ComplVal::start(void) { 00204 if ((*i)()) { 00205 assert((i->min() >= UMIN) && (i->max() <= UMAX)); 00206 if (i->min() > UMIN) { 00207 mi = UMIN; 00208 ma = i->min()-1; 00209 } else if (i->max() < UMAX) { 00210 mi = i->max()+1; 00211 ++(*i); 00212 ma = (*i)() ? (i->min()-1) : UMAX; 00213 } else { 00214 finish(); 00215 } 00216 } else { 00217 mi = UMIN; 00218 ma = UMAX; 00219 } 00220 } 00221 00222 forceinline 00223 ComplVal::ComplVal(void) {} 00224 00225 forceinline 00226 ComplVal::ComplVal(int umin, int umax, Iterator* i0) 00227 : UMIN(umin), UMAX(umax), i(i0) { 00228 start(); 00229 } 00230 00231 forceinline 00232 ComplVal::~ComplVal(void) { delete i; } 00233 00234 forceinline void 00235 ComplVal::operator ++(void) { 00236 assert(!(*i)() || (i->max() <= UMAX)); 00237 if ((*i)() && (i->max() < UMAX)) { 00238 mi = i->max()+1; 00239 ++(*i); 00240 ma = (*i)() ? (i->min()-1) : UMAX; 00241 } else { 00242 finish(); 00243 } 00244 } 00245 00246 forceinline bool 00247 ComplVal::operator ()(void) { return MinMax::operator ()(); } 00248 00249 forceinline int 00250 ComplVal::min(void) const { return MinMax::min(); } 00251 00252 forceinline int 00253 ComplVal::max(void) const { return MinMax::max(); } 00254 00255 forceinline unsigned int 00256 ComplVal::width(void) const { return MinMax::width(); } 00257 00258 }}}} 00259 00260 // STATISTICS: iter-any 00261