nq.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <tack@gecode.org>
* Christian Schulte <schulte@gecode.org>
*
* Contributing authors:
* Gabor Szokoli <szokoli@gecode.org>
*
* Copyright:
* Guido Tack, 2004
* Christian Schulte, 2004
* Gabor Szokoli, 2004
*
* 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 Set { namespace Rel {
template<class View0, class View1>
forceinline
Distinct<View0,View1>::Distinct(Home home, View0 x, View1 y)
: MixBinaryPropagator<View0, PC_SET_VAL, View1, PC_SET_VAL>(home,x,y) {}
template<class View0, class View1>
forceinline
Distinct<View0,View1>::Distinct(Space& home, Distinct& p)
: MixBinaryPropagator<View0, PC_SET_VAL, View1, PC_SET_VAL>
(home,p) {}
template<class View0, class View1>
ExecStatus
Distinct<View0,View1>::post(Home home, View0 x, View1 y) {
if (same(x,y))
return ES_FAILED;
if (x.assigned()) {
GlbRanges<View0> xr(x);
IntSet xs(xr);
ConstSetView cv(home, xs);
GECODE_ES_CHECK((DistinctDoit<View1>::post(home,y,cv)));
}
if (y.assigned()) {
GlbRanges<View1> yr(y);
IntSet ys(yr);
ConstSetView cv(home, ys);
GECODE_ES_CHECK((DistinctDoit<View0>::post(home,x,cv)));
}
(void) new (home) Distinct<View0,View1>(home,x,y);
return ES_OK;
}
template<class View0, class View1>
Actor*
Distinct<View0,View1>::copy(Space& home) {
return new (home) Distinct<View0,View1>(home,*this);
}
template<class View0, class View1>
ExecStatus
Distinct<View0,View1>::propagate(Space& home, const ModEventDelta&) {
assert(x0.assigned()||x1.assigned());
if (x0.assigned()) {
GlbRanges<View0> xr(x0);
IntSet xs(xr);
ConstSetView cv(home, xs);
GECODE_REWRITE(*this,(DistinctDoit<View1>::post(home(*this),x1,cv)));
} else {
GlbRanges<View1> yr(x1);
IntSet ys(yr);
ConstSetView cv(home, ys);
GECODE_REWRITE(*this,(DistinctDoit<View0>::post(home(*this),x0,cv)));
}
}
template<class View0>
ExecStatus
DistinctDoit<View0>::post(Home home, View0 x, ConstSetView y) {
(void) new (home) DistinctDoit<View0>(home,x,y);
return ES_OK;
}
template<class View0>
Actor*
DistinctDoit<View0>::copy(Space& home) {
return new (home) DistinctDoit<View0>(home,*this);
}
template<class View0>
ExecStatus
DistinctDoit<View0>::propagate(Space& home, const ModEventDelta&) {
if (x0.assigned()) {
GlbRanges<View0> xi(x0);
GlbRanges<ConstSetView> yi(y);
if (Iter::Ranges::equal(xi,yi)) { return ES_FAILED; }
else { return home.ES_SUBSUMED(*this); }
}
assert(x0.lubSize()-x0.glbSize() >0);
if (x0.cardMin()>y.cardMax()) { return home.ES_SUBSUMED(*this); }
if (x0.cardMax()<y.cardMin()) { return home.ES_SUBSUMED(*this); }
//These tests are too expensive, we should only do them
//in the 1 unknown left case.
GlbRanges<View0> xi1(x0);
LubRanges<ConstSetView> yi1(y);
if (!Iter::Ranges::subset(xi1,yi1)) { return home.ES_SUBSUMED(*this); }
LubRanges<View0> xi2(x0);
GlbRanges<ConstSetView> yi2(y);
if (!Iter::Ranges::subset(yi2,xi2)) { return home.ES_SUBSUMED(*this); }
// from here, we know y\subseteq lub(x) and glb(x)\subseteq y
if (x0.lubSize() == y.cardMin() && x0.lubSize() > 0) {
GECODE_ME_CHECK(x0.cardMax(home, x0.lubSize() - 1));
return home.ES_SUBSUMED(*this);
}
if (x0.glbSize() == y.cardMin()) {
GECODE_ME_CHECK(x0.cardMin(home, x0.glbSize() + 1));
return home.ES_SUBSUMED(*this);
}
return ES_FIX;
}
template<class View0>
forceinline
DistinctDoit<View0>::DistinctDoit(Home home, View0 _x, ConstSetView _y)
: UnaryPropagator<View0, PC_SET_ANY>(home,_x), y(_y) {}
template<class View0>
forceinline
DistinctDoit<View0>::DistinctDoit(Space& home, DistinctDoit<View0>& p)
: UnaryPropagator<View0, PC_SET_ANY>(home,p) {
y.update(home,p.y);
}
}}}
// STATISTICS: set-prop
Gecode::Actor
Base-class for both propagators and branchers.
Definition core.hpp:628
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::IntSet
Integer sets.
Definition int.hh:174
Gecode::MixBinaryPropagator< View0, PC_SET_VAL, View1, PC_SET_VAL >::x1
View1 x1
Definition pattern.hpp:209
Gecode::MixBinaryPropagator< View0, PC_SET_VAL, View1, PC_SET_VAL >::MixBinaryPropagator
MixBinaryPropagator(Space &home, MixBinaryPropagator &p)
Definition pattern.hpp:597
Gecode::MixBinaryPropagator< View0, PC_SET_VAL, View1, PC_SET_VAL >::x0
View0 x0
Definition pattern.hpp:207
Gecode::Propagator::Space
friend class Space
Definition core.hpp:1066
Gecode::Set::ConstSetView
Constant view.
Definition view.hpp:186
Gecode::Set::GlbRanges
Range iterator for the greatest lower bound.
Definition var-imp.hpp:359
Gecode::Set::LubRanges
Range iterator for the least upper bound.
Definition var-imp.hpp:317
Gecode::Set::Rel::DistinctDoit::DistinctDoit
DistinctDoit(Space &home, DistinctDoit &)
Constructor for cloning p.
Definition nq.hpp:150
Gecode::Set::Rel::DistinctDoit::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition nq.hpp:106
Gecode::Set::Rel::DistinctDoit::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition nq.hpp:112
Gecode::Set::Rel::DistinctDoit::post
static ExecStatus post(Home home, View0 x, ConstSetView y)
Post propagator .
Definition nq.hpp:99
Gecode::Set::Rel::DistinctDoit::y
ConstSetView y
The view that is already assigned.
Definition rel.hh:300
Gecode::Set::Rel::Distinct::Distinct
Distinct(Space &home, Distinct &p)
Constructor for cloning p.
Definition nq.hpp:49
Gecode::Set::Rel::Distinct::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition nq.hpp:76
Gecode::Set::Rel::Distinct::post
static ExecStatus post(Home home, View0 x, View1 y)
Post propagator .
Definition nq.hpp:55
Gecode::Set::Rel::Distinct::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition nq.hpp:82
Gecode::UnaryPropagator< View0, PC_SET_ANY >::x0
View0 x0
Definition pattern.hpp:58
Gecode::UnaryPropagator< View0, PC_SET_ANY >::UnaryPropagator
UnaryPropagator(Space &home, UnaryPropagator &p)
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition core.hpp:3563
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
GECODE_ME_CHECK
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition macros.hpp:52
GECODE_REWRITE
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition macros.hpp:116
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
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::equal
bool equal(I &i, J &j)
Check whether range iterators i and j are equal.
Definition ranges-operations.hpp:84
Gecode::Set::Rel
Standard set relation propagators.
Definition rel.hh:45
Gecode::Set
Finite integer sets.
Definition var-imp.hpp:137
Gecode::Set::PC_SET_VAL
const Gecode::PropCond PC_SET_VAL
Propagate when a view becomes assigned (single value).
Definition var-type.hpp:207
Gecode::Set::PC_SET_ANY
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition var-type.hpp:248
Gecode
Gecode toplevel namespace
Gecode::same
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
Definition array.hpp:1937
Gecode::ExecStatus
ExecStatus
Definition core.hpp:472
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition core.hpp:476
Gecode::ES_FIX
@ ES_FIX
Propagation has computed fixpoint.
Definition core.hpp:477
Gecode::ES_FAILED
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:474
forceinline
#define forceinline
Definition config.hpp:187