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 * Vincent Barichard <Vincent.Barichard@univ-angers.fr> 6 * 7 * Copyright: 8 * Christian Schulte, 2002 9 * Vincent Barichard, 2012 10 * 11 * This file is part of Gecode, the generic constraint 12 * development environment: 13 * http://www.gecode.org 14 * 15 * Permission is hereby granted, free of charge, to any person obtaining 16 * a copy of this software and associated documentation files (the 17 * "Software"), to deal in the Software without restriction, including 18 * without limitation the rights to use, copy, modify, merge, publish, 19 * distribute, sublicense, and/or sell copies of the Software, and to 20 * permit persons to whom the Software is furnished to do so, subject to 21 * the following conditions: 22 * 23 * The above copyright notice and this permission notice shall be 24 * included in all copies or substantial portions of the Software. 25 * 26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 * 34 */ 35 36namespace Gecode { namespace Float { 37 38 /* 39 * Constructors and initialization 40 * 41 */ 42 forceinline 43 ScaleView::ScaleView(void) {} 44 forceinline 45 ScaleView::ScaleView(FloatVal d, const FloatView& y) 46 : DerivedView<FloatView>(y), a(d) {} 47 48 49 /* 50 * Value access 51 * 52 */ 53 forceinline FloatVal 54 ScaleView::scale(void) const { 55 return a; 56 } 57 forceinline FloatVal 58 ScaleView::domain(void) const { 59 return x.domain()*a; 60 } 61 forceinline FloatNum 62 ScaleView::min(void) const { 63 FloatVal c = x.min(); c *= a; return c.min(); 64 } 65 forceinline FloatNum 66 ScaleView::max(void) const { 67 FloatVal c = x.max(); c *= a; return c.max(); 68 } 69 forceinline FloatNum 70 ScaleView::med(void) const { 71 FloatVal c = x.med(); c *= a; return (c.min()+c.max())/2; 72 } 73 forceinline FloatVal 74 ScaleView::val(void) const { 75 FloatVal c = x.val(); c *= a; return c; 76 } 77 78 forceinline FloatNum 79 ScaleView::size(void) const { 80 FloatVal c = x.size(); c *= a; return c.max(); 81 } 82 83 84 /* 85 * Domain tests 86 * 87 */ 88 forceinline bool 89 ScaleView::zero_in(void) const { 90 return x.zero_in(); 91 } 92 forceinline bool 93 ScaleView::in(FloatNum n) const { 94 return x.in(n/a); 95 } 96 forceinline bool 97 ScaleView::in(const FloatVal& n) const { 98 return x.in(n/a); 99 } 100 101 102 /* 103 * Domain update by value 104 * 105 */ 106 forceinline ModEvent 107 ScaleView::lq(Space& home, int n) { 108 FloatVal c = n; c /= a; 109 return x.lq(home,c.max()); 110 } 111 forceinline ModEvent 112 ScaleView::lq(Space& home, FloatNum n) { 113 FloatVal c = n; c /= a; 114 return x.lq(home,c.max()); 115 } 116 forceinline ModEvent 117 ScaleView::lq(Space& home, FloatVal n) { 118 FloatVal c = n; c /= a; 119 return x.lq(home,c.max()); 120 } 121 122 forceinline ModEvent 123 ScaleView::gq(Space& home, int n) { 124 FloatVal c = n; c /= a; 125 return x.gq(home,c.min()); 126 } 127 forceinline ModEvent 128 ScaleView::gq(Space& home, FloatNum n) { 129 FloatVal c = n; c /= a; 130 return x.gq(home,c.min()); 131 } 132 forceinline ModEvent 133 ScaleView::gq(Space& home, FloatVal n) { 134 FloatVal c = n; c /= a; 135 return x.gq(home,c.min()); 136 } 137 138 forceinline ModEvent 139 ScaleView::eq(Space& home, int n) { 140 FloatVal c = n; c /= a; 141 return x.eq(home,c); 142 } 143 forceinline ModEvent 144 ScaleView::eq(Space& home, FloatNum n) { 145 FloatVal c = n; c /= a; 146 return x.eq(home,c); 147 } 148 forceinline ModEvent 149 ScaleView::eq(Space& home, const FloatVal& n) { 150 FloatVal c = n; c /= a; 151 return x.eq(home,c); 152 } 153 154 155 /* 156 * Delta information for advisors 157 * 158 */ 159 forceinline FloatNum 160 ScaleView::min(const Delta& d) const { 161 FloatVal c = x.min(d); c *= a; return c.min(); 162 } 163 forceinline FloatNum 164 ScaleView::max(const Delta& d) const { 165 FloatVal c = x.max(d); c *= a; return c.max(); 166 } 167 168 forceinline ModEventDelta 169 ScaleView::med(ModEvent me) { 170 return VarImpView<FloatVar>::med(me); 171 } 172 173 174 /* 175 * Cloning 176 * 177 */ 178 forceinline void 179 ScaleView::update(Space& home, ScaleView& y) { 180 DerivedView<FloatView>::update(home,y); 181 a=y.a; 182 } 183 184 /* 185 * Ordering 186 * 187 */ 188 forceinline bool 189 ScaleView::operator <(const ScaleView& y) const { 190 return ((base() < y.base()) 191 || ((base() == y.base()) && (scale() < y.scale()))); 192 } 193 194 195 /* 196 * View comparison 197 * 198 */ 199 forceinline bool 200 operator ==(const ScaleView& x, const ScaleView& y) { 201 return (x.base() == y.base()) && (x.scale() == y.scale()); 202 } 203 forceinline bool 204 operator !=(const ScaleView& x, const ScaleView& y) { 205 return !(x == y); 206 } 207 208}} 209 210// STATISTICS: float-var 211