offset.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, 2002 00008 * 00009 * Last modified: 00010 * $Date: 2010-10-06 22:42:28 +0200 (Wed, 06 Oct 2010) $ by $Author: schulte $ 00011 * $Revision: 11464 $ 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 OffsetView::OffsetView(void) {} 00046 forceinline 00047 OffsetView::OffsetView(const IntView& y, int d) 00048 : DerivedView<IntView>(y), c(d) {} 00049 00050 00051 /* 00052 * Value access 00053 * 00054 */ 00055 forceinline int 00056 OffsetView::offset(void) const { 00057 return c; 00058 } 00059 forceinline void 00060 OffsetView::offset(int n) { 00061 c = n; 00062 } 00063 forceinline int 00064 OffsetView::min(void) const { 00065 return x.min()+c; 00066 } 00067 forceinline int 00068 OffsetView::max(void) const { 00069 return x.max()+c; 00070 } 00071 forceinline int 00072 OffsetView::med(void) const { 00073 return x.med()+c; 00074 } 00075 forceinline int 00076 OffsetView::val(void) const { 00077 return x.val()+c; 00078 } 00079 00080 forceinline unsigned int 00081 OffsetView::width(void) const { 00082 return x.width(); 00083 } 00084 forceinline unsigned int 00085 OffsetView::size(void) const { 00086 return x.size(); 00087 } 00088 forceinline unsigned int 00089 OffsetView::regret_min(void) const { 00090 return x.regret_min(); 00091 } 00092 forceinline unsigned int 00093 OffsetView::regret_max(void) const { 00094 return x.regret_max(); 00095 } 00096 00097 /* 00098 * Domain tests 00099 * 00100 */ 00101 forceinline bool 00102 OffsetView::range(void) const { 00103 return x.range(); 00104 } 00105 forceinline bool 00106 OffsetView::in(int n) const { 00107 return x.in(n-c); 00108 } 00109 forceinline bool 00110 OffsetView::in(double n) const { 00111 return x.in(n-c); 00112 } 00113 00114 00115 /* 00116 * Domain update by value 00117 * 00118 */ 00119 forceinline ModEvent 00120 OffsetView::lq(Space& home, int n) { 00121 return x.lq(home,n-c); 00122 } 00123 forceinline ModEvent 00124 OffsetView::lq(Space& home, double n) { 00125 return x.lq(home,n-c); 00126 } 00127 forceinline ModEvent 00128 OffsetView::le(Space& home, int n) { 00129 return x.le(home,n-c); 00130 } 00131 forceinline ModEvent 00132 OffsetView::le(Space& home, double n) { 00133 return x.le(home,n-c); 00134 } 00135 forceinline ModEvent 00136 OffsetView::gq(Space& home, int n) { 00137 return x.gq(home,n-c); 00138 } 00139 forceinline ModEvent 00140 OffsetView::gq(Space& home, double n) { 00141 return x.gq(home,n-c); 00142 } 00143 forceinline ModEvent 00144 OffsetView::gr(Space& home, int n) { 00145 return x.gr(home,n-c); 00146 } 00147 forceinline ModEvent 00148 OffsetView::gr(Space& home, double n) { 00149 return x.gr(home,n-c); 00150 } 00151 forceinline ModEvent 00152 OffsetView::nq(Space& home, int n) { 00153 return x.nq(home,n-c); 00154 } 00155 forceinline ModEvent 00156 OffsetView::nq(Space& home, double n) { 00157 return x.nq(home,n-c); 00158 } 00159 forceinline ModEvent 00160 OffsetView::eq(Space& home, int n) { 00161 return x.eq(home,n-c); 00162 } 00163 forceinline ModEvent 00164 OffsetView::eq(Space& home, double n) { 00165 return x.eq(home,n-c); 00166 } 00167 00168 00169 /* 00170 * Iterator-based domain update 00171 * 00172 */ 00173 template<class I> 00174 forceinline ModEvent 00175 OffsetView::narrow_r(Space& home, I& i, bool depend) { 00176 Iter::Ranges::Offset<I> oi(i,-c); 00177 return x.narrow_r(home,oi,depend); 00178 } 00179 template<class I> 00180 forceinline ModEvent 00181 OffsetView::inter_r(Space& home, I& i, bool depend) { 00182 Iter::Ranges::Offset<I> oi(i,-c); 00183 return x.inter_r(home,oi,depend); 00184 } 00185 template<class I> 00186 forceinline ModEvent 00187 OffsetView::minus_r(Space& home, I& i, bool depend) { 00188 Iter::Ranges::Offset<I> oi(i,-c); 00189 return x.minus_r(home,oi,depend); 00190 } 00191 template<class I> 00192 forceinline ModEvent 00193 OffsetView::narrow_v(Space& home, I& i, bool depend) { 00194 Iter::Values::Offset<I> oi(i,-c); 00195 return x.narrow_v(home,oi,depend); 00196 } 00197 template<class I> 00198 forceinline ModEvent 00199 OffsetView::inter_v(Space& home, I& i, bool depend) { 00200 Iter::Values::Offset<I> oi(i,-c); 00201 return x.inter_v(home,oi,depend); 00202 } 00203 template<class I> 00204 forceinline ModEvent 00205 OffsetView::minus_v(Space& home, I& i, bool depend) { 00206 Iter::Values::Offset<I> oi(i,-c); 00207 return x.minus_v(home,oi,depend); 00208 } 00209 00210 00211 00212 /* 00213 * Propagator modification events 00214 * 00215 */ 00216 forceinline ModEventDelta 00217 OffsetView::med(ModEvent me) { 00218 return IntView::med(me); 00219 } 00220 00221 00222 /* 00223 * Delta information for advisors 00224 * 00225 */ 00226 forceinline int 00227 OffsetView::min(const Delta& d) const { 00228 return x.min(d)+c; 00229 } 00230 forceinline int 00231 OffsetView::max(const Delta& d) const { 00232 return x.max(d)+c; 00233 } 00234 forceinline bool 00235 OffsetView::any(const Delta& d) const { 00236 return x.any(d); 00237 } 00238 00239 00240 00241 /* 00242 * Cloning 00243 * 00244 */ 00245 forceinline void 00246 OffsetView::update(Space& home, bool share, OffsetView& y) { 00247 DerivedView<IntView>::update(home,share,y); 00248 c=y.c; 00249 } 00250 00251 00256 template<> 00257 class ViewRanges<OffsetView> 00258 : public Iter::Ranges::Offset<ViewRanges<IntView> > { 00259 public: 00261 00262 00263 ViewRanges(void); 00265 ViewRanges(const OffsetView& x); 00267 void init(const OffsetView& x); 00269 }; 00270 00271 forceinline 00272 ViewRanges<OffsetView>::ViewRanges(void) {} 00273 00274 forceinline 00275 ViewRanges<OffsetView>::ViewRanges(const OffsetView& x) { 00276 ViewRanges<IntView> xi(x.base()); 00277 Iter::Ranges::Offset<ViewRanges<IntView> >::init(xi,x.offset()); 00278 } 00279 00280 forceinline void 00281 ViewRanges<OffsetView>::init(const OffsetView& x) { 00282 ViewRanges<IntView> xi(x.base()); 00283 Iter::Ranges::Offset<ViewRanges<IntView> >::init(xi,x.offset()); 00284 } 00285 00286 /* 00287 * View comparison 00288 * 00289 */ 00290 forceinline bool 00291 same(const OffsetView& x, const OffsetView& y) { 00292 return same(x.base(),y.base()) && (x.offset() == y.offset()); 00293 } 00294 forceinline bool 00295 before(const OffsetView& x, const OffsetView& y) { 00296 return before(x.base(),y.base()) 00297 || (same(x.base(),y.base()) && (x.offset() < y.offset())); 00298 } 00299 00300 }} 00301 00302 // STATISTICS: int-var 00303