this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * 6 * Contributing authors: 7 * Samuel Gagnon <samuel.gagnon92@gmail.com> 8 * 9 * Copyright: 10 * Christian Schulte, 2002 11 * Samuel Gagnon, 2018 12 * 13 * This file is part of Gecode, the generic constraint 14 * development environment: 15 * http://www.gecode.org 16 * 17 * Permission is hereby granted, free of charge, to any person obtaining 18 * a copy of this software and associated documentation files (the 19 * "Software"), to deal in the Software without restriction, including 20 * without limitation the rights to use, copy, modify, merge, publish, 21 * distribute, sublicense, and/or sell copies of the Software, and to 22 * permit persons to whom the Software is furnished to do so, subject to 23 * the following conditions: 24 * 25 * The above copyright notice and this permission notice shall be 26 * included in all copies or substantial portions of the Software. 27 * 28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 31 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 32 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 33 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 34 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 * 36 */ 37 38#include <gecode/int/div.hh> 39 40namespace Gecode { namespace Int { 41 42 /* 43 * Constructors and initialization 44 * 45 */ 46 template<class Val, class UnsVal> 47 forceinline 48 ScaleView<Val,UnsVal>::ScaleView(void) {} 49 50 template<class Val, class UnsVal> 51 forceinline 52 ScaleView<Val,UnsVal>::ScaleView(int b, const IntView& y) 53 : DerivedView<IntView>(y), a(b) {} 54 55 56 /* 57 * Value access 58 * 59 */ 60 template<class Val, class UnsVal> 61 forceinline int 62 ScaleView<Val,UnsVal>::scale(void) const { 63 return a; 64 } 65 template<class Val, class UnsVal> 66 forceinline Val 67 ScaleView<Val,UnsVal>::min(void) const { 68 return static_cast<Val>(x.min()) * a; 69 } 70 71 template<class Val, class UnsVal> 72 forceinline Val 73 ScaleView<Val,UnsVal>::max(void) const { 74 return static_cast<Val>(x.max()) * a; 75 } 76 77 template<class Val, class UnsVal> 78 forceinline Val 79 ScaleView<Val,UnsVal>::med(void) const { 80 return static_cast<Val>(x.med()) * a; 81 } 82 83 template<class Val, class UnsVal> 84 forceinline Val 85 ScaleView<Val,UnsVal>::val(void) const { 86 return static_cast<Val>(x.val()) * a; 87 } 88#ifdef GECODE_HAS_CBS 89 template<class Val, class UnsVal> 90 forceinline Val 91 ScaleView<Val,UnsVal>::baseval(Val val) const { 92 return val / a; 93 } 94#endif 95 96 template<class Val, class UnsVal> 97 forceinline UnsVal 98 ScaleView<Val,UnsVal>::size(void) const { 99 return static_cast<UnsVal>(x.size()); 100 } 101 102 template<class Val, class UnsVal> 103 forceinline UnsVal 104 ScaleView<Val,UnsVal>::width(void) const { 105 return static_cast<UnsVal>(x.width()) * a; 106 } 107 108 template<class Val, class UnsVal> 109 forceinline UnsVal 110 ScaleView<Val,UnsVal>::regret_min(void) const { 111 return static_cast<UnsVal>(x.regret_min()) * a; 112 } 113 114 template<class Val, class UnsVal> 115 forceinline UnsVal 116 ScaleView<Val,UnsVal>::regret_max(void) const { 117 return static_cast<UnsVal>(x.regret_max()) * a; 118 } 119 120 121 /* 122 * Domain tests 123 * 124 */ 125 template<class Val, class UnsVal> 126 forceinline bool 127 ScaleView<Val,UnsVal>::range(void) const { 128 return x.range(); 129 } 130 template<class Val, class UnsVal> 131 forceinline bool 132 ScaleView<Val,UnsVal>::in(Val n) const { 133 return ((n % a) == 0) && x.in(n / a); 134 } 135 136 137 138 139 /* 140 * Domain update by value 141 * 142 */ 143 template<class Val, class UnsVal> 144 forceinline ModEvent 145 ScaleView<Val,UnsVal>::lq(Space& home, Val n) { 146 return (n >= max()) ? ME_INT_NONE : 147 x.lq(home,floor_div_xp(n,static_cast<Val>(a))); 148 } 149 150 template<class Val, class UnsVal> 151 forceinline ModEvent 152 ScaleView<Val,UnsVal>::le(Space& home, Val n) { 153 return (n > max()) ? ME_INT_NONE : 154 x.le(home,floor_div_xp(n,static_cast<Val>(a))); 155 } 156 157 template<class Val, class UnsVal> 158 forceinline ModEvent 159 ScaleView<Val,UnsVal>::gq(Space& home, Val n) { 160 return (n <= min()) ? ME_INT_NONE : 161 x.gq(home,ceil_div_xp(n,static_cast<Val>(a))); 162 } 163 template<class Val, class UnsVal> 164 forceinline ModEvent 165 ScaleView<Val,UnsVal>::gr(Space& home, Val n) { 166 return (n < min()) ? ME_INT_NONE : 167 x.gr(home,ceil_div_xp(n,static_cast<Val>(a))); 168 } 169 170 template<class Val, class UnsVal> 171 forceinline ModEvent 172 ScaleView<Val,UnsVal>::nq(Space& home, Val n) { 173 return ((n % a) == 0) ? x.nq(home,n/a) : ME_INT_NONE; 174 } 175 176 template<class Val, class UnsVal> 177 forceinline ModEvent 178 ScaleView<Val,UnsVal>::eq(Space& home, Val n) { 179 return ((n % a) == 0) ? x.eq(home,n/a) : ME_INT_FAILED; 180 } 181 182 183 /* 184 * Propagator modification events 185 * 186 */ 187 template<class Val, class UnsVal> 188 forceinline ModEventDelta 189 ScaleView<Val,UnsVal>::med(ModEvent me) { 190 return IntView::med(me); 191 } 192 193 194 195 /* 196 * Delta information for advisors 197 * 198 */ 199 template<class Val, class UnsVal> 200 forceinline Val 201 ScaleView<Val,UnsVal>::min(const Delta& d) const { 202 return static_cast<Val>(x.min(d)) * a; 203 } 204 template<class Val, class UnsVal> 205 forceinline Val 206 ScaleView<Val,UnsVal>::max(const Delta& d) const { 207 return static_cast<Val>(x.max(d)) * a; 208 } 209 template<class Val, class UnsVal> 210 forceinline UnsVal 211 ScaleView<Val,UnsVal>::width(const Delta& d) const { 212 return static_cast<UnsVal>(x.width(d)) * a; 213 } 214 template<class Val, class UnsVal> 215 forceinline bool 216 ScaleView<Val,UnsVal>::any(const Delta& d) const { 217 return x.any(d); 218 } 219 220 221 222 /* 223 * Cloning 224 * 225 */ 226 template<class Val, class UnsVal> 227 forceinline void 228 ScaleView<Val,UnsVal>::update(Space& home, ScaleView<Val,UnsVal>& y) { 229 DerivedView<IntView>::update(home,y); 230 a=y.a; 231 } 232 233 234 /* 235 * Ordering 236 * 237 */ 238 template<class Val, class UnsVal> 239 forceinline bool 240 ScaleView<Val,UnsVal>::operator <(const ScaleView<Val,UnsVal>& y) const { 241 return ((base() < y.base()) 242 || ((base() == y.base()) && (scale() < y.scale()))); 243 } 244 245 246 247 248 /** 249 * \brief %Range iterator for integer-precision scale integer views 250 * \ingroup TaskActorIntView 251 */ 252 template<> 253 class ViewRanges<IntScaleView> 254 : public Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> > { 255 public: 256 /// \name Constructors and initialization 257 //@{ 258 /// Default constructor 259 ViewRanges(void); 260 /// Initialize with ranges for view \a x 261 ViewRanges(const IntScaleView& x); 262 /// Initialize with ranges for view \a x 263 void init(const IntScaleView& x); 264 //@} 265 }; 266 267 forceinline 268 ViewRanges<IntScaleView>::ViewRanges(void) {} 269 forceinline 270 ViewRanges<IntScaleView>::ViewRanges(const IntScaleView& x) { 271 ViewRanges<IntView> xi(x.base()); 272 Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> >::init 273 (xi,x.scale()); 274 } 275 forceinline void 276 ViewRanges<IntScaleView>::init(const IntScaleView& x) { 277 ViewRanges<IntView> xi(x.base()); 278 Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> >::init 279 (xi,x.scale()); 280 } 281 282 283 /** 284 * \brief %Range iterator for long long int-precision scale integer views 285 * \ingroup TaskActorIntView 286 */ 287 template<> 288 class ViewRanges<LLongScaleView> 289 : public Iter::Ranges::ScaleUp<long long int,unsigned long long int, 290 ViewRanges<IntView> > { 291 public: 292 /// \name Constructors and initialization 293 //@{ 294 /// Default constructor 295 ViewRanges(void); 296 /// Initialize with ranges for view \a x 297 ViewRanges(const LLongScaleView& x); 298 /// Initialize with ranges for view \a x 299 void init(const LLongScaleView& x); 300 //@} 301 }; 302 303 forceinline 304 ViewRanges<LLongScaleView>::ViewRanges(void) {} 305 forceinline 306 ViewRanges<LLongScaleView>::ViewRanges(const LLongScaleView& x) { 307 ViewRanges<IntView> xi(x.base()); 308 Iter::Ranges::ScaleUp<long long int,unsigned long long int, 309 ViewRanges<IntView> >::init(xi,x.scale()); 310 } 311 forceinline void 312 ViewRanges<LLongScaleView>::init(const LLongScaleView& x) { 313 ViewRanges<IntView> xi(x.base()); 314 Iter::Ranges::ScaleUp<long long int,unsigned long long int, 315 ViewRanges<IntView> >::init(xi,x.scale()); 316 } 317 318 319 /* 320 * View comparison 321 * 322 */ 323 template<class Val, class UnsVal> 324 forceinline bool 325 operator ==(const ScaleView<Val,UnsVal>& x, const ScaleView<Val,UnsVal>& y) { 326 return (x.base() == y.base()) && (x.scale() == y.scale()); 327 } 328 template<class Val, class UnsVal> 329 forceinline bool 330 operator !=(const ScaleView<Val,UnsVal>& x, const ScaleView<Val,UnsVal>& y) { 331 return !(x == y); 332 } 333 334}} 335 336// STATISTICS: int-var 337