zero.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 * 00006 * Copyright: 00007 * Christian Schulte, 2003 00008 * 00009 * Last modified: 00010 * $Date: 2010-07-28 17:35:33 +0200 (Wed, 28 Jul 2010) $ by $Author: schulte $ 00011 * $Revision: 11294 $ 00012 * 00013 * This file is part of Gecode, the generic constraint 00014 * development environment: 00015 * http://www.gecode.org 00016 * 00017 * Permission is hereby granted, free of charge, to any person obtaining 00018 * a copy of this software and associated documentation files (the 00019 * "Software"), to deal in the Software without restriction, including 00020 * without limitation the rights to use, copy, modify, merge, publish, 00021 * distribute, sublicense, and/or sell copies of the Software, and to 00022 * permit persons to whom the Software is furnished to do so, subject to 00023 * the following conditions: 00024 * 00025 * The above copyright notice and this permission notice shall be 00026 * included in all copies or substantial portions of the Software. 00027 * 00028 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00029 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00030 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00031 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00032 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00033 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00034 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00035 * 00036 */ 00037 00038 namespace Gecode { namespace Int { 00039 00040 /* 00041 * Constructors and initialization 00042 * 00043 */ 00044 forceinline 00045 ZeroIntView::ZeroIntView(void) {} 00046 00047 /* 00048 * Value access 00049 * 00050 */ 00051 forceinline int 00052 ZeroIntView::min(void) const { 00053 return 0; 00054 } 00055 forceinline int 00056 ZeroIntView::max(void) const { 00057 return 0; 00058 } 00059 forceinline int 00060 ZeroIntView::med(void) const { 00061 return 0; 00062 } 00063 forceinline int 00064 ZeroIntView::val(void) const { 00065 return 0; 00066 } 00067 00068 forceinline unsigned int 00069 ZeroIntView::size(void) const { 00070 return 1; 00071 } 00072 forceinline unsigned int 00073 ZeroIntView::width(void) const { 00074 return 1; 00075 } 00076 forceinline unsigned int 00077 ZeroIntView::regret_min(void) const { 00078 return 0; 00079 } 00080 forceinline unsigned int 00081 ZeroIntView::regret_max(void) const { 00082 return 0; 00083 } 00084 00085 00086 /* 00087 * Domain tests 00088 * 00089 */ 00090 forceinline bool 00091 ZeroIntView::range(void) const { 00092 return true; 00093 } 00094 forceinline bool 00095 ZeroIntView::in(int n) const { 00096 return n == 0; 00097 } 00098 forceinline bool 00099 ZeroIntView::in(double n) const { 00100 return n == 0; 00101 } 00102 00103 00104 /* 00105 * Domain update by value 00106 * 00107 */ 00108 forceinline ModEvent 00109 ZeroIntView::lq(Space&, int n) { 00110 return (0 <= n) ? ME_INT_NONE : ME_INT_FAILED; 00111 } 00112 forceinline ModEvent 00113 ZeroIntView::lq(Space&, double n) { 00114 return (0 <= n) ? ME_INT_NONE : ME_INT_FAILED; 00115 } 00116 00117 forceinline ModEvent 00118 ZeroIntView::le(Space&, int n) { 00119 return (0 < n) ? ME_INT_NONE : ME_INT_FAILED; 00120 } 00121 forceinline ModEvent 00122 ZeroIntView::le(Space&, double n) { 00123 return (0 < n) ? ME_INT_NONE : ME_INT_FAILED; 00124 } 00125 00126 forceinline ModEvent 00127 ZeroIntView::gq(Space&, int n) { 00128 return (0 >= n) ? ME_INT_NONE : ME_INT_FAILED; 00129 } 00130 forceinline ModEvent 00131 ZeroIntView::gq(Space&, double n) { 00132 return (0 >= n) ? ME_INT_NONE : ME_INT_FAILED; 00133 } 00134 00135 forceinline ModEvent 00136 ZeroIntView::gr(Space&, int n) { 00137 return (0 > n) ? ME_INT_NONE : ME_INT_FAILED; 00138 } 00139 forceinline ModEvent 00140 ZeroIntView::gr(Space&, double n) { 00141 return (0 > n) ? ME_INT_NONE : ME_INT_FAILED; 00142 } 00143 00144 forceinline ModEvent 00145 ZeroIntView::nq(Space&, int n) { 00146 return (0 != n) ? ME_INT_NONE : ME_INT_FAILED; 00147 } 00148 forceinline ModEvent 00149 ZeroIntView::nq(Space&, double n) { 00150 return (0 != n) ? ME_INT_NONE : ME_INT_FAILED; 00151 } 00152 00153 forceinline ModEvent 00154 ZeroIntView::eq(Space&, int n) { 00155 return (0 == n) ? ME_INT_NONE : ME_INT_FAILED; 00156 } 00157 forceinline ModEvent 00158 ZeroIntView::eq(Space&, double n) { 00159 return (0 == n) ? ME_INT_NONE : ME_INT_FAILED; 00160 } 00161 00162 00163 00164 /* 00165 * Iterator-based domain update 00166 * 00167 */ 00168 template<class I> 00169 forceinline ModEvent 00170 ZeroIntView::narrow_r(Space&, I& i, bool) { 00171 return i() ? ME_INT_NONE : ME_INT_FAILED; 00172 } 00173 template<class I> 00174 forceinline ModEvent 00175 ZeroIntView::inter_r(Space&, I& i, bool) { 00176 while (i() && (i.max() < 0)) 00177 ++i; 00178 return (i() && (i.min() <= 0)) ? ME_INT_NONE : ME_INT_FAILED; 00179 } 00180 template<class I> 00181 forceinline ModEvent 00182 ZeroIntView::minus_r(Space&, I& i, bool) { 00183 while (i() && (i.max() < 0)) 00184 ++i; 00185 return (i() && (i.min() <= 0)) ? ME_INT_FAILED : ME_INT_NONE; 00186 } 00187 template<class I> 00188 forceinline ModEvent 00189 ZeroIntView::narrow_v(Space&, I& i, bool) { 00190 return i() ? ME_INT_NONE : ME_INT_FAILED; 00191 } 00192 template<class I> 00193 forceinline ModEvent 00194 ZeroIntView::inter_v(Space&, I& i, bool) { 00195 while (i() && (i.val() < 0)) 00196 ++i; 00197 return (i() && (i.val() == 0)) ? ME_INT_NONE : ME_INT_FAILED; 00198 } 00199 template<class I> 00200 forceinline ModEvent 00201 ZeroIntView::minus_v(Space&, I& i, bool) { 00202 while (i() && (i.val() < 0)) 00203 ++i; 00204 return (i() && (i.val() == 0)) ? ME_INT_FAILED : ME_INT_NONE; 00205 } 00206 00207 /* 00208 * Delta information for advisors 00209 * 00210 */ 00211 forceinline int 00212 ZeroIntView::min(const Delta&) const { 00213 return 1; 00214 } 00215 forceinline int 00216 ZeroIntView::max(const Delta&) const { 00217 return 0; 00218 } 00219 forceinline bool 00220 ZeroIntView::any(const Delta&) const { 00221 return true; 00222 } 00223 00224 00229 template<> 00230 class ViewRanges<ZeroIntView> { 00231 private: 00233 bool done; 00234 public: 00236 00237 00238 ViewRanges(void); 00240 ViewRanges(const ZeroIntView& x); 00242 void init(const ZeroIntView& x); 00244 00246 00247 00248 bool operator ()(void) const; 00250 void operator ++(void); 00252 00254 00255 00256 int min(void) const; 00258 int max(void) const; 00260 unsigned int width(void) const; 00262 }; 00263 00264 forceinline 00265 ViewRanges<ZeroIntView>::ViewRanges(void) {} 00266 00267 forceinline 00268 ViewRanges<ZeroIntView>::ViewRanges(const ZeroIntView&) 00269 : done(false) {} 00270 00271 forceinline bool 00272 ViewRanges<ZeroIntView>::operator ()(void) const { 00273 return !done; 00274 } 00275 forceinline void 00276 ViewRanges<ZeroIntView>::operator ++(void) { 00277 done=true; 00278 } 00279 00280 forceinline int 00281 ViewRanges<ZeroIntView>::min(void) const { 00282 return 0; 00283 } 00284 forceinline int 00285 ViewRanges<ZeroIntView>::max(void) const { 00286 return 0; 00287 } 00288 forceinline unsigned int 00289 ViewRanges<ZeroIntView>::width(void) const { 00290 return 1; 00291 } 00292 00293 /* 00294 * View comparison 00295 * 00296 */ 00297 forceinline bool 00298 same(const ZeroIntView&, const ZeroIntView&) { 00299 return true; 00300 } 00301 00302 }} 00303 00304 // STATISTICS: int-var 00305