/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Guido Tack * * Copyright: * Guido Tack, 2011 * * Last modified: * $Date: 2011-05-02 08:24:42 +1000 (Mon, 02 May 2011) $ by $Author: tack $ * $Revision: 11973 $ * * 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(NULL), _lastRange(NULL), _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(); } 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(double 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, double 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, double 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, double 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, double 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, double 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, double 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 bool CachedView::any(const Delta& d) const { return x.any(d); } /* * Cloning * */ template void CachedView::update(Space& home, bool share, CachedView& y) { DerivedView::update(home,share,y); if (y._firstRange) { _firstRange = new (home) RangeList(y._firstRange->min(), y._firstRange->max(),NULL); RangeList* cur = _firstRange; for (RangeList* y_cur = y._firstRange->next(); y_cur != NULL; y_cur = y_cur->next()) { RangeList* next = new (home) RangeList(y_cur->min(),y_cur->max(),NULL); cur->next(next); cur = next; } _lastRange = cur; _size = y._size; } } /* * Cache operations * */ template void CachedView::initCache(Space& home, const IntSet& s) { _firstRange = NULL; 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(),NULL); ++xr; RangeList* cur = _firstRange; for (; xr(); ++xr) { RangeList* next = new (home) RangeList(xr.min(),xr.max(),NULL); 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 same(const CachedView& x, const CachedView& y) { return same(x.base(),y.base()) && (x.offset() == y.offset()); } template forceinline bool before(const CachedView& x, const CachedView& y) { return before(x.base(),y.base()) || (same(x.base(),y.base()) && (x.offset() < y.offset())); } }} // STATISTICS: int-var