/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Guido Tack * * Contributing authors: * Samuel Gagnon * * Copyright: * Guido Tack, 2011 * 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. * */ namespace Gecode { namespace Int { /* * Constructors and initialization * */ template forceinline CachedView::CachedView(void) : _size(0) {} template forceinline CachedView::CachedView(const View& y) : DerivedView(y), _firstRange(nullptr), _lastRange(nullptr), _size(0) {} /* * Value access * */ template forceinline int CachedView::min(void) const { return x.min(); } template forceinline int CachedView::max(void) const { return x.max(); } template forceinline int CachedView::med(void) const { return x.med(); } template forceinline int CachedView::val(void) const { return x.val(); } #ifdef GECODE_HAS_CBS template forceinline int CachedView::baseval(int val) const { return val; } #endif template forceinline unsigned int CachedView::width(void) const { return x.width(); } template forceinline unsigned int CachedView::size(void) const { return x.size(); } template forceinline unsigned int CachedView::regret_min(void) const { return x.regret_min(); } template forceinline unsigned int CachedView::regret_max(void) const { return x.regret_max(); } /* * Domain tests * */ template forceinline bool CachedView::range(void) const { return x.range(); } template forceinline bool CachedView::in(int n) const { return x.in(n); } template forceinline bool CachedView::in(long long int n) const { return x.in(n); } /* * Domain update by value * */ template forceinline ModEvent CachedView::lq(Space& home, int n) { return x.lq(home,n); } template forceinline ModEvent CachedView::lq(Space& home, long long int n) { return x.lq(home,n); } template forceinline ModEvent CachedView::le(Space& home, int n) { return x.le(home,n); } template forceinline ModEvent CachedView::le(Space& home, long long int n) { return x.le(home,n); } template forceinline ModEvent CachedView::gq(Space& home, int n) { return x.gq(home,n); } template forceinline ModEvent CachedView::gq(Space& home, long long int n) { return x.gq(home,n); } template forceinline ModEvent CachedView::gr(Space& home, int n) { return x.gr(home,n); } template forceinline ModEvent CachedView::gr(Space& home, long long int n) { return x.gr(home,n); } template forceinline ModEvent CachedView::nq(Space& home, int n) { return x.nq(home,n); } template forceinline ModEvent CachedView::nq(Space& home, long long int n) { return x.nq(home,n); } template forceinline ModEvent CachedView::eq(Space& home, int n) { return x.eq(home,n); } template forceinline ModEvent CachedView::eq(Space& home, long long int n) { return x.eq(home,n); } /* * Iterator-based domain update * */ template template forceinline ModEvent CachedView::narrow_r(Space& home, I& i, bool depend) { return x.narrow_r(home,i,depend); } template template forceinline ModEvent CachedView::inter_r(Space& home, I& i, bool depend) { return x.inter_r(home,i,depend); } template template forceinline ModEvent CachedView::minus_r(Space& home, I& i, bool depend) { return x.minus_r(home,i,depend); } template template forceinline ModEvent CachedView::narrow_v(Space& home, I& i, bool depend) { return x.narrow_v(home,i,depend); } template template forceinline ModEvent CachedView::inter_v(Space& home, I& i, bool depend) { return x.inter_v(home,i,depend); } template template forceinline ModEvent CachedView::minus_v(Space& home, I& i, bool depend) { return x.minus_v(home,i,depend); } /* * Propagator modification events * */ template forceinline ModEventDelta CachedView::med(ModEvent me) { return View::med(me); } /* * Delta information for advisors * */ template forceinline int CachedView::min(const Delta& d) const { return x.min(d); } template forceinline int CachedView::max(const Delta& d) const { return x.max(d); } template forceinline unsigned int CachedView::width(const Delta& d) const { return x.width(d); } template forceinline bool CachedView::any(const Delta& d) const { return x.any(d); } /* * Cloning * */ template void CachedView::update(Space& home, CachedView& y) { DerivedView::update(home,y); if (y._firstRange) { _firstRange = new (home) RangeList(y._firstRange->min(), y._firstRange->max(),nullptr); RangeList* cur = _firstRange; for (RangeList* y_cur = y._firstRange->next(); y_cur != nullptr; y_cur = y_cur->next()) { RangeList* next = new (home) RangeList(y_cur->min(),y_cur->max(),nullptr); cur->next(next); cur = next; } _lastRange = cur; _size = y._size; } } /* * Cache operations * */ template void CachedView::initCache(Space& home, const IntSet& s) { _firstRange = nullptr; for (int i=s.ranges(); i--;) { _firstRange = new (home) RangeList(s.min(i),s.max(i),_firstRange); if (i==s.ranges()-1) _lastRange = _firstRange; } _size = s.size(); } template void CachedView::cache(Space& home) { _firstRange->dispose(home,_lastRange); ViewRanges xr(x); _firstRange = new (home) RangeList(xr.min(),xr.max(),nullptr); ++xr; RangeList* cur = _firstRange; for (; xr(); ++xr) { RangeList* next = new (home) RangeList(xr.min(),xr.max(),nullptr); cur->next(next); cur = next; } _lastRange = cur; _size = x.size(); } template forceinline bool CachedView::modified(void) const { return x.size() != _size; } /** * \brief %Range iterator for offset integer views * \ingroup TaskActorIntView */ template class ViewRanges > : public ViewRanges { public: /// \name Constructors and initialization //@{ /// Default constructor ViewRanges(void); /// Initialize with ranges for view \a x ViewRanges(const CachedView& x); /// Initialize with ranges for view \a x void init(const CachedView& x); //@} }; template forceinline ViewRanges >::ViewRanges(void) {} template forceinline ViewRanges >::ViewRanges(const CachedView& x) { ViewRanges::init(x.base()); } template forceinline void ViewRanges >::init(const CachedView& x) { ViewRanges::init(x.base()); } template forceinline ViewDiffRanges::ViewDiffRanges(void) {} template forceinline ViewDiffRanges::ViewDiffRanges(const CachedView& x) : cr(x._firstRange), dr(x.base()) { Super::init(cr,dr); } template forceinline void ViewDiffRanges::init(const CachedView& x) { cr.init(x._firstRange); dr.init(x.base()); Super::init(cr,dr); } /* * View comparison * */ template forceinline bool operator ==(const CachedView& x, const CachedView& y) { return (x.base() == y.base()) && (x.offset() == y.offset()); } template forceinline bool operator !=(const CachedView& x, const CachedView& y) { return !(x == y); } }} // STATISTICS: int-var