this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Filip Konvicka <filip.konvicka@logis.cz> 5 * Lubomir Moric <lubomir.moric@logis.cz> 6 * Vincent Barichard <Vincent.Barichard@univ-angers.fr> 7 * 8 * Contributing authors: 9 * Christian Schulte <schulte@gecode.org> 10 * 11 * Copyright: 12 * LOGIS, s.r.o., 2008 13 * Christian Schulte, 2010 14 * Vincent Barichard, 2012 15 * 16 * This file is part of Gecode, the generic constraint 17 * development environment: 18 * http://www.gecode.org 19 * 20 * Permission is hereby granted, free of charge, to any person obtaining 21 * a copy of this software and associated documentation files (the 22 * "Software"), to deal in the Software without restriction, including 23 * without limitation the rights to use, copy, modify, merge, publish, 24 * distribute, sublicense, and/or sell copies of the Software, and to 25 * permit persons to whom the Software is furnished to do so, subject to 26 * the following conditions: 27 * 28 * The above copyright notice and this permission notice shall be 29 * included in all copies or substantial portions of the Software. 30 * 31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 38 * 39 */ 40 41#include <cmath> 42 43namespace Gecode { namespace Float { 44 45 class FloatVarImp; 46 47 /// Float delta information for advisors 48 class FloatDelta : public Delta { 49 friend class FloatVarImp; 50 private: 51 FloatNum _min; ///< Minimum value just pruned 52 FloatNum _max; ///< Largest value just pruned 53 public: 54 /// Create float delta as providing no information 55 FloatDelta(void); 56 /// Create float delta with \a min and \a max 57 FloatDelta(FloatNum min, FloatNum max); 58 private: 59 /// Return minimum 60 FloatNum min(void) const; 61 /// Return maximum 62 FloatNum max(void) const; 63 }; 64 65}} 66 67#include <gecode/float/var-imp/delta.hpp> 68 69namespace Gecode { namespace Float { 70 71 /** 72 * \brief Float variable implementation 73 * 74 * \ingroup Other 75 */ 76 class FloatVarImp : public FloatVarImpBase { 77 protected: 78 /// Domain information 79 FloatVal dom; 80 /// Constructor for cloning \a x 81 FloatVarImp(Space& home, FloatVarImp& x); 82 public: 83 /// Initialize with interval \a d 84 FloatVarImp(Space& home, const FloatVal& d); 85 86 /// \name Value access 87 //@{ 88 /// Return domain 89 FloatVal domain(void) const; 90 /// Return minimum of domain 91 FloatNum min(void) const; 92 /// Return maximum of domain 93 FloatNum max(void) const; 94 /// Return value of domain (only if assigned) 95 FloatVal val(void) const; 96 /// Return median of domain (closest representation) 97 FloatNum med(void) const; 98 99 /// Return width of domain (distance between maximum and minimum) 100 FloatNum size(void) const; 101 //@} 102 103 /// \name Domain tests 104 //@{ 105 /// Test whether variable is assigned 106 bool assigned(void) const; 107 108 /// Test whether 0 is contained in domain 109 bool zero_in(void) const; 110 /// Test whether \a n is contained in domain 111 bool in(FloatNum n) const; 112 /// Test whether \a n is contained in domain 113 bool in(const FloatVal& n) const; 114 //@} 115 116 /// \name Domain update by value 117 //@{ 118 /// Restrict domain values to be equal to \a n 119 ModEvent eq(Space& home, FloatNum n); 120 /// Restrict domain values to be equal to \a n 121 ModEvent eq(Space& home, const FloatVal& n); 122 /// Restrict domain values to be less or equal than \a n 123 ModEvent lq(Space& home, FloatNum n); 124 /// Restrict domain values to be less or equal than \a n 125 ModEvent lq(Space& home, const FloatVal& n); 126 /// Restrict domain values to be greater or equal than \a n 127 ModEvent gq(Space& home, FloatNum n); 128 /// Restrict domain values to be greater or equal than \a n 129 ModEvent gq(Space& home, const FloatVal& n); 130 //@} 131 132 /// \name Dependencies 133 //@{ 134 /** 135 * \brief Subscribe propagator \a p with propagation condition \a pc to variable 136 * 137 * In case \a schedule is false, the propagator is just subscribed but 138 * not scheduled for execution (this must be used when creating 139 * subscriptions during propagation). 140 * 141 */ 142 GECODE_FLOAT_EXPORT void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true); 143 /// Re-schedule propagator \a p with propagation condition \a pc 144 GECODE_FLOAT_EXPORT void reschedule(Space& home, Propagator& p, PropCond pc); 145 /** \brief Subscribe advisor \a a to variable 146 * 147 * The advisor \a a is only subscribed if \a assigned is false. 148 * 149 * If \a fail is true, the advisor \a a is also run when a variable 150 * operation triggers failure. This feature is undocumented. 151 * 152 */ 153 GECODE_FLOAT_EXPORT void subscribe(Space& home, Advisor& a, bool fail); 154 //@} 155 156 /// \name Variable implementation-dependent propagator support 157 //@{ 158 /// Translate modification event \a me to modification event delta for view 159 static ModEventDelta med(ModEvent me); 160 //@} 161 162 163 private: 164 /// Return copy of not-yet copied variable 165 GECODE_FLOAT_EXPORT FloatVarImp* perform_copy(Space& home); 166 public: 167 /// \name Cloning 168 //@{ 169 /// Return copy of this variable 170 FloatVarImp* copy(Space& home); 171 //@} 172 173 /// \name Delta information for advisors 174 //@{ 175 /// Return minimum value just pruned 176 static FloatNum min(const Delta& d); 177 /// Return maximum value just pruned 178 static FloatNum max(const Delta& d); 179 //@} 180 }; 181 182}} 183 184#include <gecode/float/var-imp/float.hpp> 185 186// STATISTICS: float-var 187