/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * * Contributing authors: * Samuel Gagnon * * Copyright: * Christian Schulte, 2002 * Samuel Gagnon, 2018 * * 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 namespace Gecode { namespace Int { /* * Constructors and initialization * */ template forceinline ScaleView::ScaleView(void) {} template forceinline ScaleView::ScaleView(int b, const IntView& y) : DerivedView(y), a(b) {} /* * Value access * */ template forceinline int ScaleView::scale(void) const { return a; } template forceinline Val ScaleView::min(void) const { return static_cast(x.min()) * a; } template forceinline Val ScaleView::max(void) const { return static_cast(x.max()) * a; } template forceinline Val ScaleView::med(void) const { return static_cast(x.med()) * a; } template forceinline Val ScaleView::val(void) const { return static_cast(x.val()) * a; } #ifdef GECODE_HAS_CBS template forceinline Val ScaleView::baseval(Val val) const { return val / a; } #endif template forceinline UnsVal ScaleView::size(void) const { return static_cast(x.size()); } template forceinline UnsVal ScaleView::width(void) const { return static_cast(x.width()) * a; } template forceinline UnsVal ScaleView::regret_min(void) const { return static_cast(x.regret_min()) * a; } template forceinline UnsVal ScaleView::regret_max(void) const { return static_cast(x.regret_max()) * a; } /* * Domain tests * */ template forceinline bool ScaleView::range(void) const { return x.range(); } template forceinline bool ScaleView::in(Val n) const { return ((n % a) == 0) && x.in(n / a); } /* * Domain update by value * */ template forceinline ModEvent ScaleView::lq(Space& home, Val n) { return (n >= max()) ? ME_INT_NONE : x.lq(home,floor_div_xp(n,static_cast(a))); } template forceinline ModEvent ScaleView::le(Space& home, Val n) { return (n > max()) ? ME_INT_NONE : x.le(home,floor_div_xp(n,static_cast(a))); } template forceinline ModEvent ScaleView::gq(Space& home, Val n) { return (n <= min()) ? ME_INT_NONE : x.gq(home,ceil_div_xp(n,static_cast(a))); } template forceinline ModEvent ScaleView::gr(Space& home, Val n) { return (n < min()) ? ME_INT_NONE : x.gr(home,ceil_div_xp(n,static_cast(a))); } template forceinline ModEvent ScaleView::nq(Space& home, Val n) { return ((n % a) == 0) ? x.nq(home,n/a) : ME_INT_NONE; } template forceinline ModEvent ScaleView::eq(Space& home, Val n) { return ((n % a) == 0) ? x.eq(home,n/a) : ME_INT_FAILED; } /* * Propagator modification events * */ template forceinline ModEventDelta ScaleView::med(ModEvent me) { return IntView::med(me); } /* * Delta information for advisors * */ template forceinline Val ScaleView::min(const Delta& d) const { return static_cast(x.min(d)) * a; } template forceinline Val ScaleView::max(const Delta& d) const { return static_cast(x.max(d)) * a; } template forceinline UnsVal ScaleView::width(const Delta& d) const { return static_cast(x.width(d)) * a; } template forceinline bool ScaleView::any(const Delta& d) const { return x.any(d); } /* * Cloning * */ template forceinline void ScaleView::update(Space& home, ScaleView& y) { DerivedView::update(home,y); a=y.a; } /* * Ordering * */ template forceinline bool ScaleView::operator <(const ScaleView& y) const { return ((base() < y.base()) || ((base() == y.base()) && (scale() < y.scale()))); } /** * \brief %Range iterator for integer-precision scale integer views * \ingroup TaskActorIntView */ template<> class ViewRanges : public Iter::Ranges::ScaleUp > { public: /// \name Constructors and initialization //@{ /// Default constructor ViewRanges(void); /// Initialize with ranges for view \a x ViewRanges(const IntScaleView& x); /// Initialize with ranges for view \a x void init(const IntScaleView& x); //@} }; forceinline ViewRanges::ViewRanges(void) {} forceinline ViewRanges::ViewRanges(const IntScaleView& x) { ViewRanges xi(x.base()); Iter::Ranges::ScaleUp >::init (xi,x.scale()); } forceinline void ViewRanges::init(const IntScaleView& x) { ViewRanges xi(x.base()); Iter::Ranges::ScaleUp >::init (xi,x.scale()); } /** * \brief %Range iterator for long long int-precision scale integer views * \ingroup TaskActorIntView */ template<> class ViewRanges : public Iter::Ranges::ScaleUp > { public: /// \name Constructors and initialization //@{ /// Default constructor ViewRanges(void); /// Initialize with ranges for view \a x ViewRanges(const LLongScaleView& x); /// Initialize with ranges for view \a x void init(const LLongScaleView& x); //@} }; forceinline ViewRanges::ViewRanges(void) {} forceinline ViewRanges::ViewRanges(const LLongScaleView& x) { ViewRanges xi(x.base()); Iter::Ranges::ScaleUp >::init(xi,x.scale()); } forceinline void ViewRanges::init(const LLongScaleView& x) { ViewRanges xi(x.base()); Iter::Ranges::ScaleUp >::init(xi,x.scale()); } /* * View comparison * */ template forceinline bool operator ==(const ScaleView& x, const ScaleView& y) { return (x.base() == y.base()) && (x.scale() == y.scale()); } template forceinline bool operator !=(const ScaleView& x, const ScaleView& y) { return !(x == y); } }} // STATISTICS: int-var