/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Guido Tack * * Contributing authors: * Christian Schulte * * Copyright: * Guido Tack, 2004, 2006 * Christian Schulte, 2004 * * Last modified: * $Date: 2008-01-24 13:05:13 +0100 (Thu, 24 Jan 2008) $ by $Author: tack $ * $Revision: 5974 $ * * 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 Set { template forceinline OffsetSetView::OffsetSetView(void) {} template forceinline OffsetSetView::OffsetSetView(View& s0, int k0) : DerivedViewBase(s0), k(k0) {} template forceinline OffsetSetView::OffsetSetView(Space* home, const Reflection::VarMap& vars, Reflection::Arg* arg) : DerivedViewBase(View(home, vars, arg->second())), k(arg->first()->toInt()) {} template forceinline bool OffsetSetView::assigned(void) const { return view.assigned(); } template forceinline unsigned int OffsetSetView::glbSize(void) const { return view.glbSize(); } template forceinline unsigned int OffsetSetView::lubSize(void) const { return view.lubSize(); } template forceinline unsigned int OffsetSetView::unknownSize(void) const { return view.unknownSize(); } template forceinline int OffsetSetView::offset(void) const { return k; } template forceinline bool OffsetSetView::contains(int n) const { return view.contains(n-k); } template forceinline bool OffsetSetView::notContains(int n) const { return view.notContains(n-k); } template forceinline unsigned int OffsetSetView::cardMin() const { return view.cardMin(); } template forceinline unsigned int OffsetSetView::cardMax() const { return view.cardMax(); } template forceinline int OffsetSetView::lubMin() const { if (view.cardMax() == 0) return view.lubMin(); return view.lubMin() + k; } template forceinline int OffsetSetView::lubMax() const { if (view.cardMax() == 0) return view.lubMax(); return view.lubMax() + k; } template forceinline int OffsetSetView::glbMin() const { if (view.cardMax() == 0) return view.glbMin(); return view.glbMin() + k; } template forceinline int OffsetSetView::glbMax() const { if (view.cardMax() == 0) return view.glbMax(); return view.glbMax() + k; } template forceinline ModEvent OffsetSetView::cardMin(Space* home, unsigned int c) { return view.cardMin(home, c); } template forceinline ModEvent OffsetSetView::cardMax(Space* home, unsigned int c) { return view.cardMax(home, c); } template forceinline ModEvent OffsetSetView::include(Space* home, int c) { return view.include(home, c-k); } template forceinline ModEvent OffsetSetView::exclude(Space* home, int c) { return view.exclude(home, c-k); } template forceinline ModEvent OffsetSetView::intersect(Space* home, int c) { return view.intersect(home, c-k); } template forceinline ModEvent OffsetSetView::intersect(Space* home, int i, int j) { return view.intersect(home, i-k, j-k); } template forceinline ModEvent OffsetSetView::include(Space* home, int i, int j) { return view.include(home, i-k, j-k); } template forceinline ModEvent OffsetSetView::exclude(Space* home, int i, int j) { return view.exclude(home, i-k, j-k); } template template ModEvent OffsetSetView::excludeI(Space* home,I& iter) { Iter::Ranges::Offset off(iter, -k); return view.excludeI(home, off); } template template ModEvent OffsetSetView::includeI(Space* home,I& iter) { Iter::Ranges::Offset off(iter, -k); return view.includeI(home, off); } template template ModEvent OffsetSetView::intersectI(Space* home,I& iter) { Iter::Ranges::Offset off(iter, -k); return view.intersectI(home, off); } template forceinline void OffsetSetView::subscribe(Space* home, Propagator* p, PropCond pc, bool process) { view.subscribe(home,p, pc,process); } template forceinline void OffsetSetView::cancel(Space* home, Propagator* p, PropCond pc) { view.cancel(home,p, pc); } template forceinline void OffsetSetView::subscribe(Space* home, Advisor* a) { view.subscribe(home,a); } template forceinline void OffsetSetView::cancel(Space* home, Advisor* a) { view.cancel(home,a); } template forceinline void OffsetSetView::schedule(Space* home, Propagator* p, ModEvent me) { return View::schedule(home,p,me); } template forceinline ModEvent OffsetSetView::me(ModEventDelta med) { return View::me(med); } template forceinline ModEventDelta OffsetSetView::med(ModEvent me) { return View::med(me); } template forceinline void OffsetSetView::update(Space* home, bool share, OffsetSetView& y) { k = y.k; view.update(home,share,y.view); } template forceinline Reflection::Arg* OffsetSetView::spec(const Space* home, Reflection::VarMap& m) const { return Reflection::Arg::newPair(Reflection::Arg::newInt(k), view.spec(home, m)); } template inline Support::Symbol OffsetSetView::type(void) { Support::Symbol t("Set::OffsetSetView<"); t += View::type(); t += ">"; return t; } /* * Delta information for advisors * */ template forceinline ModEvent OffsetSetView::modevent(const Delta* d) { return View::modevent(d); } template forceinline int OffsetSetView::glbMin(const Delta* d) const { return view.glbMin(d)+k; } template forceinline int OffsetSetView::glbMax(const Delta* d) const { return view.glbMax(d)+k; } template forceinline bool OffsetSetView::glbAny(const Delta* d) const { return view.glbAny(d); } template forceinline int OffsetSetView::lubMin(const Delta* d) const { return view.lubMin(d)+k; } template forceinline int OffsetSetView::lubMax(const Delta* d) const { return view.lubMax(d)+k; } template forceinline bool OffsetSetView::lubAny(const Delta* d) const { return view.lubAny(d); } /** * \brief %Range iterator for least upper bound of offset set views * \ingroup TaskActorSetView */ template class LubRanges > : public Iter::Ranges::Offset > { private: LubRanges ub; Iter::Ranges::Offset > ubo; public: /// \name Constructors and initialization //@{ /// Default constructor LubRanges(void) {} /// Initialize with ranges for view \a x LubRanges(const OffsetSetView& x); /// Initialize with ranges for view \a x void init(const OffsetSetView& x); /// \name Iteration control //@{ /// Test whether iterator is still at a range or done bool operator()(void) const; /// Move iterator to next range (if possible) void operator++(void); //@} /// \name Range access //@{ /// Return smallest value of range int min(void) const; /// Return largest value of range int max(void) const; /// Return width of ranges (distance between minimum and maximum) unsigned int width(void) const; //@} }; template forceinline LubRanges >::LubRanges(const OffsetSetView& s) : ub(s.base()), ubo(ub, s.offset()) {} template forceinline void LubRanges >::init(const OffsetSetView& s) { ub.init(s.base()); ubo.init(ub, s.offset()); } template forceinline bool LubRanges >::operator()(void) const { return ubo(); } template forceinline void LubRanges >::operator++(void) { return ++ubo; } template forceinline int LubRanges >::min(void) const { return ubo.min(); } template forceinline int LubRanges >::max(void) const { return ubo.max(); } template forceinline unsigned int LubRanges >::width(void) const { return ubo.width(); } /** * \brief %Range iterator for greatest lower bound of offset set views * \ingroup TaskActorSetView */ template class GlbRanges > { private: GlbRanges lb; Iter::Ranges::Offset > lbo; public: /// \name Constructors and initialization //@{ /// Default constructor GlbRanges(void) {} /// Initialize with ranges for view \a x GlbRanges(const OffsetSetView & x); /// Initialize with ranges for view \a x void init(const OffsetSetView & x); /// \name Iteration control //@{ /// Test whether iterator is still at a range or done bool operator()(void) const; /// Move iterator to next range (if possible) void operator++(void); //@} /// \name Range access //@{ /// Return smallest value of range int min(void) const; /// Return largest value of range int max(void) const; /// Return width of ranges (distance between minimum and maximum) unsigned int width(void) const; //@} }; template forceinline GlbRanges >::GlbRanges(const OffsetSetView & s) : lb(s.base()), lbo(lb, s.offset()) {} template forceinline void GlbRanges >::init(const OffsetSetView & s) { lb.init(s.base()); lbo.init(lb, s.offset()); } template forceinline bool GlbRanges >::operator()(void) const { return lbo(); } template forceinline void GlbRanges >::operator++(void) { return ++lbo; } template forceinline int GlbRanges >::min(void) const { return lbo.min(); } template forceinline int GlbRanges >::max(void) const { return lbo.max(); } template forceinline unsigned int GlbRanges >::width(void) const { return lbo.width(); } } /* * Testing * */ template forceinline bool same(const Set::OffsetSetView& x, const Set::OffsetSetView& y) { return same(x.base(),y.base()); } template forceinline bool before(const Set::OffsetSetView& x, const Set::OffsetSetView& y) { return before(x.base(),y.base()); } } template forceinline std::ostream& operator<<(std::ostream& os, const Gecode::Set::OffsetSetView& s) { return os << "(" << s.base() << ")+"<