/* * Main authors: * Christian Schulte * * Copyright: * Christian Schulte, 2003 * * Last modified: * $Date: 2006-08-24 11:25:05 +0200 (Thu, 24 Aug 2006) $ by $Author: schulte $ * $Revision: 3559 $ * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * See the file "LICENSE" for information on usage and * redistribution of this file, and for a * DISCLAIMER OF ALL WARRANTIES. * */ namespace Gecode { namespace Int { /* * Constructors and initialization * */ forceinline ConstIntView::ConstIntView(void) {} forceinline ConstIntView::ConstIntView(int n) : x(n) {} forceinline void ConstIntView::init(int n) { x=n; } /* * Value access * */ forceinline int ConstIntView::min(void) const { return x; } forceinline int ConstIntView::max(void) const { return x; } forceinline int ConstIntView::med(void) const { return x; } forceinline int ConstIntView::val(void) const { return x; } forceinline unsigned int ConstIntView::size(void) const { return 1; } forceinline unsigned int ConstIntView::width(void) const { return 1; } forceinline unsigned int ConstIntView::regret_min(void) const { return 0; } forceinline unsigned int ConstIntView::regret_max(void) const { return 0; } /* * Domain tests * */ forceinline bool ConstIntView::range(void) const { return true; } forceinline bool ConstIntView::assigned(void) const { return true; } forceinline bool ConstIntView::in(int n) const { return n == x; } forceinline bool ConstIntView::in(double n) const { return n == x; } /* * Domain update by value * */ forceinline ModEvent ConstIntView::lq(Space*, int n) { return (x <= n) ? ME_INT_NONE : ME_INT_FAILED; } forceinline ModEvent ConstIntView::lq(Space*, double n) { return (x <= n) ? ME_INT_NONE : ME_INT_FAILED; } forceinline ModEvent ConstIntView::le(Space*, int n) { return (x < n) ? ME_INT_NONE : ME_INT_FAILED; } forceinline ModEvent ConstIntView::le(Space*, double n) { return (x < n) ? ME_INT_NONE : ME_INT_FAILED; } forceinline ModEvent ConstIntView::gq(Space*, int n) { return (x >= n) ? ME_INT_NONE : ME_INT_FAILED; } forceinline ModEvent ConstIntView::gq(Space*, double n) { return (x >= n) ? ME_INT_NONE : ME_INT_FAILED; } forceinline ModEvent ConstIntView::gr(Space*, int n) { return (x > n) ? ME_INT_NONE : ME_INT_FAILED; } forceinline ModEvent ConstIntView::gr(Space*, double n) { return (x > n) ? ME_INT_NONE : ME_INT_FAILED; } forceinline ModEvent ConstIntView::nq(Space*, int n) { return (x != n) ? ME_INT_NONE : ME_INT_FAILED; } forceinline ModEvent ConstIntView::nq(Space*, double n) { return (x != n) ? ME_INT_NONE : ME_INT_FAILED; } forceinline ModEvent ConstIntView::eq(Space*, int n) { return (x == n) ? ME_INT_NONE : ME_INT_FAILED; } forceinline ModEvent ConstIntView::eq(Space*, double n) { return (x == n) ? ME_INT_NONE : ME_INT_FAILED; } /* * Domain update by range iterator * */ template forceinline ModEvent ConstIntView::narrow(Space*, I& i) { return i() ? ME_INT_NONE : ME_INT_FAILED; } template ModEvent ConstIntView::inter(Space*, I& i) { while (i() && (i.max() < x)) ++i; return (i() && (i.min() <= x)) ? ME_INT_NONE : ME_INT_FAILED; } template ModEvent ConstIntView::minus(Space*, I& i) { while (i() && (i.max() < x)) ++i; return (i() && (i.min() <= x)) ? ME_INT_FAILED : ME_INT_NONE; } /* * Propagator modification events * */ forceinline ModEvent ConstIntView::pme(const Propagator*) { return ME_INT_NONE; } forceinline PropModEvent ConstIntView::pme(ModEvent me) { return static_cast(me); } /* * Dependencies * */ forceinline void ConstIntView::subscribe(Space*,Propagator*,PropCond,bool) {} forceinline void ConstIntView::cancel(Space* home, Propagator*,PropCond) {} /* * Cloning * */ forceinline void ConstIntView::update(Space*, bool, ConstIntView& y) { x = y.x; } /** * \brief %Range iterator for constant integer views * \ingroup TaskActorIntView */ template <> class ViewRanges { private: /// The single integer to iterate int n; public: /// \name Constructors and initialization //@{ /// Default constructor ViewRanges(void); /// Initialize with ranges for view \a x ViewRanges(const ConstIntView& x); /// Initialize with ranges for view \a x void init(const ConstIntView& 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; //@} }; forceinline ViewRanges::ViewRanges(void) {} forceinline ViewRanges::ViewRanges(const ConstIntView& x) : n(x.val()) {} forceinline bool ViewRanges::operator()(void) const { return n < Limits::Int::int_max; } forceinline void ViewRanges::operator++(void) { n = Limits::Int::int_max; } forceinline int ViewRanges::min(void) const { return n; } forceinline int ViewRanges::max(void) const { return n; } forceinline unsigned int ViewRanges::width(void) const { return 1; } } /* * View comparison * */ forceinline bool same(const Int::ConstIntView& x, const Int::ConstIntView& y) { return x.min() == y.min(); } forceinline bool before(const Int::ConstIntView& x, const Int::ConstIntView& y) { return x.min() < y.min(); } } // STATISTICS: int-var