rel.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.
*
*/
#include <gecode/int/rel.hh>
namespace Gecode { namespace Int { namespace Count {
/*
* Counting domain consistent equality
*
*/
template<class VY>
forceinline bool
isintset(VY y) {
(void) y;
return false;
}
template<>
forceinline bool
isintset(IntSet y) {
(void) y;
return true;
}
template<class VY>
forceinline bool
isval(VY y) {
return y.assigned();
}
template<>
forceinline bool
isval(IntSet y) {
(void) y;
return true;
}
forceinline void
subscribe(Space& home, Propagator& p, IntSet& y) {
(void) home; (void) p; (void) y;
}
template<class VY>
forceinline void
subscribe(Space& home, Propagator& p, VY y) {
y.subscribe(home, p, PC_INT_DOM);
}
forceinline void
cancel(Space& home, Propagator& p, IntSet& y) {
(void) home; (void) p;
y.~IntSet();
}
template<class VY>
forceinline void
cancel(Space& home, Propagator& p, VY y) {
y.cancel(home, p, PC_INT_DOM);
}
forceinline void
reschedule(Space& home, Propagator& p, IntSet& y) {
(void) home; (void) p; (void) y;
}
template<class VY>
forceinline void
reschedule(Space& home, Propagator& p, VY y) {
(void) y; // To satisy MSVC
y.schedule(home, p, PC_INT_DOM);
}
forceinline void
update(IntSet& y, Space& home, IntSet& py) {
(void) home;
y=py;
}
template<class VY>
forceinline void
update(VY& y, Space& home, VY py) {
y.update(home, py);
}
template<class VX>
forceinline RelTest
holds(VX x, ConstIntView y) {
return rtest_eq_dom(x,y.val());
}
template<class VX>
forceinline RelTest
holds(VX x, ZeroIntView) {
return rtest_eq_dom(x,0);
}
template<class VX>
forceinline RelTest
holds(VX x, const IntSet& y) {
if ((x.max() < y.min()) || (y.max() < x.min()))
return RT_FALSE;
ViewRanges<VX> rx(x);
IntSetRanges ry(y);
switch (Iter::Ranges::compare(rx,ry)) {
case Iter::Ranges::CS_SUBSET:
return RT_TRUE;
case Iter::Ranges::CS_DISJOINT:
return RT_FALSE;
case Iter::Ranges::CS_NONE:
return RT_MAYBE;
default:
GECODE_NEVER;
}
GECODE_NEVER;
return RT_MAYBE;
}
template<class VX>
forceinline RelTest
holds(VX x, VX y) {
return rtest_eq_dom(x,y);
}
template<class VX>
forceinline ExecStatus
post_true(Home home, VX x, ConstIntView y) {
GECODE_ME_CHECK(x.eq(home,y.val()));
return ES_OK;
}
template<class VX>
forceinline ExecStatus
post_true(Home home, VX x, ZeroIntView) {
GECODE_ME_CHECK(x.eq(home,0));
return ES_OK;
}
template<class VX>
forceinline ExecStatus
post_true(Home home, VX x, const IntSet& y) {
IntSetRanges ry(y);
GECODE_ME_CHECK(x.inter_r(home,ry,false));
return ES_OK;
}
template<class VX>
forceinline ExecStatus
post_true(Home home, ViewArray<VX>& x, ConstIntView y) {
for (int i=0; i<x.size(); i++)
GECODE_ME_CHECK(x[i].eq(home,y.val()));
return ES_OK;
}
template<class VX>
forceinline ExecStatus
post_true(Home home, ViewArray<VX>& x, ZeroIntView) {
for (int i=0; i<x.size(); i++)
GECODE_ME_CHECK(x[i].eq(home,0));
return ES_OK;
}
template<class VX>
forceinline ExecStatus
post_true(Home home, ViewArray<VX>& x, const IntSet& y) {
for (int i=0; i<x.size(); i++) {
IntSetRanges ry(y);
GECODE_ME_CHECK(x[i].inter_r(home,ry,false));
}
return ES_OK;
}
template<class VX>
forceinline ExecStatus
post_false(Home home, VX x, ConstIntView y) {
GECODE_ME_CHECK(x.nq(home,y.val()));
return ES_OK;
}
template<class VX>
forceinline ExecStatus
post_false(Home home, VX x, ZeroIntView) {
GECODE_ME_CHECK(x.nq(home,0));
return ES_OK;
}
template<class VX>
forceinline ExecStatus
post_false(Home home, VX x, const IntSet& y) {
IntSetRanges ry(y);
GECODE_ME_CHECK(x.minus_r(home,ry,false));
return ES_OK;
}
template<class VX>
forceinline ExecStatus
post_false(Home home, ViewArray<VX>& x, ConstIntView y) {
for (int i=0; i<x.size(); i++)
GECODE_ME_CHECK(x[i].nq(home,y.val()));
return ES_OK;
}
template<class VX>
forceinline ExecStatus
post_false(Home home, ViewArray<VX>& x, ZeroIntView) {
for (int i=0; i<x.size(); i++)
GECODE_ME_CHECK(x[i].nq(home,0));
return ES_OK;
}
template<class VX>
forceinline ExecStatus
post_false(Home home, ViewArray<VX>& x, const IntSet& y) {
for (int i=0; i<x.size(); i++) {
IntSetRanges ry(y);
GECODE_ME_CHECK(x[i].minus_r(home,ry,false));
}
return ES_OK;
}
template<class VX>
forceinline ExecStatus
post_true(Home home, ViewArray<VX>& x, VX y) {
ViewArray<VX> z(home,x.size()+1);
z[x.size()] = y;
for (int i=0; i<x.size(); i++)
z[i] = x[i];
return Rel::NaryEqDom<VX>::post(home,z);
}
template<class VX>
forceinline ExecStatus
post_true(Home home, VX x, VX y) {
return Rel::EqDom<VX,VX>::post(home,x,y);
}
template<class VX>
forceinline ExecStatus
post_false(Home home, ViewArray<VX>& x, VX y) {
for (int i=0; i<x.size(); i++)
GECODE_ES_CHECK((Rel::Nq<VX,VX>::post(home,x[i],y)));
return ES_OK;
}
template<class VX>
forceinline ExecStatus
post_false(Home home, VX x, VX y) {
return Rel::Nq<VX,VX>::post(home,x,y);
}
template<class VX>
forceinline ExecStatus
prune(Space& home, ViewArray<VX>& x, ConstIntView) {
(void) home;
(void) x;
return ES_OK;
}
template<class VX>
forceinline ExecStatus
prune(Space& home, ViewArray<VX>& x, ZeroIntView) {
(void) home;
(void) x;
return ES_OK;
}
template<class VX>
forceinline ExecStatus
prune(Space& home, ViewArray<VX>& x, const IntSet& y) {
(void) home;
(void) x;
(void) y;
return ES_OK;
}
template<class VX>
forceinline ExecStatus
prune(Space& home, ViewArray<VX>& x, VX y) {
if (x.size() == 0)
return ES_OK;
Region r;
ViewRanges<VX>* rx = r.alloc<ViewRanges<VX> >(x.size());
for (int i=0; i<x.size(); i++)
rx[i] = ViewRanges<VX>(x[i]);
Iter::Ranges::NaryUnion u(r, rx, x.size());
GECODE_ME_CHECK(y.inter_r(home, u, false));
return ES_OK;
}
}}}
// STATISTICS: int-prop
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
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::ConstIntView
Constant integer view.
Definition view.hpp:851
Gecode::Int::ConstIntView::val
int val(void) const
Return assigned value (only if assigned).
Definition constint.hpp:62
Gecode::Int::Rel::EqDom::post
static ExecStatus post(Home home, View0 x0, View1 x1)
Post domain consistent propagator .
Definition eq.hpp:176
Gecode::Int::Rel::NaryEqDom::post
static ExecStatus post(Home home, ViewArray< View > &x)
Post domain consistent propagator .
Definition eq.hpp:270
Gecode::Int::Rel::Nq::post
static ExecStatus post(Home home, V0 x0, V1 x1)
Post propagator .
Definition nq.hpp:49
Gecode::Int::ViewRanges
Range iterator for integer views.
Definition view.hpp:54
Gecode::Int::ZeroIntView
Zero integer view.
Definition view.hpp:1014
Gecode::Iter::Ranges::NaryUnion
Range iterator for union of iterators.
Definition ranges-union.hpp:74
Gecode::Propagator
Base-class for propagators.
Definition core.hpp:1064
Gecode::Region
Handle to region.
Definition region.hpp:55
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::ViewArray
View arrays.
Definition array.hpp:253
Gecode::ViewArray::size
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1156
GECODE_ME_CHECK
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition macros.hpp:52
GECODE_ES_CHECK
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition macros.hpp:91
rel.hh
Gecode::Int::Count
Counting propagators.
Gecode::Int::Count::cancel
void cancel(Space &home, Propagator &p, VY y)
Cancel propagator p for view y.
Definition rel.hpp:87
Gecode::Int::Count::update
void update(VY &y, Space &home, bool shared, VY py)
Update view y from py.
Gecode::Int::Count::prune
ExecStatus prune(Home home, ViewArray< VX > &x, VX y)
Prune that y is the union of x.
Gecode::Int::Count::isval
bool isval(VY y)
Return whether y is a value.
Definition rel.hpp:59
Gecode::Int::Count::post_false
ExecStatus post_false(Home home, ViewArray< VX > &x, VX y)
Post that all views in x are not equal to y.
Definition rel.hpp:251
Gecode::Int::Count::post_true
ExecStatus post_true(Home home, ViewArray< VX > &x, VX y)
Post that all views in x are equal to y.
Definition rel.hpp:237
Gecode::Int::Count::isintset
bool isintset(VY y)
Return whether y is an integer set.
Definition rel.hpp:45
Gecode::Int::Count::subscribe
void subscribe(Space &home, Propagator &p, VY y)
Subscribe propagator p to view y.
Definition rel.hpp:76
Gecode::Int::Count::reschedule
void reschedule(Space &home, Propagator &p, VY y)
Schedule propagator p for view y.
Definition rel.hpp:97
Gecode::Int::Count::holds
RelTest holds(VX x, VX y)
Test whether x and y are equal.
Definition rel.hpp:145
Gecode::Int
Finite domain integers.
Gecode::Int::rtest_eq_dom
RelTest rtest_eq_dom(VX x, VY y)
Test whether views x and y are equal (use full domain information).
Definition rel-test.hpp:65
Gecode::Int::PC_INT_DOM
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition var-type.hpp:100
Gecode::Int::RelTest
RelTest
Result of testing relation.
Definition view.hpp:1734
Gecode::Int::RT_TRUE
@ RT_TRUE
Relation does hold.
Definition view.hpp:1737
Gecode::Int::RT_MAYBE
@ RT_MAYBE
Relation may hold or not.
Definition view.hpp:1736
Gecode::Int::RT_FALSE
@ RT_FALSE
Relation does not hold.
Definition view.hpp:1735
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::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
Gecode toplevel namespace
Gecode::ExecStatus
ExecStatus
Definition core.hpp:472
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition core.hpp:476
forceinline
#define forceinline
Definition config.hpp:187
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56