neg-bool.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>
*
* Contributing authors:
* Samuel Gagnon <samuel.gagnon92@gmail.com>
*
* Copyright:
* Christian Schulte, 2008
* Samuel Gagnon, 2018
*
* 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 {
/*
* Negated Boolean views
*
*/
/*
* Constructors and initialization
*
*/
forceinline
NegBoolView::NegBoolView(void) {}
forceinline
NegBoolView::NegBoolView(const BoolView& y)
: DerivedView<BoolView>(y) {}
/*
* Boolean domain tests
*
*/
forceinline BoolStatus
NegBoolView::status(void) const {
return x.status();
}
forceinline bool
NegBoolView::zero(void) const {
return x.one();
}
forceinline bool
NegBoolView::one(void) const {
return x.zero();
}
forceinline bool
NegBoolView::none(void) const {
return x.none();
}
/*
* Boolean assignment operations
*
*/
forceinline ModEvent
NegBoolView::zero_none(Space& home) {
return x.one_none(home);
}
forceinline ModEvent
NegBoolView::one_none(Space& home) {
return x.zero_none(home);
}
forceinline ModEvent
NegBoolView::zero(Space& home) {
return x.one(home);
}
forceinline ModEvent
NegBoolView::one(Space& home) {
return x.zero(home);
}
/* Domain update by value
*
*/
forceinline ModEvent
NegBoolView::lq(Space& home, int n) {
return n==0 ? x.one(home) : (n < 0 ? ME_BOOL_FAILED : ME_BOOL_NONE);
}
forceinline ModEvent
NegBoolView::lq(Space& home, long long int n) {
return n==0 ? x.one(home) : (n < 0 ? ME_BOOL_FAILED : ME_BOOL_NONE);
}
forceinline ModEvent
NegBoolView::le(Space& home, int n) {
return n==1 ? x.one(home) : (n < 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
}
forceinline ModEvent
NegBoolView::le(Space& home, long long int n) {
return n==1 ? x.one(home) : (n < 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
}
forceinline ModEvent
NegBoolView::gq(Space& home, int n) {
return n==1 ? x.zero(home) : (n <= 0 ? ME_BOOL_NONE : ME_BOOL_FAILED);
}
forceinline ModEvent
NegBoolView::gq(Space& home, long long int n) {
return n==1 ? x.zero(home) : (n <= 0 ? ME_BOOL_NONE : ME_BOOL_FAILED);
}
forceinline ModEvent
NegBoolView::gr(Space& home, int n) {
return n==0 ? x.zero(home) : (n >= 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
}
forceinline ModEvent
NegBoolView::gr(Space& home, long long int n) {
return n==0 ? x.zero(home) : (n >= 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
}
forceinline ModEvent
NegBoolView::nq(Space& home, int n) {
return n==0 ? x.zero(home) : (n==1 ? x.one(home) : ME_BOOL_NONE);
}
forceinline ModEvent
NegBoolView::nq(Space& home, long long int n) {
return n==0 ? x.zero(home) : (n==1 ? x.one(home) : ME_BOOL_NONE);
}
forceinline ModEvent
NegBoolView::eq(Space& home, int n) {
return n==0 ? x.one(home) : (n==1 ? x.zero(home) : ME_BOOL_FAILED);
}
forceinline ModEvent
NegBoolView::eq(Space& home, long long int n) {
return n==0 ? x.one(home) : (n==1 ? x.zero(home) : ME_BOOL_FAILED);
}
/*
* Value access
*
*/
forceinline int
NegBoolView::min(void) const {
return 1-x.max();
}
forceinline int
NegBoolView::max(void) const {
return 1-x.min();
}
forceinline int
NegBoolView::val(void) const {
return 1-x.val();
}
#ifdef GECODE_HAS_CBS
forceinline int
NegBoolView::baseval(int val) const {
return 1-val;
}
#endif
/*
* Delta information for advisors
*
*/
forceinline int
NegBoolView::min(const Delta& d) const {
return x.max(d);
}
forceinline int
NegBoolView::max(const Delta& d) const {
return x.min(d);
}
forceinline unsigned int
NegBoolView::width(const Delta& d) const {
return x.width(d);
}
forceinline bool
NegBoolView::any(const Delta& d) const {
return x.any(d);
}
forceinline bool
NegBoolView::zero(const Delta& d) {
return BoolView::one(d);
}
forceinline bool
NegBoolView::one(const Delta& d) {
return BoolView::zero(d);
}
/*
* View comparison
*
*/
forceinline bool
operator ==(const NegBoolView& x, const NegBoolView& y) {
return x.base() == y.base();
}
forceinline bool
operator !=(const NegBoolView& x, const NegBoolView& y) {
return !(x == y);
}
template<>
class ViewRanges<NegBoolView> : public Iter::Ranges::Singleton {
public:
ViewRanges(void);
ViewRanges(const NegBoolView& x);
void init(const NegBoolView& x);
};
forceinline
ViewRanges<NegBoolView>::ViewRanges(void) {}
forceinline
ViewRanges<NegBoolView>::ViewRanges(const NegBoolView& x)
: Iter::Ranges::Singleton(x.min(),x.max()) {}
forceinline void
ViewRanges<NegBoolView>::init(const NegBoolView& x) {
Iter::Ranges::Singleton::init(x.min(),x.max());
}
}}
// STATISTICS: int-var
Gecode::Delta
Generic domain change information to be supplied to advisors.
Definition core.hpp:204
Gecode::DerivedView::base
View base(void) const
Return view from which this view is derived.
Definition view.hpp:605
Gecode::DerivedView< BoolView >::x
BoolView x
Definition view.hpp:238
Gecode::DerivedView< BoolView >::DerivedView
DerivedView(void)
Definition view.hpp:584
Gecode::Int::BoolView
Boolean view for Boolean variables.
Definition view.hpp:1380
Gecode::Int::BoolView::zero
bool zero(void) const
Test whether view is assigned to be zero.
Definition bool.hpp:220
Gecode::Int::BoolView::one
bool one(void) const
Test whether view is assigned to be one.
Definition bool.hpp:224
Gecode::Int::NegBoolView
Negated Boolean view.
Definition view.hpp:1574
Gecode::Int::NegBoolView::gr
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition neg-bool.hpp:129
Gecode::Int::NegBoolView::status
BoolStatus status(void) const
Return current domain status.
Definition neg-bool.hpp:61
Gecode::Int::NegBoolView::zero
bool zero(void) const
Test whether view is assigned to be zero.
Definition neg-bool.hpp:65
Gecode::Int::NegBoolView::one
bool one(void) const
Test whether view is assigned to be one.
Definition neg-bool.hpp:69
Gecode::Int::NegBoolView::gq
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition neg-bool.hpp:121
Gecode::Int::NegBoolView::none
bool none(void) const
Test whether view is not yet assigned.
Definition neg-bool.hpp:73
Gecode::Int::NegBoolView::le
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition neg-bool.hpp:113
Gecode::Int::NegBoolView::width
unsigned int width(const Delta &d) const
Return width of values just pruned.
Definition neg-bool.hpp:190
Gecode::Int::NegBoolView::one_none
ModEvent one_none(Space &home)
Assign not yet assigned view to one.
Definition neg-bool.hpp:87
Gecode::Int::NegBoolView::any
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition neg-bool.hpp:194
Gecode::Int::NegBoolView::lq
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition neg-bool.hpp:105
Gecode::Int::NegBoolView::nq
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition neg-bool.hpp:137
Gecode::Int::NegBoolView::max
int max(void) const
Return maximum of domain.
Definition neg-bool.hpp:162
Gecode::Int::NegBoolView::eq
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition neg-bool.hpp:145
Gecode::Int::NegBoolView::min
int min(void) const
Return minimum of domain.
Definition neg-bool.hpp:158
Gecode::Int::NegBoolView::zero_none
ModEvent zero_none(Space &home)
Assign not yet assigned view to zero.
Definition neg-bool.hpp:83
Gecode::Int::NegBoolView::NegBoolView
NegBoolView(void)
Default constructor.
Definition neg-bool.hpp:50
Gecode::Int::NegBoolView::val
int val(void) const
Return assigned value (only if assigned).
Definition neg-bool.hpp:166
Gecode::Int::ViewRanges< NegBoolView >::ViewRanges
ViewRanges(void)
Default constructor.
Definition neg-bool.hpp:239
Gecode::Int::ViewRanges< NegBoolView >::max
int max(void) const
Gecode::Int::ViewRanges< NegBoolView >::min
int min(void) const
Gecode::Int::ViewRanges::init
void init(const View &x)
Initialize with ranges for view x.
Gecode::Int::ViewRanges::ViewRanges
ViewRanges(void)
Default constructor.
Gecode::Iter::Ranges::Singleton
Range iterator for singleton range.
Definition ranges-singleton.hpp:42
Gecode::Iter::Ranges::Singleton::init
void init(int min, int max)
Initialize with range min to max.
Definition ranges-singleton.hpp:70
Gecode::Iter::Ranges::Singleton::Singleton
Singleton(void)
Default constructor.
Definition ranges-singleton.hpp:63
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::Int
Finite domain integers.
Gecode::Int::ME_BOOL_NONE
const Gecode::ModEvent ME_BOOL_NONE
Domain operation has not changed domain.
Definition var-type.hpp:114
Gecode::Int::ME_BOOL_FAILED
const Gecode::ModEvent ME_BOOL_FAILED
Domain operation has resulted in failure.
Definition var-type.hpp:112
Gecode::Int::operator==
bool operator==(const CachedView< View > &x, const CachedView< View > &y)
Definition cached.hpp:401
Gecode::Int::BoolStatus
unsigned int BoolStatus
Type for status of a Boolean variable.
Definition var-imp.hpp:484
Gecode::Int::operator!=
bool operator!=(const CachedView< View > &x, const CachedView< View > &y)
Definition cached.hpp:406
Gecode::Iter
Range and value iterators.
Definition iter.hh:41
Gecode
Gecode toplevel namespace
Gecode::ModEvent
int ModEvent
Type for modification events.
Definition core.hpp:62
forceinline
#define forceinline
Definition config.hpp:187