/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * * Copyright: * Christian Schulte, 2002 * * Last modified: * $Date: 2008-01-31 18:29:16 +0100 (Thu, 31 Jan 2008) $ by $Author: tack $ * $Revision: 6017 $ * * 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 * */ forceinline BoolView::BoolView(void) {} forceinline BoolView::BoolView(const BoolVar& x) : VarViewBase(x.var()) {} forceinline BoolView::BoolView(BoolVarImp* x) : VarViewBase(x) {} forceinline BoolView::BoolView(Space* /*home*/, const Reflection::VarMap& vars, Reflection::Arg* arg) : VarViewBase(BoolVar(vars.var(arg->toVar())).var()) {} /* * Value access * */ forceinline BoolStatus BoolView::status(void) const { return varimp->status(); } forceinline int BoolView::min(void) const { return varimp->min(); } forceinline int BoolView::max(void) const { return varimp->max(); } forceinline int BoolView::med(void) const { return varimp->med(); } forceinline int BoolView::val(void) const { return varimp->val(); } forceinline unsigned int BoolView::size(void) const { return varimp->size(); } forceinline unsigned int BoolView::width(void) const { return varimp->width(); } forceinline unsigned int BoolView::regret_min(void) const { return varimp->regret_min(); } forceinline unsigned int BoolView::regret_max(void) const { return varimp->regret_max(); } /* * Domain tests * */ forceinline bool BoolView::range(void) const { return varimp->range(); } forceinline bool BoolView::assigned(void) const { return varimp->assigned(); } forceinline bool BoolView::in(int n) const { return varimp->in(n); } forceinline bool BoolView::in(double n) const { return varimp->in(n); } /* * Domain update by value * */ forceinline ModEvent BoolView::lq(Space* home, int n) { return varimp->lq(home,n); } forceinline ModEvent BoolView::lq(Space* home, double n) { return varimp->lq(home,n); } forceinline ModEvent BoolView::le(Space* home, int n) { return varimp->lq(home,n-1); } forceinline ModEvent BoolView::le(Space* home, double n) { return lq(home,n-1.0); } forceinline ModEvent BoolView::gq(Space* home, int n) { return varimp->gq(home,n); } forceinline ModEvent BoolView::gq(Space* home, double n) { return varimp->gq(home,n); } forceinline ModEvent BoolView::gr(Space* home, int n) { return varimp->gq(home,n+1); } forceinline ModEvent BoolView::gr(Space* home, double n) { return gq(home,n+1.0); } forceinline ModEvent BoolView::nq(Space* home, int n) { return varimp->nq(home,n); } forceinline ModEvent BoolView::nq(Space* home, double n) { return varimp->nq(home,n); } forceinline ModEvent BoolView::eq(Space* home, int n) { return varimp->eq(home,n); } forceinline ModEvent BoolView::eq(Space* home, double n) { return varimp->eq(home,n); } /* * Iterator-based domain update * */ template forceinline ModEvent BoolView::narrow_r(Space* home, I& i, bool depend) { return varimp->narrow_r(home,i,depend); } template forceinline ModEvent BoolView::inter_r(Space* home, I& i, bool depend) { return varimp->inter_r(home,i,depend); } template forceinline ModEvent BoolView::minus_r(Space* home, I& i, bool depend) { return varimp->minus_r(home,i,depend); } template forceinline ModEvent BoolView::narrow_v(Space* home, I& i, bool depend) { return varimp->narrow_v(home,i,depend); } template forceinline ModEvent BoolView::inter_v(Space* home, I& i, bool depend) { return varimp->inter_v(home,i,depend); } template forceinline ModEvent BoolView::minus_v(Space* home, I& i, bool depend) { return varimp->minus_v(home,i,depend); } /* * Boolean domain tests * */ forceinline bool BoolView::zero(void) const { return varimp->zero(); } forceinline bool BoolView::one(void) const { return varimp->one(); } forceinline bool BoolView::none(void) const { return varimp->none(); } /* * Boolean assignment operations * */ forceinline ModEvent BoolView::zero_none(Space* home) { return varimp->zero_none(home); } forceinline ModEvent BoolView::one_none(Space* home) { return varimp->one_none(home); } forceinline ModEvent BoolView::zero(Space* home) { return varimp->zero(home); } forceinline ModEvent BoolView::one(Space* home) { return varimp->one(home); } /* * Delta information for advisors * */ forceinline ModEvent BoolView::modevent(const Delta* d) { return BoolVarImp::modevent(d); } forceinline int BoolView::min(const Delta* d) const { return varimp->min(d); } forceinline int BoolView::max(const Delta* d) const { return varimp->max(d); } forceinline bool BoolView::any(const Delta* d) const { return varimp->any(d); } forceinline ModEventDelta BoolView::med(ModEvent me) { return VarViewBase::med(me); } /* * Cloning * */ forceinline void BoolView::update(Space* home, bool share, BoolView& x) { varimp = x.varimp->copy(home,share); } /* * Serialization * */ forceinline Reflection::Arg* BoolView::spec(const Space* home, Reflection::VarMap& m) const { return varimp->spec(home, m); } inline Support::Symbol BoolView::type(void) { return Support::Symbol("Gecode::Int::BoolView"); } /* * Negated Boolean views * */ /* * Constructors and initialization * */ forceinline NegBoolView::NegBoolView(void) {} forceinline NegBoolView::NegBoolView(const BoolView& b) : DerivedViewBase(b) {} forceinline void NegBoolView::init(const BoolView& b) { view = b; } forceinline NegBoolView::NegBoolView(Space* home, const Reflection::VarMap& vars, Reflection::Arg* arg) : DerivedViewBase(BoolView(home, vars, arg)) {} /* * Boolean domain tests * */ forceinline BoolStatus NegBoolView::status(void) const { return view.status(); } forceinline bool NegBoolView::zero(void) const { return view.one(); } forceinline bool NegBoolView::one(void) const { return view.zero(); } forceinline bool NegBoolView::none(void) const { return view.none(); } /* * Boolean assignment operations * */ forceinline ModEvent NegBoolView::zero_none(Space* home) { return view.one_none(home); } forceinline ModEvent NegBoolView::one_none(Space* home) { return view.zero_none(home); } forceinline ModEvent NegBoolView::zero(Space* home) { return view.one(home); } forceinline ModEvent NegBoolView::one(Space* home) { return view.zero(home); } /* * Value access * */ forceinline int NegBoolView::min(void) const { return view.max(); } forceinline int NegBoolView::max(void) const { return view.min(); } forceinline int NegBoolView::val(void) const { return 1-view.val(); } /* * Domain tests * */ forceinline bool NegBoolView::assigned(void) const { return view.assigned(); } /* * Propagator modification events * */ forceinline void NegBoolView::schedule(Space* home, Propagator* p, ModEvent me) { return BoolView::schedule(home,p,me); } forceinline ModEvent NegBoolView::me(ModEventDelta med) { return BoolView::me(med); } forceinline ModEventDelta NegBoolView::med(ModEvent me) { return BoolView::med(me); } /* * Dependencies * */ forceinline void NegBoolView::subscribe(Space* home, Propagator* p, PropCond pc, bool process) { view.subscribe(home,p,pc,process); } forceinline void NegBoolView::cancel(Space* home, Propagator* p, PropCond pc) { view.cancel(home,p,pc); } forceinline void NegBoolView::subscribe(Space* home, Advisor* a) { view.subscribe(home,a); } forceinline void NegBoolView::cancel(Space* home, Advisor* a) { view.cancel(home,a); } /* * Delta information for advisors * */ forceinline ModEvent NegBoolView::modevent(const Delta* d) { return BoolView::modevent(d); } forceinline int NegBoolView::min(const Delta* d) const { return view.max(d); } forceinline int NegBoolView::max(const Delta* d) const { return view.min(d); } forceinline bool NegBoolView::any(const Delta* d) const { return view.any(d); } /* * Cloning * */ forceinline void NegBoolView::update(Space* home, bool share, NegBoolView& b) { view.update(home,share,b.view); } /* * Serialization * */ forceinline Reflection::Arg* NegBoolView::spec(const Space* home, Reflection::VarMap& m) const { return view.spec(home, m); } inline Support::Symbol NegBoolView::type(void) { return Support::Symbol("Gecode::Int::NegBoolView"); } /** * \brief %Range iterator for Boolean variable views * \ingroup TaskActorIntView */ template <> class ViewRanges : public Iter::Ranges::Singleton { public: /// \name Constructors and initialization //@{ /// Default constructor ViewRanges(void); /// Initialize with ranges for view \a x ViewRanges(const BoolView& x); /// Initialize with ranges for view \a x void init(const BoolView& x); //@} }; forceinline ViewRanges::ViewRanges(void) {} forceinline ViewRanges::ViewRanges(const BoolView& x) : Iter::Ranges::Singleton(x.min(),x.max()) {} forceinline void ViewRanges::init(const BoolView& x) { Iter::Ranges::Singleton::init(x.min(),x.max()); } /** * \brief %Range iterator for negated Boolean variable views * \ingroup TaskActorIntView */ template <> class ViewRanges : public Iter::Ranges::Singleton { public: /// \name Constructors and initialization //@{ /// Default constructor ViewRanges(void); /// Initialize with ranges for view \a x ViewRanges(const NegBoolView& x); /// Initialize with ranges for view \a x void init(const NegBoolView& x); //@} }; forceinline ViewRanges::ViewRanges(void) {} forceinline ViewRanges::ViewRanges(const NegBoolView& x) : Iter::Ranges::Singleton(x.min(),x.max()) {} forceinline void ViewRanges::init(const NegBoolView& x) { Iter::Ranges::Singleton::init(x.min(),x.max()); } } /* * View comparison * */ forceinline bool same(const Int::NegBoolView& x, const Int::NegBoolView& y) { return same(x.base(),y.base()); } forceinline bool before(const Int::NegBoolView& x, const Int::NegBoolView& y) { return before(x.base(),y.base()); } namespace Int { /* * Test sharing between Boolean and negated Boolean views * */ forceinline BoolTest bool_test(const BoolView& b0, const BoolView& b1) { return same(b0,b1) ? BT_SAME : BT_NONE; } forceinline BoolTest bool_test(const BoolView& b0, const NegBoolView& b1) { return same(b0,b1.base()) ? BT_COMP : BT_NONE; } forceinline BoolTest bool_test(const NegBoolView& b0, const BoolView& b1) { return same(b0.base(),b1) ? BT_COMP : BT_NONE; } /// Test whether views \a b0 and \a b1 are the same forceinline BoolTest bool_test(const NegBoolView& b0, const NegBoolView& b1) { return same(b0,b1) ? BT_SAME : BT_NONE; } } } // STATISTICS: int-var