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

float.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Filip Konvicka <filip.konvicka@logis.cz>
00005  *     Lubomir Moric <lubomir.moric@logis.cz>
00006  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00007  *
00008  *  Contributing authors:
00009  *     Christian Schulte <schulte@gecode.org>
00010  *
00011  *  Copyright:
00012  *     LOGIS, s.r.o., 2008
00013  *     Christian Schulte, 2010
00014  *     Vincent Barichard, 2012
00015  *
00016  *  This file is part of Gecode, the generic constraint
00017  *  development environment:
00018  *     http://www.gecode.org
00019  *
00020  *  Permission is hereby granted, free of charge, to any person obtaining
00021  *  a copy of this software and associated documentation files (the
00022  *  "Software"), to deal in the Software without restriction, including
00023  *  without limitation the rights to use, copy, modify, merge, publish,
00024  *  distribute, sublicense, and/or sell copies of the Software, and to
00025  *  permit persons to whom the Software is furnished to do so, subject to
00026  *  the following conditions:
00027  *
00028  *  The above copyright notice and this permission notice shall be
00029  *  included in all copies or substantial portions of the Software.
00030  *
00031  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00032  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00033  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00034  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00035  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00036  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00037  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00038  *
00039  */
00040 
00041 namespace Gecode { namespace Float {
00042 
00043   /*
00044    * Creation of new variable implementations
00045    *
00046    */
00047 
00048   forceinline
00049   FloatVarImp::FloatVarImp(Space& home, const FloatVal& d)
00050     : FloatVarImpBase(home), dom(d) {}
00051 
00052   forceinline
00053   FloatVarImp::FloatVarImp(Space& home, FloatVarImp& x)
00054     : FloatVarImpBase(home, x), dom(x.dom) {}
00055 
00056 
00057   /*
00058    * Operations on float variable implementations
00059    *
00060    */
00061 
00062   forceinline FloatVal
00063   FloatVarImp::domain(void) const {
00064     return dom;
00065   }
00066   forceinline FloatNum
00067   FloatVarImp::min(void) const {
00068     return dom.min();
00069   }
00070   forceinline FloatNum
00071   FloatVarImp::max(void) const {
00072     return dom.max();
00073   }
00074   forceinline FloatVal
00075   FloatVarImp::val(void) const {
00076     return dom;
00077   }
00078   forceinline FloatNum
00079   FloatVarImp::med(void) const {
00080     return dom.med();
00081   }
00082 
00083   forceinline bool
00084   FloatVarImp::assigned(void) const {
00085     return dom.tight();
00086   }
00087 
00088   forceinline FloatNum
00089   FloatVarImp::size(void) const {
00090     return dom.size();
00091   }
00092 
00093 
00094   /*
00095    * Tests
00096    *
00097    */
00098 
00099   forceinline bool
00100   FloatVarImp::zero_in(void) const {
00101     return dom.zero_in();
00102   }
00103   forceinline bool
00104   FloatVarImp::in(FloatNum n) const {
00105     return dom.in(n);
00106   }
00107   forceinline bool
00108   FloatVarImp::in(const FloatVal& n) const {
00109     return subset(n,dom);
00110   }
00111 
00112 
00113   /*
00114    * Support for delta information
00115    *
00116    */
00117   forceinline FloatNum
00118   FloatVarImp::min(const Delta& d) {
00119     return static_cast<const FloatDelta&>(d).min();
00120   }
00121   forceinline FloatNum
00122   FloatVarImp::max(const Delta& d) {
00123     return static_cast<const FloatDelta&>(d).max();
00124   }
00125 
00126 
00127   /*
00128    * Tell operations (to be inlined: performing bounds checks first)
00129    *
00130    */
00131 
00132   forceinline ModEvent
00133   FloatVarImp::gq(Space& home, FloatNum n) {
00134     if (n > dom.max())  return fail(home);
00135     if ((n <= dom.min()) || assigned()) return ME_FLOAT_NONE;
00136     FloatDelta d(dom.min(),n);
00137     ModEvent me = ME_FLOAT_BND;
00138     dom = intersect(dom,FloatVal(n,dom.max()));
00139     if (assigned()) me = ME_FLOAT_VAL;
00140     GECODE_ASSUME((me == ME_FLOAT_VAL) |
00141                   (me == ME_FLOAT_BND));
00142     return notify(home,me,d);
00143   }
00144   forceinline ModEvent
00145   FloatVarImp::gq(Space& home, const FloatVal& n) {
00146     if (n.min() > dom.max())  return fail(home);
00147     if ((n.min() <= dom.min()) || assigned()) return ME_FLOAT_NONE;
00148     FloatDelta d(dom.min(),n.min());
00149     ModEvent me = ME_FLOAT_BND;
00150     dom = intersect(dom,FloatVal(n.min(),dom.max()));
00151     if (assigned()) me = ME_FLOAT_VAL;
00152     GECODE_ASSUME((me == ME_FLOAT_VAL) |
00153                   (me == ME_FLOAT_BND));
00154     return notify(home,me,d);
00155   }
00156 
00157 
00158   forceinline ModEvent
00159   FloatVarImp::lq(Space& home, FloatNum n) {
00160     if (n < dom.min())  return fail(home);
00161     if ((n >= dom.max()) || assigned()) return ME_FLOAT_NONE;
00162     FloatDelta d(n,dom.max());
00163     ModEvent me = ME_FLOAT_BND;
00164     dom = intersect(dom,FloatVal(dom.min(),n));
00165     if (assigned()) me = ME_FLOAT_VAL;
00166     GECODE_ASSUME((me == ME_FLOAT_VAL) |
00167                   (me == ME_FLOAT_BND));
00168     return notify(home,me,d);
00169   }
00170   forceinline ModEvent
00171   FloatVarImp::lq(Space& home, const FloatVal& n) {
00172     if (n.max() < dom.min())  return fail(home);
00173     if ((n.max() >= dom.max()) || assigned()) return ME_FLOAT_NONE;
00174     FloatDelta d(n.max(),dom.max());
00175     ModEvent me = ME_FLOAT_BND;
00176     dom = intersect(dom,FloatVal(dom.min(),n.max()));
00177     if (assigned()) me = ME_FLOAT_VAL;
00178     GECODE_ASSUME((me == ME_FLOAT_VAL) |
00179                   (me == ME_FLOAT_BND));
00180     return notify(home,me,d);
00181   }
00182 
00183 
00184   forceinline ModEvent
00185   FloatVarImp::eq(Space& home, FloatNum n) {
00186     if (!dom.in(n))
00187       return fail(home);
00188     if (assigned())
00189       return ME_FLOAT_NONE;
00190     FloatDelta d;
00191     dom = n;
00192     return notify(home,ME_FLOAT_VAL,d);
00193   }
00194   forceinline ModEvent
00195   FloatVarImp::eq(Space& home, const FloatVal& n) {
00196     if (!overlap(dom,n))
00197       return fail(home);
00198     if (assigned() || subset(dom,n))
00199       return ME_FLOAT_NONE;
00200     FloatDelta d;
00201     ModEvent me = ME_FLOAT_BND;
00202     dom = intersect(dom,n);
00203     if (assigned()) me = ME_FLOAT_VAL;
00204     GECODE_ASSUME((me == ME_FLOAT_VAL) |
00205                   (me == ME_FLOAT_BND));
00206     return notify(home,me,d);
00207   }
00208 
00209 
00210   /*
00211    * Copying a variable
00212    *
00213    */
00214 
00215   forceinline FloatVarImp*
00216   FloatVarImp::copy(Space& home) {
00217     return copied() ? static_cast<FloatVarImp*>(forward())
00218       : perform_copy(home);
00219   }
00220 
00222   forceinline FloatVarImp*
00223   FloatVarImp::perform_copy(Space& home) {
00224     return new (home) FloatVarImp(home, *this);
00225   }
00226 
00227   forceinline ModEventDelta
00228   FloatVarImp::med(ModEvent me) {
00229     return FloatVarImpBase::med(me);
00230   }
00231 
00232 }}
00233 
00234 // STATISTICS: float-var