set-op.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, 2009
*
* 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 { namespace Sequence {
enum TakesStatus {
TS_NO,
TS_YES,
TS_MAYBE
};
template<class View>
forceinline TakesStatus
takes(const View& x, int s) {
if (x.in(s))
return x.assigned() ? TS_YES : TS_MAYBE;
else
return TS_NO;
}
template<class View>
forceinline TakesStatus
takes(const View& x, const IntSet& s) {
if ((x.max() < s.min()) || (x.min() > s.max()))
return TS_NO;
ViewRanges<View> ix(x);
IntSetRanges is(s);
switch (Iter::Ranges::compare(ix,is)) {
case Iter::Ranges::CS_SUBSET: return TS_YES;
case Iter::Ranges::CS_DISJOINT: return TS_NO;
case Iter::Ranges::CS_NONE: return TS_MAYBE;
default: GECODE_NEVER;
}
return TS_MAYBE;
}
template<class View>
forceinline bool
includes(const View& x, int s) {
return x.assigned() && x.in(s);
}
template<class View>
forceinline bool
includes(const View& x, const IntSet& s) {
if ((x.max() < s.min()) || (x.min() > s.max()))
return false;
ViewRanges<View> ix(x);
IntSetRanges is(s);
return Iter::Ranges::subset(ix,is);
}
template<class View>
forceinline bool
excludes(const View& x, int s) {
return !x.in(s);
}
template<class View>
forceinline bool
excludes(const View& x, const IntSet& s) {
if ((x.max() < s.min()) || (x.min() > s.max()))
return true;
ViewRanges<View> ix(x);
IntSetRanges is(s);
return Iter::Ranges::disjoint(ix,is);
}
template<class View>
forceinline bool
undecided(const View& x, int s) {
return !x.assigned() && x.in(s);
}
template<class View>
forceinline bool
undecided(const View& x, const IntSet& s) {
if ((x.max() < s.min()) || (x.min() > s.max()))
return false;
ViewRanges<View> ix(x);
IntSetRanges is(s);
return Iter::Ranges::compare(ix,is) == Iter::Ranges::CS_NONE;
}
template<class View>
forceinline ModEvent
include(Space& home, View& x, int s) {
return x.eq(home,s);
}
template<class View>
forceinline ModEvent
include(Space& home, View& x, const IntSet& s) {
IntSetRanges is(s);
return x.inter_r(home,is,false);
}
template<class View>
forceinline ModEvent
exclude(Space& home, View& x, int s) {
return x.nq(home,s);
}
template<class View>
forceinline ModEvent
exclude(Space& home, View& x, const IntSet& s) {
IntSetRanges is(s);
return x.minus_r(home,is,false);
}
}}}
// STATISTICS: int-prop
Gecode::IntSetRanges
Range iterator for integer sets.
Definition int.hh:292
Gecode::IntSet
Integer sets.
Definition int.hh:174
Gecode::IntSet::min
int min(int i) const
Return minimum of range at position i.
Definition int-set-1.hpp:152
Gecode::IntSet::max
int max(int i) const
Return maximum of range at position i.
Definition int-set-1.hpp:158
Gecode::Int::ViewRanges
Range iterator for integer views.
Definition view.hpp:54
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::View
Gecode::Int::Sequence
Sequence propagators
Definition sequence.hh:40
Gecode::Int::Sequence::exclude
ModEvent exclude(Space &home, View &x, int s)
Prune view x to exclude all values from s.
Definition set-op.hpp:137
Gecode::Int::Sequence::excludes
bool excludes(const View &x, int s)
Test whether all values of view x are excluded from s.
Definition set-op.hpp:89
Gecode::Int::Sequence::TakesStatus
TakesStatus
Status of whether a view takes a value from a set.
Definition set-op.hpp:37
Gecode::Int::Sequence::TS_MAYBE
@ TS_MAYBE
Maybe or maybe not.
Definition set-op.hpp:40
Gecode::Int::Sequence::TS_NO
@ TS_NO
Definitely not.
Definition set-op.hpp:38
Gecode::Int::Sequence::TS_YES
@ TS_YES
Definitely yes.
Definition set-op.hpp:39
Gecode::Int::Sequence::includes
bool includes(const View &x, int s)
Test whether all values of view x are included in s.
Definition set-op.hpp:72
Gecode::Int::Sequence::include
ModEvent include(Space &home, View &x, int s)
Prune view x to only include values from s.
Definition set-op.hpp:123
Gecode::Int::Sequence::undecided
bool undecided(const View &x, int s)
Test whether no decision on inclusion or exclusion of values of view x in s can be made.
Definition set-op.hpp:106
Gecode::Int::Sequence::takes
TakesStatus takes(const View &x, int s)
Return whether view x takes value s.
Definition set-op.hpp:46
Gecode::Int
Finite domain integers.
Gecode::Iter::Ranges::CS_NONE
@ CS_NONE
Neither of the above.
Definition ranges-operations.hpp:63
Gecode::Iter::Ranges::CS_SUBSET
@ CS_SUBSET
First is subset of second iterator.
Definition ranges-operations.hpp:61
Gecode::Iter::Ranges::CS_DISJOINT
@ CS_DISJOINT
Intersection is empty.
Definition ranges-operations.hpp:62
Gecode::Iter::Ranges::subset
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
Definition ranges-operations.hpp:97
Gecode::Iter::Ranges::compare
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
Definition ranges-operations.hpp:127
Gecode::Iter::Ranges::disjoint
bool disjoint(I &i, J &j)
Check whether range iterators i and j are disjoint.
Definition ranges-operations.hpp:112
Gecode
Gecode toplevel namespace
Gecode::ModEvent
int ModEvent
Type for modification events.
Definition core.hpp:62
forceinline
#define forceinline
Definition config.hpp:187
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56