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