Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
17 kB · 560 lines
C++
at develop
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- *//* * Main authors: * Christian Schulte <schulte@gecode.org> * Vincent Barichard <Vincent.Barichard@univ-angers.fr> * * Copyright: * Christian Schulte, 2005 * Vincent Barichard, 2012 * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */
#include <iostream>
namespace Gecode { namespace Float {
/** * \defgroup TaskActorFloatView Float views * * Float propagators and branchers compute with float views. * Float views provide views on float variable implementations. * \ingroup TaskActorFloat */
/** * \brief Float view for float variables * \ingroup TaskActorFloatView */ class FloatView : public VarImpView<FloatVar> { protected: using VarImpView<FloatVar>::x; public: /// \name Constructors and initialization //@{ /// Default constructor FloatView(void); /// Initialize from float variable \a y FloatView(const FloatVar& y); /// Initialize from float variable \a y FloatView(FloatVarImp* y); //@}
/// \name Value access //@{ /// Return domain FloatVal domain(void) const; /// Return minimum of domain FloatNum min(void) const; /// Return maximum of domain FloatNum max(void) const; /// Return median of domain (closest representation) FloatNum med(void) const; /** * \brief Return assigned value * * Throws an exception of type Float::ValOfUnassignedVar if variable * is not yet assigned. * */ FloatVal val(void) const;
/// Return size of domain (distance between maximum and minimum) FloatNum size(void) const; //@}
/// \name Domain tests //@{ /// Test whether 0 is contained in domain bool zero_in(void) const; /// Test whether \a n is contained in domain bool in(FloatNum n) const; /// Test whether \a n is contained in domain bool in(const FloatVal& n) const; //@}
/// \name Domain update by value //@{ /// Restrict domain values to be less or equal than \a n ModEvent lq(Space& home, int n); /// Restrict domain values to be less or equal than \a n ModEvent lq(Space& home, FloatNum n); /// Restrict domain values to be less or equal than \a n ModEvent lq(Space& home, FloatVal n);
/// Restrict domain values to be greater or equal than \a n ModEvent gq(Space& home, int n); /// Restrict domain values to be greater or equal than \a n ModEvent gq(Space& home, FloatNum n); /// Restrict domain values to be greater or equal than \a n ModEvent gq(Space& home, FloatVal n);
/// Restrict domain values to be equal to \a n ModEvent eq(Space& home, int n); /// Restrict domain values to be equal to \a n ModEvent eq(Space& home, FloatNum n); /// Restrict domain values to be equal to \a n ModEvent eq(Space& home, const FloatVal& n);
//@}
/// \name Delta information for advisors //@{ /// Return minimum value just pruned FloatNum min(const Delta& d) const; /// Return maximum value just pruned FloatNum max(const Delta& d) const; //@}
/// \name View-dependent propagator support //@{ /// Translate modification event \a me to modification event delta for view static ModEventDelta med(ModEvent me); //@} };
/** * \brief Print float variable view * \relates Gecode::Float::FloatView */ template<class Char, class Traits> std::basic_ostream<Char,Traits>& operator <<(std::basic_ostream<Char,Traits>& os, const FloatView& x);
/** * \brief Minus float view * * A minus float view \f$m\f$ for an float view \f$x\f$ provides * operations such that \f$m\f$ behaves as \f$-x\f$. * \ingroup TaskActorFloatView */ class MinusView : public DerivedView<FloatView> { protected: using DerivedView<FloatView>::x; public: /// \name Constructors and initialization //@{ /// Default constructor MinusView(void); /// Initialize with float view \a y explicit MinusView(const FloatView& y); //@}
/// \name Value access //@{ /// Return domain FloatVal domain(void) const; /// Return minimum of domain FloatNum min(void) const; /// Return maximum of domain FloatNum max(void) const; /// Return median of domain (closest representation) FloatNum med(void) const; /** * \brief Return assigned value * * Throws an exception of type Float::ValOfUnassignedVar if variable * is not yet assigned. * */ FloatVal val(void) const;
/// Return size of domain (distance between maximum and minimum) FloatNum size(void) const; //@}
/// \name Domain tests //@{ /// Test whether 0 is contained in domain bool zero_in(void) const; /// Test whether \a n is contained in domain bool in(FloatNum n) const; /// Test whether \a n is contained in domain bool in(const FloatVal& n) const; //@}
/// \name Domain update by value //@{ /// Restrict domain values to be less or equal than \a n ModEvent lq(Space& home, int n); /// Restrict domain values to be less or equal than \a n ModEvent lq(Space& home, FloatNum n); /// Restrict domain values to be less or equal than \a n ModEvent lq(Space& home, FloatVal n);
/// Restrict domain values to be greater or equal than \a n ModEvent gq(Space& home, int n); /// Restrict domain values to be greater or equal than \a n ModEvent gq(Space& home, FloatNum n); /// Restrict domain values to be greater or equal than \a n ModEvent gq(Space& home, FloatVal n);
/// Restrict domain values to be equal to \a n ModEvent eq(Space& home, int n); /// Restrict domain values to be equal to \a n ModEvent eq(Space& home, FloatNum n); /// Restrict domain values to be equal to \a n ModEvent eq(Space& home, const FloatVal& n);
//@}
/// \name Delta information for advisors //@{ /// Return minimum value just pruned FloatNum min(const Delta& d) const; /// Return maximum value just pruned FloatNum max(const Delta& d) const; //@}
/// \name View-dependent propagator support //@{ /// Translate modification event \a me to modification event delta for view static ModEventDelta med(ModEvent me); //@} };
/** * \brief Print float minus view * \relates Gecode::Float::MinusView */ template<class Char, class Traits> std::basic_ostream<Char,Traits>& operator <<(std::basic_ostream<Char,Traits>& os, const MinusView& x);
/** \name View comparison * \relates Gecode::Float::MinusView */ //@{ /// Test whether views \a x and \a y are the same bool operator ==(const MinusView& x, const MinusView& y); /// Test whether views \a x and \a y are not the same bool operator !=(const MinusView& x, const MinusView& y); //@}
/** * \brief OffsetView float view * * An offset float view \f$o\f$ for an float view \f$x\f$ and * an float \f$c\f$ provides operations such that \f$o\f$ * behaves as \f$x+c\f$. * \ingroup TaskActorFloatView */ class OffsetView : public DerivedView<FloatView> { protected: /// Offset FloatNum c; using DerivedView<FloatView>::x; public: /// \name Constructors and initialization //@{ /// Default constructor OffsetView(void); /// Initialize with float view \a y and an offset c explicit OffsetView(const FloatView& y, FloatNum c); //@}
/// \name Value access //@{ /// Return offset FloatNum offset(void) const; /// Change offset to be \a n void offset(FloatNum n); /// Return domain FloatVal domain(void) const; /// Return minimum of domain FloatNum min(void) const; /// Return maximum of domain FloatNum max(void) const; /// Return median of domain (closest representation) FloatNum med(void) const; /** * \brief Return assigned value * * Throws an exception of type Float::ValOfUnassignedVar if variable * is not yet assigned. * */ FloatVal val(void) const;
/// Return size of domain (distance between maximum and minimum) FloatNum size(void) const; //@}
/// \name Domain tests //@{ /// Test whether 0 is contained in domain bool zero_in(void) const; /// Test whether \a n is contained in domain bool in(FloatNum n) const; /// Test whether \a n is contained in domain bool in(const FloatVal& n) const; //@}
/// \name Domain update by value //@{ /// Restrict domain values to be less or equal than \a n ModEvent lq(Space& home, int n); /// Restrict domain values to be less or equal than \a n ModEvent lq(Space& home, FloatNum n); /// Restrict domain values to be less or equal than \a n ModEvent lq(Space& home, FloatVal n);
/// Restrict domain values to be greater or equal than \a n ModEvent gq(Space& home, int n); /// Restrict domain values to be greater or equal than \a n ModEvent gq(Space& home, FloatNum n); /// Restrict domain values to be greater or equal than \a n ModEvent gq(Space& home, FloatVal n);
/// Restrict domain values to be equal to \a n ModEvent eq(Space& home, int n); /// Restrict domain values to be equal to \a n ModEvent eq(Space& home, FloatNum n); /// Restrict domain values to be equal to \a n ModEvent eq(Space& home, const FloatVal& n);
//@}
/// \name Delta information for advisors //@{ /// Return minimum value just pruned FloatNum min(const Delta& d) const; /// Return maximum value just pruned FloatNum max(const Delta& d) const; //@}
/// \name View-dependent propagator support //@{ /// Translate modification event \a me to modification event delta for view static ModEventDelta med(ModEvent me); //@}
/// \name Cloning //@{ void update(Space& home, OffsetView& y); //@}
/// \name Ordering //@{ /// Whether this view comes before view \a y (arbitray order) bool operator <(const OffsetView& y) const; //@} };
/** * \brief Print float offset view * \relates Gecode::Float::OffsetView */ template<class Char, class Traits> std::basic_ostream<Char,Traits>& operator <<(std::basic_ostream<Char,Traits>& os, const OffsetView& x);
/** \name View comparison * \relates Gecode::Float::OffsetView */ //@{ /// Test whether views \a x and \a y are the same bool operator ==(const OffsetView& x, const OffsetView& y); /// Test whether views \a x and \a y are not the same bool operator !=(const OffsetView& x, const OffsetView& y); //@}
/** * \brief Scale float view * * A scale float view \f$s\f$ for a float view \f$x\f$ and * a non-negative float \f$a\f$ provides operations such that \f$s\f$ * behaves as \f$a\cdot x\f$. * * \ingroup TaskActorFloatView */ class ScaleView : public DerivedView<FloatView> { protected: using DerivedView<FloatView>::x; /// Scale factor FloatVal a;
public: /// \name Constructors and initialization //@{ /// Default constructor ScaleView(void); /// Initialize as \f$b\cdot y\f$ ScaleView(FloatVal b, const FloatView& y); //@}
/// \name Value access //@{ /// Return domain FloatVal domain(void) const; /// Return scale factor of scale view FloatVal scale(void) const; /// Return minimum of domain FloatNum min(void) const; /// Return maximum of domain FloatNum max(void) const; /// Return median of domain (closest representation) FloatNum med(void) const;
/** * \brief Return assigned value * * Throws an exception of type Float::ValOfUnassignedVar if variable * is not yet assigned. * */ FloatVal val(void) const;
/// Return size of domain (distance between maximum and minimum) FloatNum size(void) const; //@}
/// \name Domain tests //@{ /// Test whether 0 is contained in domain bool zero_in(void) const; /// Test whether \a n is contained in domain bool in(FloatNum n) const; /// Test whether \a n is contained in domain bool in(const FloatVal& n) const; //@}
/// \name Domain update by value //@{ /// Restrict domain values to be less or equal than \a n ModEvent lq(Space& home, int n); /// Restrict domain values to be less or equal than \a n ModEvent lq(Space& home, FloatNum n); /// Restrict domain values to be less or equal than \a n ModEvent lq(Space& home, FloatVal n);
/// Restrict domain values to be greater or equal than \a n ModEvent gq(Space& home, int n); /// Restrict domain values to be greater or equal than \a n ModEvent gq(Space& home, FloatNum n); /// Restrict domain values to be greater or equal than \a n ModEvent gq(Space& home, FloatVal n);
/// Restrict domain values to be equal to \a n ModEvent eq(Space& home, int n); /// Restrict domain values to be equal to \a n ModEvent eq(Space& home, FloatNum n); /// Restrict domain values to be equal to \a n ModEvent eq(Space& home, const FloatVal& n);
//@}
/// \name Delta information for advisors //@{ /// Return minimum value just pruned FloatNum min(const Delta& d) const; /// Return maximum value just pruned FloatNum max(const Delta& d) const; //@}
/// \name View-dependent propagator support //@{ /// Translate modification event \a me to modification event delta for view static ModEventDelta med(ModEvent me); //@}
/// \name Cloning //@{ void update(Space& home, ScaleView& y); //@}
/// \name Ordering //@{ /// Whether this view comes before view \a y (arbitray order) bool operator <(const ScaleView& y) const; //@} };
/** * \brief Print scale view * \relates Gecode::Float::ScaleView */ template<class Char, class Traits> std::basic_ostream<Char,Traits>& operator <<(std::basic_ostream<Char,Traits>& os, const ScaleView& x);
/** \name View comparison * \relates Gecode::Float::ScaleView */ //@{ /// Test whether views \a x and \a y are the same bool operator ==(const ScaleView& x, const ScaleView& y); /// Test whether views \a x and \a y are not the same bool operator !=(const ScaleView& x, const ScaleView& y); //@}
}}
#include <gecode/float/var/float.hpp>#include <gecode/float/view/float.hpp>#include <gecode/float/view/minus.hpp>#include <gecode/float/view/offset.hpp>#include <gecode/float/view/scale.hpp>#include <gecode/float/view/print.hpp>#include <gecode/float/var/print.hpp>
namespace Gecode { namespace Float { /** * \defgroup TaskActorFloatTest Testing relations between float views * \ingroup TaskActorFloat */
//@{ /// Result of testing relation enum RelTest { RT_FALSE = 0, ///< Relation does not hold RT_MAYBE = 1, ///< Relation may hold or not RT_TRUE = 2 ///< Relation does hold };
/// Test whether views \a x and \a y are equal template<class View> RelTest rtest_eq(View x, View y); /// Test whether view \a x and Float \a n are equal template<class View> RelTest rtest_eq(View x, FloatVal n);
/// Test whether view \a x is less or equal than view \a y template<class View> RelTest rtest_lq(View x, View y); /// Test whether view \a x is less or equal than float \a n template<class View> RelTest rtest_lq(View x, FloatVal n);
/// Test whether view \a x is less than view \a y template<class View> RelTest rtest_le(View x, View y); /// Test whether view \a x is less or equal than float \a n template<class View> RelTest rtest_le(View x, FloatVal n);
//@}
}}
#include <gecode/float/view/rel-test.hpp>
// STATISTICS: float-var