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-06-29 10:39:13 +0200 (Tue, 29 Jun 2010) $ by $Author: schulte $ 00011 * $Revision: 11118 $ 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 Iter::Ranges::Minus<I> mi(i); 00166 return x.narrow_r(home,mi,false); 00167 } 00168 template<class I> 00169 forceinline ModEvent 00170 MinusView::inter_r(Space& home, I& i, bool) { 00171 Iter::Ranges::Minus<I> mi(i); 00172 return x.inter_r(home,mi,false); 00173 } 00174 template<class I> 00175 forceinline ModEvent 00176 MinusView::minus_r(Space& home, I& i, bool) { 00177 Iter::Ranges::Minus<I> mi(i); 00178 return x.minus_r(home,mi,false); 00179 } 00180 template<class I> 00181 forceinline ModEvent 00182 MinusView::narrow_v(Space& home, I& i, bool) { 00183 Iter::Values::Minus<I> mi(i); 00184 return x.narrow_v(home,mi,false); 00185 } 00186 template<class I> 00187 forceinline ModEvent 00188 MinusView::inter_v(Space& home, I& i, bool) { 00189 Iter::Values::Minus<I> mi(i); 00190 return x.inter_v(home,mi,false); 00191 } 00192 template<class I> 00193 forceinline ModEvent 00194 MinusView::minus_v(Space& home, I& i, bool) { 00195 Iter::Values::Minus<I> mi(i); 00196 return x.minus_v(home,mi,false); 00197 } 00198 00199 00200 /* 00201 * Propagator modification events 00202 * 00203 */ 00204 forceinline ModEventDelta 00205 MinusView::med(ModEvent me) { 00206 return IntView::med(me); 00207 } 00208 00209 00210 /* 00211 * Delta information for advisors 00212 * 00213 */ 00214 forceinline int 00215 MinusView::min(const Delta& d) const { 00216 return -x.max(d); 00217 } 00218 forceinline int 00219 MinusView::max(const Delta& d) const { 00220 return -x.min(d); 00221 } 00222 forceinline bool 00223 MinusView::any(const Delta& d) const { 00224 return x.any(d); 00225 } 00226 00227 00232 template<> 00233 class ViewRanges<MinusView> : public IntVarImpBwd { 00234 public: 00236 00237 00238 ViewRanges(void); 00240 ViewRanges(const MinusView& x); 00242 void init(const MinusView& x); 00244 00246 00247 00248 int min(void) const; 00250 int max(void) const; 00252 }; 00253 00254 forceinline 00255 ViewRanges<MinusView>::ViewRanges(void) {} 00256 00257 forceinline 00258 ViewRanges<MinusView>::ViewRanges(const MinusView& x) 00259 : IntVarImpBwd(x.base().varimp()) {} 00260 00261 forceinline void 00262 ViewRanges<MinusView>::init(const MinusView& x) { 00263 IntVarImpBwd::init(x.base().varimp()); 00264 } 00265 00266 forceinline int 00267 ViewRanges<MinusView>::min(void) const { 00268 return -IntVarImpBwd::max(); 00269 } 00270 forceinline int 00271 ViewRanges<MinusView>::max(void) const { 00272 return -IntVarImpBwd::min(); 00273 } 00274 00275 inline int 00276 MinusView::med(void) const { 00277 if (x.range()) 00278 return (min()+max())/2 - ((min()+max())%2 < 0 ? 1 : 0); 00279 00280 unsigned int i = x.size() / 2; 00281 if (size() % 2 == 0) 00282 i--; 00283 ViewRanges<MinusView> r(*this); 00284 while (i >= r.width()) { 00285 i -= r.width(); 00286 ++r; 00287 } 00288 return r.min() + static_cast<int>(i); 00289 } 00290 00291 }} 00292 00293 // STATISTICS: int-var 00294