zero.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2003
*
* 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
ZeroIntView::ZeroIntView(void) {}
/*
* Value access
*
*/
forceinline int
ZeroIntView::min(void) const {
return 0;
}
forceinline int
ZeroIntView::max(void) const {
return 0;
}
forceinline int
ZeroIntView::med(void) const {
return 0;
}
forceinline int
ZeroIntView::val(void) const {
return 0;
}
forceinline unsigned int
ZeroIntView::size(void) const {
return 1;
}
forceinline unsigned int
ZeroIntView::width(void) const {
return 1;
}
forceinline unsigned int
ZeroIntView::regret_min(void) const {
return 0;
}
forceinline unsigned int
ZeroIntView::regret_max(void) const {
return 0;
}
/*
* Domain tests
*
*/
forceinline bool
ZeroIntView::range(void) const {
return true;
}
forceinline bool
ZeroIntView::in(int n) const {
return n == 0;
}
forceinline bool
ZeroIntView::in(long long int n) const {
return n == 0;
}
/*
* Domain update by value
*
*/
forceinline ModEvent
ZeroIntView::lq(Space&, int n) {
return (0 <= n) ? ME_INT_NONE : ME_INT_FAILED;
}
forceinline ModEvent
ZeroIntView::lq(Space&, long long int n) {
return (0 <= n) ? ME_INT_NONE : ME_INT_FAILED;
}
forceinline ModEvent
ZeroIntView::le(Space&, int n) {
return (0 < n) ? ME_INT_NONE : ME_INT_FAILED;
}
forceinline ModEvent
ZeroIntView::le(Space&, long long int n) {
return (0 < n) ? ME_INT_NONE : ME_INT_FAILED;
}
forceinline ModEvent
ZeroIntView::gq(Space&, int n) {
return (0 >= n) ? ME_INT_NONE : ME_INT_FAILED;
}
forceinline ModEvent
ZeroIntView::gq(Space&, long long int n) {
return (0 >= n) ? ME_INT_NONE : ME_INT_FAILED;
}
forceinline ModEvent
ZeroIntView::gr(Space&, int n) {
return (0 > n) ? ME_INT_NONE : ME_INT_FAILED;
}
forceinline ModEvent
ZeroIntView::gr(Space&, long long int n) {
return (0 > n) ? ME_INT_NONE : ME_INT_FAILED;
}
forceinline ModEvent
ZeroIntView::nq(Space&, int n) {
return (0 != n) ? ME_INT_NONE : ME_INT_FAILED;
}
forceinline ModEvent
ZeroIntView::nq(Space&, long long int n) {
return (0 != n) ? ME_INT_NONE : ME_INT_FAILED;
}
forceinline ModEvent
ZeroIntView::eq(Space&, int n) {
return (0 == n) ? ME_INT_NONE : ME_INT_FAILED;
}
forceinline ModEvent
ZeroIntView::eq(Space&, long long int n) {
return (0 == n) ? ME_INT_NONE : ME_INT_FAILED;
}
/*
* Iterator-based domain update
*
*/
template<class I>
forceinline ModEvent
ZeroIntView::narrow_r(Space&, I& i, bool) {
return i() ? ME_INT_NONE : ME_INT_FAILED;
}
template<class I>
forceinline ModEvent
ZeroIntView::inter_r(Space&, I& i, bool) {
while (i() && (i.max() < 0))
++i;
return (i() && (i.min() <= 0)) ? ME_INT_NONE : ME_INT_FAILED;
}
template<class I>
forceinline ModEvent
ZeroIntView::minus_r(Space&, I& i, bool) {
while (i() && (i.max() < 0))
++i;
return (i() && (i.min() <= 0)) ? ME_INT_FAILED : ME_INT_NONE;
}
template<class I>
forceinline ModEvent
ZeroIntView::narrow_v(Space&, I& i, bool) {
return i() ? ME_INT_NONE : ME_INT_FAILED;
}
template<class I>
forceinline ModEvent
ZeroIntView::inter_v(Space&, I& i, bool) {
while (i() && (i.val() < 0))
++i;
return (i() && (i.val() == 0)) ? ME_INT_NONE : ME_INT_FAILED;
}
template<class I>
forceinline ModEvent
ZeroIntView::minus_v(Space&, I& i, bool) {
while (i() && (i.val() < 0))
++i;
return (i() && (i.val() == 0)) ? ME_INT_FAILED : ME_INT_NONE;
}
/*
* Delta information for advisors
*
*/
forceinline int
ZeroIntView::min(const Delta&) const {
return 1;
}
forceinline int
ZeroIntView::max(const Delta&) const {
return 0;
}
forceinline unsigned int
ZeroIntView::width(const Delta&) const {
return 1U;
}
forceinline bool
ZeroIntView::any(const Delta&) const {
return true;
}
template<>
class ViewRanges<ZeroIntView> {
private:
bool done;
public:
ViewRanges(void);
ViewRanges(const ZeroIntView& x);
void init(const ZeroIntView& x);
bool operator ()(void) const;
void operator ++(void);
int min(void) const;
int max(void) const;
unsigned int width(void) const;
};
forceinline
ViewRanges<ZeroIntView>::ViewRanges(void) {}
forceinline
ViewRanges<ZeroIntView>::ViewRanges(const ZeroIntView&)
: done(false) {}
forceinline bool
ViewRanges<ZeroIntView>::operator ()(void) const {
return !done;
}
forceinline void
ViewRanges<ZeroIntView>::operator ++(void) {
done=true;
}
forceinline int
ViewRanges<ZeroIntView>::min(void) const {
return 0;
}
forceinline int
ViewRanges<ZeroIntView>::max(void) const {
return 0;
}
forceinline unsigned int
ViewRanges<ZeroIntView>::width(void) const {
return 1;
}
/*
* View comparison
*
*/
forceinline bool
operator ==(const ZeroIntView&, const ZeroIntView&) {
return true;
}
forceinline bool
operator !=(const ZeroIntView&, const ZeroIntView&) {
return false;
}
}}
// STATISTICS: int-var
Gecode::Delta
Generic domain change information to be supplied to advisors.
Definition core.hpp:204
Gecode::Int::ViewRanges< ZeroIntView >::ViewRanges
ViewRanges(void)
Default constructor.
Definition zero.hpp:265
Gecode::Int::ViewRanges< ZeroIntView >::init
void init(const ZeroIntView &x)
Initialize with ranges for view x.
Gecode::Int::ViewRanges::max
int max(void) const
Return largest value of range.
Gecode::Int::ViewRanges::operator()
bool operator()(void) const
Test whether iterator is still at a range or done.
Gecode::Int::ViewRanges::min
int min(void) const
Return smallest value of range.
Gecode::Int::ViewRanges::width
unsigned int width(void) const
Return width of range (distance between minimum and maximum).
Gecode::Int::ViewRanges::operator++
void operator++(void)
Move iterator to next range (if possible).
Gecode::Int::ViewRanges::ViewRanges
ViewRanges(void)
Default constructor.
Gecode::Int::ZeroIntView
Zero integer view.
Definition view.hpp:1014
Gecode::Int::ZeroIntView::gq
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition zero.hpp:123
Gecode::Int::ZeroIntView::ZeroIntView
ZeroIntView(void)
Default constructor.
Definition zero.hpp:41
Gecode::Int::ZeroIntView::med
int med(void) const
Return median of domain (greatest element not greater than the median).
Definition zero.hpp:56
Gecode::Int::ZeroIntView::regret_min
unsigned int regret_min(void) const
Return regret of domain minimum (distance to next larger value).
Definition zero.hpp:73
Gecode::Int::ZeroIntView::minus_r
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition zero.hpp:178
Gecode::Int::ZeroIntView::inter_v
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
Definition zero.hpp:190
Gecode::Int::ZeroIntView::max
int max(void) const
Return maximum of domain.
Definition zero.hpp:52
Gecode::Int::ZeroIntView::narrow_r
ModEvent narrow_r(Space &home, I &i, bool depends=true)
Replace domain by ranges described by i.
Definition zero.hpp:166
Gecode::Int::ZeroIntView::minus_v
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
Definition zero.hpp:197
Gecode::Int::ZeroIntView::any
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition zero.hpp:220
Gecode::Int::ZeroIntView::regret_max
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value).
Definition zero.hpp:77
Gecode::Int::ZeroIntView::range
bool range(void) const
Test whether domain is a range.
Definition zero.hpp:87
Gecode::Int::ZeroIntView::lq
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition zero.hpp:105
Gecode::Int::ZeroIntView::inter_r
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition zero.hpp:171
Gecode::Int::ZeroIntView::narrow_v
ModEvent narrow_v(Space &home, I &i, bool depends=true)
Replace domain by values described by i.
Definition zero.hpp:185
Gecode::Int::ZeroIntView::gr
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition zero.hpp:132
Gecode::Int::ZeroIntView::le
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition zero.hpp:114
Gecode::Int::ZeroIntView::val
int val(void) const
Return assigned value (only if assigned).
Definition zero.hpp:60
Gecode::Int::ZeroIntView::size
unsigned int size(void) const
Return size (cardinality) of domain.
Definition zero.hpp:65
Gecode::Int::ZeroIntView::eq
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition zero.hpp:150
Gecode::Int::ZeroIntView::nq
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition zero.hpp:141
Gecode::Int::ZeroIntView::width
unsigned int width(void) const
Return width of domain (distance between maximum and minimum).
Definition zero.hpp:69
Gecode::Int::ZeroIntView::in
bool in(int n) const
Test whether n is contained in domain.
Definition zero.hpp:91
Gecode::Int::ZeroIntView::min
int min(void) const
Return minimum of domain.
Definition zero.hpp:48
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::Int
Finite domain integers.
Gecode::Int::ME_INT_FAILED
const Gecode::ModEvent ME_INT_FAILED
Domain operation has resulted in failure.
Definition var-type.hpp:52
Gecode::Int::operator==
bool operator==(const CachedView< View > &x, const CachedView< View > &y)
Definition cached.hpp:401
Gecode::Int::operator!=
bool operator!=(const CachedView< View > &x, const CachedView< View > &y)
Definition cached.hpp:406
Gecode::Int::ME_INT_NONE
const Gecode::ModEvent ME_INT_NONE
Domain operation has not changed domain.
Definition var-type.hpp:54
Gecode
Gecode toplevel namespace
Gecode::ModEvent
int ModEvent
Type for modification events.
Definition core.hpp:62
forceinline
#define forceinline
Definition config.hpp:187