minus.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, 2003
* 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 {
/*
* Constructors and initialization
*
*/
forceinline
MinusView::MinusView(void) {}
forceinline
MinusView::MinusView(const IntView& y)
: DerivedView<IntView>(y) {}
/*
* Value access
*
*/
forceinline int
MinusView::min(void) const {
return -x.max();
}
forceinline int
MinusView::max(void) const {
return -x.min();
}
forceinline int
MinusView::val(void) const {
return -x.val();
}
#ifdef GECODE_HAS_CBS
forceinline int
MinusView::baseval(int val) const {
return -val;
}
#endif
forceinline unsigned int
MinusView::width(void) const {
return x.width();
}
forceinline unsigned int
MinusView::size(void) const {
return x.size();
}
forceinline unsigned int
MinusView::regret_min(void) const {
return x.regret_max();
}
forceinline unsigned int
MinusView::regret_max(void) const {
return x.regret_min();
}
/*
* Domain tests
*
*/
forceinline bool
MinusView::range(void) const {
return x.range();
}
forceinline bool
MinusView::in(int n) const {
return x.in(-n);
}
forceinline bool
MinusView::in(long long int n) const {
return x.in(-n);
}
/*
* Domain update by value
*
*/
forceinline ModEvent
MinusView::lq(Space& home, int n) {
return x.gq(home,-n);
}
forceinline ModEvent
MinusView::lq(Space& home, long long int n) {
return x.gq(home,-n);
}
forceinline ModEvent
MinusView::le(Space& home, int n) {
return x.gr(home,-n);
}
forceinline ModEvent
MinusView::le(Space& home, long long int n) {
return x.gr(home,-n);
}
forceinline ModEvent
MinusView::gq(Space& home, int n) {
return x.lq(home,-n);
}
forceinline ModEvent
MinusView::gq(Space& home, long long int n) {
return x.lq(home,-n);
}
forceinline ModEvent
MinusView::gr(Space& home, int n) {
return x.le(home,-n);
}
forceinline ModEvent
MinusView::gr(Space& home, long long int n) {
return x.le(home,-n);
}
forceinline ModEvent
MinusView::nq(Space& home, int n) {
return x.nq(home,-n);
}
forceinline ModEvent
MinusView::nq(Space& home, long long int n) {
return x.nq(home,-n);
}
forceinline ModEvent
MinusView::eq(Space& home, int n) {
return x.eq(home,-n);
}
forceinline ModEvent
MinusView::eq(Space& home, long long int n) {
return x.eq(home,-n);
}
/*
* Iterator-based domain update
*
*/
template<class I>
forceinline ModEvent
MinusView::narrow_r(Space& home, I& i, bool) {
Region r;
Iter::Ranges::Minus mi(r,i);
return x.narrow_r(home,mi,false);
}
template<class I>
forceinline ModEvent
MinusView::inter_r(Space& home, I& i, bool) {
Region r;
Iter::Ranges::Minus mi(r,i);
return x.inter_r(home,mi,false);
}
template<class I>
forceinline ModEvent
MinusView::minus_r(Space& home, I& i, bool) {
Region r;
Iter::Ranges::Minus mi(r,i);
return x.minus_r(home,mi,false);
}
template<class I>
forceinline ModEvent
MinusView::narrow_v(Space& home, I& i, bool) {
Region r;
Iter::Values::Minus mi(r,i);
return x.narrow_v(home,mi,false);
}
template<class I>
forceinline ModEvent
MinusView::inter_v(Space& home, I& i, bool) {
Region r;
Iter::Values::Minus mi(r,i);
return x.inter_v(home,mi,false);
}
template<class I>
forceinline ModEvent
MinusView::minus_v(Space& home, I& i, bool) {
Region r;
Iter::Values::Minus mi(r,i);
return x.minus_v(home,mi,false);
}
/*
* Propagator modification events
*
*/
forceinline ModEventDelta
MinusView::med(ModEvent me) {
return IntView::med(me);
}
/*
* Delta information for advisors
*
*/
forceinline int
MinusView::min(const Delta& d) const {
return -x.max(d);
}
forceinline int
MinusView::max(const Delta& d) const {
return -x.min(d);
}
forceinline unsigned int
MinusView::width(const Delta& d) const {
return x.width(d);
}
forceinline bool
MinusView::any(const Delta& d) const {
return x.any(d);
}
template<>
class ViewRanges<MinusView> : public IntVarImpBwd {
public:
ViewRanges(void);
ViewRanges(const MinusView& x);
void init(const MinusView& x);
int min(void) const;
int max(void) const;
};
forceinline
ViewRanges<MinusView>::ViewRanges(void) {}
forceinline
ViewRanges<MinusView>::ViewRanges(const MinusView& x)
: IntVarImpBwd(x.base().varimp()) {}
forceinline void
ViewRanges<MinusView>::init(const MinusView& x) {
IntVarImpBwd::init(x.base().varimp());
}
forceinline int
ViewRanges<MinusView>::min(void) const {
return -IntVarImpBwd::max();
}
forceinline int
ViewRanges<MinusView>::max(void) const {
return -IntVarImpBwd::min();
}
inline int
MinusView::med(void) const {
if (x.range())
return (min()+max())/2 - ((min()+max())%2 < 0 ? 1 : 0);
unsigned int i = x.size() / 2;
if (size() % 2 == 0)
i--;
ViewRanges<MinusView> r(*this);
while (i >= r.width()) {
i -= r.width();
++r;
}
return r.min() + static_cast<int>(i);
}
/*
* View comparison
*
*/
forceinline bool
operator ==(const MinusView& x, const MinusView& y) {
return x.base() == y.base();
}
forceinline bool
operator !=(const MinusView& x, const MinusView& y) {
return !(x == y);
}
}}
// 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< IntView >::x
IntView x
Definition view.hpp:238
Gecode::DerivedView< IntView >::DerivedView
DerivedView(void)
Definition view.hpp:584
Gecode::DerivedView< IntView >::me
static ModEvent me(const ModEventDelta &med)
Definition view.hpp:639
Gecode::Int::IntVarImpBwd::max
int max(void) const
Return largest value of range.
Definition int.hpp:488
Gecode::Int::IntVarImpBwd::min
int min(void) const
Return smallest value of range.
Definition int.hpp:484
Gecode::Int::IntVarImpBwd::init
void init(const IntVarImp *x)
Initialize with ranges from variable implementation x.
Definition int.hpp:470
Gecode::Int::IntVarImpBwd::IntVarImpBwd
IntVarImpBwd(void)
Default constructor.
Definition int.hpp:465
Gecode::Int::IntView
Integer view for integer variables.
Definition view.hpp:129
Gecode::Int::IntView::med
int med(void) const
Return median of domain (greatest element not greater than the median).
Definition int.hpp:66
Gecode::Int::MinusView
Minus integer view.
Definition view.hpp:282
Gecode::Int::MinusView::narrow_v
ModEvent narrow_v(Space &home, I &i, bool depends=true)
Replace domain by values described by i.
Definition minus.hpp:196
Gecode::Int::MinusView::eq
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition minus.hpp:160
Gecode::Int::MinusView::nq
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition minus.hpp:151
Gecode::Int::MinusView::regret_max
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value).
Definition minus.hpp:87
Gecode::Int::MinusView::le
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition minus.hpp:124
Gecode::Int::MinusView::width
unsigned int width(void) const
Return width of domain (distance between maximum and minimum).
Definition minus.hpp:75
Gecode::Int::MinusView::gr
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition minus.hpp:142
Gecode::Int::MinusView::lq
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition minus.hpp:115
Gecode::Int::MinusView::regret_min
unsigned int regret_min(void) const
Return regret of domain minimum (distance to next larger value).
Definition minus.hpp:83
Gecode::Int::MinusView::minus_r
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition minus.hpp:189
Gecode::Int::MinusView::gq
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition minus.hpp:133
Gecode::Int::MinusView::inter_v
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
Definition minus.hpp:203
Gecode::Int::MinusView::max
int max(void) const
Return maximum of domain.
Definition minus.hpp:60
Gecode::Int::MinusView::min
int min(void) const
Return minimum of domain.
Definition minus.hpp:56
Gecode::Int::MinusView::inter_r
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition minus.hpp:182
Gecode::Int::MinusView::in
bool in(int n) const
Test whether n is contained in domain.
Definition minus.hpp:101
Gecode::Int::MinusView::range
bool range(void) const
Test whether domain is a range.
Definition minus.hpp:97
Gecode::Int::MinusView::size
unsigned int size(void) const
Return size (cardinality) of domain.
Definition minus.hpp:79
Gecode::Int::MinusView::narrow_r
ModEvent narrow_r(Space &home, I &i, bool depends=true)
Replace domain by ranges described by i.
Definition minus.hpp:175
Gecode::Int::MinusView::any
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition minus.hpp:244
Gecode::Int::MinusView::minus_v
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
Definition minus.hpp:210
Gecode::Int::MinusView::MinusView
MinusView(void)
Default constructor.
Definition minus.hpp:45
Gecode::Int::MinusView::med
int med(void) const
Return median of domain.
Definition minus.hpp:297
Gecode::Int::MinusView::val
int val(void) const
Return assigned value (only if assigned).
Definition minus.hpp:64
Gecode::Int::ViewRanges< MinusView >::ViewRanges
ViewRanges(void)
Default constructor.
Definition minus.hpp:276
Gecode::Int::ViewRanges
Range iterator for integer views.
Definition view.hpp:54
Gecode::Int::ViewRanges::max
int max(void) const
Return largest value of range.
Gecode::Int::ViewRanges::min
int min(void) const
Return smallest value of range.
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::Minus
Range iterator for pointwise minus of a range iterator.
Definition ranges-minus.hpp:47
Gecode::Iter::Values::Minus
Value iterator for pointwise minus of a value iterator.
Definition values-minus.hpp:47
Gecode::Region
Handle to region.
Definition region.hpp:55
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::VarImpView::varimp
void varimp(VarImpType *y)
Set variable implementation to y.
Definition view.hpp:484
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
Gecode::Int
Finite domain integers.
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
Gecode toplevel namespace
Gecode::ModEvent
int ModEvent
Type for modification events.
Definition core.hpp:62
forceinline
#define forceinline
Definition config.hpp:187