/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Guido Tack * * Contributing authors: * Christian Schulte * * Copyright: * Guido Tack, 2004 * Christian Schulte, 2004 * * Last modified: * $Date: 2008-02-06 18:48:22 +0100 (Wed, 06 Feb 2008) $ by $Author: schulte $ * $Revision: 6102 $ * * 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 ComplementView::ComplementView(void) {} template forceinline ComplementView::ComplementView(View& s0) : DerivedViewBase(s0) {} template forceinline ComplementView::ComplementView(Space* home, const Reflection::VarMap& vars, Reflection::Arg* arg) : DerivedViewBase(View(home, vars, arg)) {} template forceinline ModEvent ComplementView::me_negateset(ModEvent me) { switch(me) { case ME_SET_LUB : return ME_SET_GLB; case ME_SET_GLB : return ME_SET_LUB; case ME_SET_CLUB : return ME_SET_CGLB; case ME_SET_CGLB : return ME_SET_CLUB; default: return me; } } template forceinline PropCond ComplementView::pc_negateset(PropCond pc) { switch(pc) { case PC_SET_CLUB : return PC_SET_CGLB; case PC_SET_CGLB : return PC_SET_CLUB; default: return pc; } } template forceinline bool ComplementView::assigned(void) const { return view.assigned(); } template forceinline unsigned int ComplementView::glbSize(void) const { return Limits::card - view.lubSize(); } template forceinline unsigned int ComplementView::lubSize(void) const { return Limits::card - view.glbSize(); } template forceinline unsigned int ComplementView::unknownSize(void) const { return lubSize() - glbSize(); } template forceinline bool ComplementView::contains(int n) const { return view.notContains(n); } template forceinline bool ComplementView::notContains(int n) const { return view.contains(n); } template forceinline unsigned int ComplementView::cardMin() const { return Limits::card - view.cardMax(); } template forceinline unsigned int ComplementView::cardMax() const { return Limits::card - view.cardMin(); } template forceinline int ComplementView::lubMin() const { GlbRanges lb(view); RangesCompl > lbc(lb); if (lbc()) { return lbc.min(); } else { return BndSet::MIN_OF_EMPTY; } } template forceinline int ComplementView::lubMax() const { GlbRanges lb(view); RangesCompl > lbc(lb); if (lbc()) { while(lbc()) ++lbc; return lbc.max(); } else { return BndSet::MAX_OF_EMPTY; } } template forceinline int ComplementView::glbMin() const { LubRanges ub(view); RangesCompl > ubc(ub); if (ubc()) { return ubc.min(); } else { return BndSet::MIN_OF_EMPTY; } } template forceinline int ComplementView::glbMax() const { LubRanges ub(view); RangesCompl > ubc(ub); if (ubc()) { while(ubc()) ++ubc; return ubc.max(); } else { return BndSet::MAX_OF_EMPTY; } } template forceinline ModEvent ComplementView::cardMin(Space* home, unsigned int c) { if (c < Limits::card) return me_negateset(view.cardMax(home, Limits::card - c)); return ME_SET_NONE; } template forceinline ModEvent ComplementView::cardMax(Space* home, unsigned int c) { if (c < Limits::card) return me_negateset(view.cardMin(home, Limits::card - c)); return ME_SET_NONE; } template forceinline ModEvent ComplementView::include(Space* home, int c) { return me_negateset((view.exclude(home, c))); } template forceinline ModEvent ComplementView::exclude(Space* home, int c) { return me_negateset((view.include(home, c))); } template forceinline ModEvent ComplementView::intersect(Space* home, int c) { Iter::Ranges::Singleton si(c,c); RangesCompl csi(si); return me_negateset((view.includeI(home, csi))); } template forceinline ModEvent ComplementView::intersect(Space* home, int i, int j) { Iter::Ranges::Singleton si(i,j); RangesCompl csi(si); return me_negateset((view.includeI(home, csi))); } template forceinline ModEvent ComplementView::include(Space* home, int j, int k) { return me_negateset(view.exclude(home,j,k)); } template forceinline ModEvent ComplementView::exclude(Space* home, int j, int k) { return me_negateset(view.include(home,j,k)); } template template ModEvent ComplementView::excludeI(Space* home,I& iter) { return me_negateset(view.includeI(home,iter)); } template template ModEvent ComplementView::includeI(Space* home,I& iter) { return me_negateset(view.excludeI(home,iter)); } template template ModEvent ComplementView::intersectI(Space* home,I& iter) { RangesCompl c(iter); return me_negateset(view.includeI(home,c)); } template forceinline void ComplementView::subscribe(Space* home, Propagator* p, PropCond pc, bool process) { view.subscribe(home,p, pc_negateset(pc),process); } template forceinline void ComplementView::cancel(Space* home, Propagator* p, PropCond pc) { view.cancel(home,p, pc_negateset(pc)); } template forceinline void ComplementView::subscribe(Space* home, Advisor* a) { view.subscribe(home,a); } template forceinline void ComplementView::cancel(Space* home, Advisor* a) { view.cancel(home,a); } template forceinline void ComplementView::schedule(Space* home, Propagator* p, ModEvent me) { return View::schedule(home,p,me_negateset(me)); } template forceinline ModEvent ComplementView::me(ModEventDelta med) { return me_negateset(View::me(med)); } template forceinline ModEventDelta ComplementView::med(ModEvent me) { return me_negateset(View::med(me)); } template forceinline void ComplementView::update(Space* home, bool share, ComplementView& y) { view.update(home,share,y.view); } template forceinline Reflection::Arg* ComplementView::spec(const Space* home, Reflection::VarMap& m) const { return view.spec(home, m); } template inline Support::Symbol ComplementView::type(void) { Support::Symbol t("Set::ComplementView<"); t += View::type(); t += ">"; return t; } /* * Delta information for advisors * */ template forceinline ModEvent ComplementView::modevent(const Delta* d) { return me_negateset(View::modevent(d)); } template forceinline int ComplementView::glbMin(const Delta* d) const { return view.lubMin(d); } template forceinline int ComplementView::glbMax(const Delta* d) const { return view.lubMax(d); } template forceinline bool ComplementView::glbAny(const Delta* d) const { return view.lubAny(d); } template forceinline int ComplementView::lubMin(const Delta* d) const { return view.glbMin(d); } template forceinline int ComplementView::lubMax(const Delta* d) const { return view.glbMax(d); } template forceinline bool ComplementView::lubAny(const Delta* d) const { return view.glbAny(d); } /* * Specialization for double negation * */ template forceinline ComplementView >::ComplementView(void) {} template forceinline ComplementView >:: ComplementView(ComplementView& s0) : View(s0.base()) {} /** * \brief %Range iterator for least upper bound of complement set views * \ingroup TaskActorSetView */ template class LubRanges > { private: GlbRanges lb; RangesCompl > lbc; public: /// \name Constructors and initialization //@{ /// Default constructor LubRanges(void) {} /// Initialize with ranges for view \a x LubRanges(const ComplementView& x); /// Initialize with ranges for view \a x void init(const ComplementView& 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 ComplementView& s) : lb(s.base()), lbc(lb) {} template forceinline void LubRanges >::init(const ComplementView& s) { lb.init(s.base()); lbc.init(lb); } template forceinline bool LubRanges >::operator()(void) const { return lbc(); } template forceinline void LubRanges >::operator++(void) { return ++lbc; } template forceinline int LubRanges >::min(void) const { return lbc.min(); } template forceinline int LubRanges >::max(void) const { return lbc.max(); } template forceinline unsigned int LubRanges >::width(void) const { return lbc.width(); } /** * \brief Range iterator for the least upper bound of double-complement-views * * This class provides (by specialization) a range iterator * for the least upper bounds of complements of complement set views. * * \ingroup TaskActorSet */ template class LubRanges > > : public LubRanges { public: /// \name Constructors and initialization //@{ /// Default constructor LubRanges(void) {} /// Initialize with ranges for view \a x LubRanges(const ComplementView >& x); /// Initialize with ranges for view \a x void init(const ComplementView >& x); //@} }; template forceinline LubRanges > >:: LubRanges(const ComplementView >& x) : LubRanges(x) {} template forceinline void LubRanges > >:: init(const ComplementView >& x) { LubRanges::init(x); } /** * \brief %Range iterator for greatest lower bound of complement set views * \ingroup TaskActorSetView */ template class GlbRanges > { private: LubRanges ub; RangesCompl > ubc; public: /// \name Constructors and initialization //@{ /// Default constructor GlbRanges(void) {} /// Initialize with ranges for view \a x GlbRanges(const ComplementView & x); /// Initialize with ranges for view \a x void init(const ComplementView & 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 ComplementView & s) : ub(s.base()), ubc(ub) {} template forceinline void GlbRanges >::init(const ComplementView & s) { ub.init(s.base()); ubc.init(ub); } template forceinline bool GlbRanges >::operator()(void) const { return ubc(); } template forceinline void GlbRanges >::operator++(void) { return ++ubc; } template forceinline int GlbRanges >::min(void) const { return ubc.min(); } template forceinline int GlbRanges >::max(void) const { return ubc.max(); } template forceinline unsigned int GlbRanges >::width(void) const { return ubc.width(); } /** * \brief Range iterator for the greatest lower bound of double-complement-views * * This class provides (by specialization) a range iterator * for the greatest lower bounds of complements of complement set views. * * \ingroup TaskActorSet */ template class GlbRanges > > : public GlbRanges { public: /// \name Constructors and initialization //@{ /// Default constructor GlbRanges(void) {} /// Initialize with ranges for view \a x GlbRanges(const ComplementView >& x); /// Initialize with ranges for view \a x void init(const ComplementView >& x); //@} }; template forceinline GlbRanges > >:: GlbRanges(const ComplementView >& x) : GlbRanges(x) {} template forceinline void GlbRanges > >:: init(const ComplementView >& x) { GlbRanges::init(x); } } /* * Testing * */ template forceinline bool same(const Set::ComplementView& x, const Set::ComplementView& y) { return same(x.base(),y.base()); } template forceinline bool before(const Set::ComplementView& x, const Set::ComplementView& y) { return before(x.base(),y.base()); } template forceinline bool same(const Set::ComplementView >& x, const Set::ComplementView >& y) { return same(x,y); } template forceinline bool before(const Set::ComplementView >& x, const Set::ComplementView >& y) { return before(x,y); } } template forceinline std::ostream& operator<<(std::ostream& os, const Gecode::Set::ComplementView& s) { return os << "(" << s.base() << ")^C"; } // STATISTICS: set-var