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 * Guido Tack <tack@gecode.org> 6 * Vincent Barichard <Vincent.Barichard@univ-angers.fr> 7 * 8 * Contributing authors: 9 * Gabor Szokoli <szokoli@gecode.org> 10 * 11 * Copyright: 12 * Christian Schulte, 2002 13 * Guido Tack, 2004 14 * Gabor Szokoli, 2003 15 * Vincent Barichard, 2012 16 * 17 * This file is part of Gecode, the generic constraint 18 * development environment: 19 * http://www.gecode.org 20 * 21 * Permission is hereby granted, free of charge, to any person obtaining 22 * a copy of this software and associated documentation files (the 23 * "Software"), to deal in the Software without restriction, including 24 * without limitation the rights to use, copy, modify, merge, publish, 25 * distribute, sublicense, and/or sell copies of the Software, and to 26 * permit persons to whom the Software is furnished to do so, subject to 27 * the following conditions: 28 * 29 * The above copyright notice and this permission notice shall be 30 * included in all copies or substantial portions of the Software. 31 * 32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 33 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 34 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 35 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 36 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 37 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 38 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 * 40 */ 41 42#ifndef GECODE_FLOAT_REL_HH 43#define GECODE_FLOAT_REL_HH 44 45#include <gecode/int.hh> 46#include <gecode/float.hh> 47 48/** 49 * \namespace Gecode::Float::Rel 50 * \brief Simple relation propagators 51 */ 52namespace Gecode { namespace Float { namespace Rel { 53 54 /* 55 * Equality propagators 56 * 57 */ 58 59 /** 60 * \brief Binary bounds consistent equality propagator 61 * 62 * Requires \code #include <gecode/float/rel.hh> \endcode 63 * \ingroup FuncFloatProp 64 */ 65 template<class View0, class View1> 66 class Eq : 67 public MixBinaryPropagator<View0,PC_FLOAT_BND,View1,PC_FLOAT_BND> { 68 protected: 69 using MixBinaryPropagator<View0,PC_FLOAT_BND,View1,PC_FLOAT_BND>::x0; 70 using MixBinaryPropagator<View0,PC_FLOAT_BND,View1,PC_FLOAT_BND>::x1; 71 72 /// Constructor for cloning \a p 73 Eq(Space& home, Eq<View0,View1>& p); 74 public: 75 /// Constructor for posting 76 Eq(Home home, View0 x0, View1 x1); 77 /// Constructor for rewriting \a p during cloning 78 Eq(Space& home, Propagator& p, View0 x0, View1 x1); 79 /// Copy propagator during cloning 80 virtual Actor* copy(Space& home); 81 /// Perform propagation 82 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 83 /// Post bounds consistent propagator \f$ x_0 = x_1\f$ 84 static ExecStatus post(Home home, View0 x0, View1 x1); 85 }; 86 87 /** 88 * \brief n-ary bounds consistent equality propagator 89 * 90 * Requires \code #include <gecode/float/rel.hh> \endcode 91 * \ingroup FuncFloatProp 92 */ 93 template<class View> 94 class NaryEq : public NaryPropagator<View,PC_FLOAT_BND> { 95 protected: 96 using NaryPropagator<View,PC_FLOAT_BND>::x; 97 98 /// Constructor for cloning \a p 99 NaryEq(Space& home, NaryEq<View>& p); 100 /// Constructor for posting 101 NaryEq(Home home, ViewArray<View>&); 102 public: 103 /// Copy propagator during cloning 104 virtual Actor* copy(Space& home); 105 /** 106 * \brief Cost function 107 * 108 * If a view has been assigned, the cost is low unary. 109 * Otherwise it is low linear. 110 */ 111 virtual PropCost cost(const Space& home, const ModEventDelta& med) const; 112 /// Perform propagation 113 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 114 /// Post bounds consistent propagator \f$ x_0 = x_1=\ldots =x_{|x|-1}\f$ 115 static ExecStatus post(Home home, ViewArray<View>& x); 116 }; 117 118 /** 119 * \brief Reified binary bounds consistent equality propagator 120 * 121 * Requires \code #include <gecode/float/rel.hh> \endcode 122 * \ingroup FuncFloatProp 123 */ 124 template<class View, class CtrlView, ReifyMode rm> 125 class ReEq : public Int::ReBinaryPropagator<View,PC_FLOAT_BND,CtrlView> { 126 protected: 127 using Int::ReBinaryPropagator<View,PC_FLOAT_BND,CtrlView>::x0; 128 using Int::ReBinaryPropagator<View,PC_FLOAT_BND,CtrlView>::x1; 129 using Int::ReBinaryPropagator<View,PC_FLOAT_BND,CtrlView>::b; 130 131 /// Constructor for cloning \a p 132 ReEq(Space& home, ReEq& p); 133 /// Constructor for posting 134 ReEq(Home home, View x0, View x1, CtrlView b); 135 public: 136 /// Copy propagator during cloning 137 virtual Actor* copy(Space& home); 138 /// Perform propagation 139 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 140 /// Post bounds consistent propagator \f$ (x_0 = x_1)\Leftrightarrow b\f$ 141 static ExecStatus post(Home home, View x0, View x1, CtrlView b); 142 }; 143 144 /** 145 * \brief Reified bounds consistent equality with float propagator 146 * 147 * Requires \code #include <gecode/float/rel.hh> \endcode 148 * \ingroup FuncFloatProp 149 */ 150 template<class View, class CtrlView, ReifyMode rm> 151 class ReEqFloat : public Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView> { 152 protected: 153 using Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>::x0; 154 using Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>::b; 155 156 /// Float constant to check 157 FloatVal c; 158 /// Constructor for cloning \a p 159 ReEqFloat(Space& home, ReEqFloat& p); 160 /// Constructor for posting 161 ReEqFloat(Home home, View x, FloatVal c, CtrlView b); 162 public: 163 /// Copy propagator during cloning 164 virtual Actor* copy(Space& home); 165 /// Perform propagation 166 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 167 /// Post bounds consistent propagator \f$ (x = c)\Leftrightarrow b\f$ 168 static ExecStatus post(Home home, View x, FloatVal c, CtrlView b); 169 }; 170 171 172 /** 173 * \brief Binary bounds consistent disequality propagator 174 * 175 * Requires \code #include <gecode/float/rel.hh> \endcode 176 * \ingroup FuncFloatProp 177 */ 178 template<class View0, class View1> 179 class Nq : 180 public MixBinaryPropagator<View0,PC_FLOAT_VAL,View1,PC_FLOAT_VAL> { 181 protected: 182 using MixBinaryPropagator<View0,PC_FLOAT_VAL,View1,PC_FLOAT_VAL>::x0; 183 using MixBinaryPropagator<View0,PC_FLOAT_VAL,View1,PC_FLOAT_VAL>::x1; 184 185 /// Constructor for cloning \a p 186 Nq(Space& home, Nq<View0,View1>& p); 187 public: 188 /// Constructor for posting 189 Nq(Home home, View0 x0, View1 x1); 190 /// Constructor for rewriting \a p during cloning 191 Nq(Space& home, Propagator& p, View0 x0, View1 x1); 192 /// Copy propagator during cloning 193 virtual Actor* copy(Space& home); 194 /// Perform propagation 195 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 196 /// Post bounds consistent propagator \f$ x_0 \neq x_1\f$ 197 static ExecStatus post(Home home, View0 x0, View1 x1); 198 }; 199 200 /** 201 * \brief Binary bounds consistent disequality propagator with float value 202 * 203 * Requires \code #include <gecode/float/rel.hh> \endcode 204 * \ingroup FuncFloatProp 205 */ 206 template<class View> 207 class NqFloat : 208 public UnaryPropagator<View,PC_FLOAT_VAL> { 209 protected: 210 using UnaryPropagator<View,PC_FLOAT_VAL>::x0; 211 212 /// Float constant to check 213 FloatVal c; 214 /// Constructor for cloning \a p 215 NqFloat(Space& home, NqFloat<View>& p); 216 public: 217 /// Constructor for posting 218 NqFloat(Home home, View x, FloatVal c); 219 /// Copy propagator during cloning 220 virtual Actor* copy(Space& home); 221 /// Perform propagation 222 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 223 /// Post bounds consistent propagator \f$ x_0 \neq c\f$ 224 static ExecStatus post(Home home, View x0, FloatVal c); 225 }; 226 227 228 /* 229 * Order propagators 230 * 231 */ 232 233 /** 234 * \brief Less or equal propagator 235 * 236 * Requires \code #include <gecode/float/rel.hh> \endcode 237 * \ingroup FuncFloatProp 238 */ 239 240 template<class View> 241 class Lq : public BinaryPropagator<View,PC_FLOAT_BND> { 242 protected: 243 using BinaryPropagator<View,PC_FLOAT_BND>::x0; 244 using BinaryPropagator<View,PC_FLOAT_BND>::x1; 245 246 /// Constructor for cloning \a p 247 Lq(Space& home, Lq& p); 248 /// Constructor for posting 249 Lq(Home home, View x0, View x1); 250 public: 251 /// Copy propagator during cloning 252 virtual Actor* copy(Space& home); 253 /// Perform propagation 254 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 255 /// Post propagator \f$x_0 \leq x_1\f$ 256 static ExecStatus post(Home home, View x0, View x1); 257 }; 258 259 /** 260 * \brief Less propagator 261 * 262 * Requires \code #include <gecode/float/rel.hh> \endcode 263 * \ingroup FuncFloatProp 264 */ 265 266 template<class View> 267 class Le : public BinaryPropagator<View,PC_FLOAT_BND> { 268 protected: 269 using BinaryPropagator<View,PC_FLOAT_BND>::x0; 270 using BinaryPropagator<View,PC_FLOAT_BND>::x1; 271 272 /// Constructor for cloning \a p 273 Le(Space& home, Le& p); 274 /// Constructor for posting 275 Le(Home home, View x0, View x1); 276 public: 277 /// Copy propagator during cloning 278 virtual Actor* copy(Space& home); 279 /// Perform propagation 280 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 281 /// Post propagator \f$x_0 \le x_1\f$ 282 static ExecStatus post(Home home, View x0, View x1); 283 }; 284 285 /* 286 * Reified order propagators 287 * 288 */ 289 290 /** 291 * \brief Reified less or equal with float propagator 292 * 293 * Requires \code #include <gecode/float/rel.hh> \endcode 294 * \ingroup FuncFloatProp 295 */ 296 297 template<class View, class CtrlView, ReifyMode rm> 298 class ReLqFloat : public Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView> { 299 protected: 300 using Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>::x0; 301 using Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>::b; 302 303 /// Float constant to check 304 FloatVal c; 305 /// Constructor for cloning \a p 306 ReLqFloat(Space& home, ReLqFloat& p); 307 /// Constructor for posting 308 ReLqFloat(Home home, View x, FloatVal c, CtrlView b); 309 public: 310 /// Copy propagator during cloning 311 virtual Actor* copy(Space& home); 312 /// Perform propagation 313 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 314 /// Post propagator for \f$ (x \leq c)\Leftrightarrow b\f$ 315 static ExecStatus post(Home home, View x, FloatVal c, CtrlView b); 316 }; 317 318 /** 319 * \brief Reified less with float propagator 320 * 321 * Requires \code #include <gecode/float/rel.hh> \endcode 322 * \ingroup FuncFloatProp 323 */ 324 325 template<class View, class CtrlView, ReifyMode rm> 326 class ReLeFloat : public Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView> { 327 protected: 328 using Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>::x0; 329 using Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>::b; 330 331 /// Float constant to check 332 FloatVal c; 333 /// Constructor for cloning \a p 334 ReLeFloat(Space& home, ReLeFloat& p); 335 /// Constructor for posting 336 ReLeFloat(Home home, View x, FloatVal c, CtrlView b); 337 public: 338 /// Copy propagator during cloning 339 virtual Actor* copy(Space& home); 340 /// Perform propagation 341 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 342 /// Post propagator for \f$ (x < c)\Leftrightarrow b\f$ 343 static ExecStatus post(Home home, View x, FloatVal c, CtrlView b); 344 }; 345 346 /** 347 * \brief Reified less or equal propagator 348 * 349 * Requires \code #include <gecode/float/rel.hh> \endcode 350 * \ingroup FuncFloatProp 351 */ 352 353 template<class View, class CtrlView, ReifyMode rm> 354 class ReLq : public Int::ReBinaryPropagator<View,PC_FLOAT_BND,CtrlView> { 355 protected: 356 using Int::ReBinaryPropagator<View,PC_FLOAT_BND,CtrlView>::x0; 357 using Int::ReBinaryPropagator<View,PC_FLOAT_BND,CtrlView>::x1; 358 using Int::ReBinaryPropagator<View,PC_FLOAT_BND,CtrlView>::b; 359 360 /// Constructor for cloning \a p 361 ReLq(Space& home, ReLq& p); 362 /// Constructor for posting 363 ReLq(Home home, View x0, View x1, CtrlView b); 364 public: 365 /// Copy propagator during cloning 366 virtual Actor* copy(Space& home); 367 /// Perform propagation 368 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 369 /// Post propagator for \f$ (x_0 \leq x_1)\Leftrightarrow b\f$ 370 static ExecStatus post(Home home, View x0, View x1, CtrlView b); 371 }; 372 373}}} 374 375#include <gecode/float/rel/eq.hpp> 376#include <gecode/float/rel/nq.hpp> 377#include <gecode/float/rel/lq-le.hpp> 378 379#endif 380 381 382// STATISTICS: float-prop 383