Generated on Thu Apr 11 13:59:03 2019 for Gecode by doxygen 1.6.3

scale.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  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2002
00009  *     Vincent Barichard, 2012
00010  *
00011  *  This file is part of Gecode, the generic constraint
00012  *  development environment:
00013  *     http://www.gecode.org
00014  *
00015  *  Permission is hereby granted, free of charge, to any person obtaining
00016  *  a copy of this software and associated documentation files (the
00017  *  "Software"), to deal in the Software without restriction, including
00018  *  without limitation the rights to use, copy, modify, merge, publish,
00019  *  distribute, sublicense, and/or sell copies of the Software, and to
00020  *  permit persons to whom the Software is furnished to do so, subject to
00021  *  the following conditions:
00022  *
00023  *  The above copyright notice and this permission notice shall be
00024  *  included in all copies or substantial portions of the Software.
00025  *
00026  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00030  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00031  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00032  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00033  *
00034  */
00035 
00036 namespace Gecode { namespace Float {
00037 
00038   /*
00039    * Constructors and initialization
00040    *
00041    */
00042   forceinline
00043   ScaleView::ScaleView(void) {}
00044   forceinline
00045   ScaleView::ScaleView(FloatVal d, const FloatView& y)
00046     : DerivedView<FloatView>(y), a(d) {}
00047 
00048 
00049   /*
00050    * Value access
00051    *
00052    */
00053   forceinline FloatVal
00054   ScaleView::scale(void) const {
00055     return a;
00056   }
00057   forceinline FloatVal
00058   ScaleView::domain(void) const {
00059     return x.domain()*a;
00060   }
00061   forceinline FloatNum
00062   ScaleView::min(void) const {
00063     FloatVal c = x.min(); c *= a; return c.min();
00064   }
00065   forceinline FloatNum
00066   ScaleView::max(void) const {
00067     FloatVal c = x.max(); c *= a; return c.max();
00068   }
00069   forceinline FloatNum
00070   ScaleView::med(void) const {
00071     FloatVal c = x.med(); c *= a; return (c.min()+c.max())/2;
00072   }
00073   forceinline FloatVal
00074   ScaleView::val(void) const {
00075     FloatVal c = x.val(); c *= a; return c;
00076   }
00077 
00078   forceinline FloatNum
00079   ScaleView::size(void) const {
00080     FloatVal c = x.size(); c *= a; return c.max();
00081   }
00082 
00083 
00084   /*
00085    * Domain tests
00086    *
00087    */
00088   forceinline bool
00089   ScaleView::zero_in(void) const {
00090     return x.zero_in();
00091   }
00092   forceinline bool
00093   ScaleView::in(FloatNum n) const {
00094     return x.in(n/a);
00095   }
00096   forceinline bool
00097   ScaleView::in(const FloatVal& n) const {
00098     return x.in(n/a);
00099   }
00100 
00101 
00102   /*
00103    * Domain update by value
00104    *
00105    */
00106   forceinline ModEvent
00107   ScaleView::lq(Space& home, int n) {
00108     FloatVal c = n; c /= a;
00109     return x.lq(home,c.max());
00110   }
00111   forceinline ModEvent
00112   ScaleView::lq(Space& home, FloatNum n) {
00113     FloatVal c = n; c /= a;
00114     return x.lq(home,c.max());
00115   }
00116   forceinline ModEvent
00117   ScaleView::lq(Space& home, FloatVal n) {
00118     FloatVal c = n; c /= a;
00119     return x.lq(home,c.max());
00120   }
00121 
00122   forceinline ModEvent
00123   ScaleView::gq(Space& home, int n) {
00124     FloatVal c = n; c /= a;
00125     return x.gq(home,c.min());
00126   }
00127   forceinline ModEvent
00128   ScaleView::gq(Space& home, FloatNum n) {
00129     FloatVal c = n; c /= a;
00130     return x.gq(home,c.min());
00131   }
00132   forceinline ModEvent
00133   ScaleView::gq(Space& home, FloatVal n) {
00134     FloatVal c = n; c /= a;
00135     return x.gq(home,c.min());
00136   }
00137 
00138   forceinline ModEvent
00139   ScaleView::eq(Space& home, int n) {
00140     FloatVal c = n; c /= a;
00141     return x.eq(home,c);
00142   }
00143   forceinline ModEvent
00144   ScaleView::eq(Space& home, FloatNum n) {
00145     FloatVal c = n; c /= a;
00146     return x.eq(home,c);
00147   }
00148   forceinline ModEvent
00149   ScaleView::eq(Space& home, const FloatVal& n) {
00150     FloatVal c = n; c /= a;
00151     return x.eq(home,c);
00152   }
00153 
00154 
00155   /*
00156    * Delta information for advisors
00157    *
00158    */
00159   forceinline FloatNum
00160   ScaleView::min(const Delta& d) const {
00161     FloatVal c = x.min(d); c *= a; return c.min();
00162   }
00163   forceinline FloatNum
00164   ScaleView::max(const Delta& d) const {
00165     FloatVal c = x.max(d); c *= a; return c.max();
00166   }
00167 
00168   forceinline ModEventDelta
00169   ScaleView::med(ModEvent me) {
00170     return VarImpView<FloatVar>::med(me);
00171   }
00172 
00173 
00174   /*
00175    * Cloning
00176    *
00177    */
00178   forceinline void
00179   ScaleView::update(Space& home, ScaleView& y) {
00180     DerivedView<FloatView>::update(home,y);
00181     a=y.a;
00182   }
00183 
00184   /*
00185    * Ordering
00186    *
00187    */
00188   forceinline bool
00189   ScaleView::operator <(const ScaleView& y) const {
00190     return ((base() < y.base())
00191             || ((base() == y.base()) && (scale() < y.scale())));
00192   }
00193 
00194 
00195   /*
00196    * View comparison
00197    *
00198    */
00199   forceinline bool
00200   operator ==(const ScaleView& x, const ScaleView& y) {
00201     return (x.base() == y.base()) && (x.scale() == y.scale());
00202   }
00203   forceinline bool
00204   operator !=(const ScaleView& x, const ScaleView& y) {
00205     return !(x == y);
00206   }
00207 
00208 }}
00209 
00210 // STATISTICS: float-var
00211