partition.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 RelOp {
/*
* "Nary partition" propagator
*
*/
template<class View0, class View1>
forceinline
PartitionN<View0,View1>::PartitionN(Home home, ViewArray<View0>& x, View1 y)
: MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home, x, y) {
shared = Gecode::shared(x) || viewarrayshared(x,y);
}
template<class View0, class View1>
forceinline
PartitionN<View0,View1>::PartitionN(Home home, ViewArray<View0>& x,
const IntSet& z, View1 y)
: MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home, x, y) {
shared = Gecode::shared(x) || viewarrayshared(x,y);
IntSetRanges rz(z);
unionOfDets.includeI(home, rz);
}
template<class View0, class View1>
forceinline
PartitionN<View0,View1>::PartitionN(Space& home, PartitionN& p)
: MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home,p),
shared(p.shared) {
unionOfDets.update(home,p.unionOfDets);
}
template<class View0, class View1>
Actor*
PartitionN<View0,View1>::copy(Space& home) {
return new (home) PartitionN(home,*this);
}
template<class View0, class View1>
ExecStatus PartitionN<View0,View1>::post(Home home, ViewArray<View0>& x,
View1 y) {
switch (x.size()) {
case 0:
GECODE_ME_CHECK(y.cardMax(home, 0));
return ES_OK;
case 1:
return Rel::Eq<View0,View1>::post(home, x[0], y);
default:
(void) new (home) PartitionN<View0,View1>(home,x,y);
return ES_OK;
}
}
template<class View0, class View1>
ExecStatus PartitionN<View0,View1>::post(Home home, ViewArray<View0>& x,
const IntSet& z, View1 y) {
(void) new (home) PartitionN<View0,View1>(home,x,z,y);
return ES_OK;
}
template<class View0, class View1>
PropCost PartitionN<View0,View1>::cost(const Space&, const ModEventDelta&) const {
return PropCost::quadratic(PropCost::LO, x.size()+1);
}
template<class View0, class View1>
ExecStatus
PartitionN<View0,View1>::propagate(Space& home, const ModEventDelta& med) {
ModEvent me0 = View0::me(med);
ModEvent me1 = View1::me(med);
bool ubevent = Rel::testSetEventUB(me0, me1);
bool lbevent = Rel::testSetEventLB(me0, me1);
bool anybevent = Rel::testSetEventAnyB(me0, me1);
bool cardevent = Rel::testSetEventCard(me0, me1);
bool modified = false;
bool oldModified = false;
do {
oldModified = modified;
modified = false;
if (oldModified || anybevent)
GECODE_ES_CHECK(partitionNXiUB(home,modified, x, y,unionOfDets));
if (modified || oldModified || anybevent)
GECODE_ES_CHECK(partitionNXiLB(home,modified, x, y,unionOfDets));
if (modified || oldModified || ubevent)
GECODE_ES_CHECK(partitionNYUB(home,modified, x, y,unionOfDets));
if (modified || oldModified || lbevent)
GECODE_ES_CHECK(partitionNYLB(home,modified, x, y,unionOfDets));
if (modified || oldModified || ubevent)
GECODE_ES_CHECK(unionNXiUB(home,modified, x, y,unionOfDets));
if (modified || oldModified || cardevent)
GECODE_ES_CHECK(partitionNCard(home,modified, x, y,unionOfDets));
} while (modified);
//removing assigned sets from x, accumulating the value:
for(int i=0;i<x.size();i++) {
//Do not reverse! Eats away the end of the array!
while (i<x.size() && x[i].assigned()) {
GlbRanges<View0> det(x[i]);
unionOfDets.includeI(home,det);
x.move_lst(i);
}
}
// When we run out of variables, make a final check and disolve:
if (x.size()==0) {
BndSetRanges all1(unionOfDets);
GECODE_ME_CHECK( y.intersectI(home,all1) );
BndSetRanges all2(unionOfDets);
GECODE_ME_CHECK( y.includeI(home,all2) );
unionOfDets.dispose(home);
return home.ES_SUBSUMED(*this);
}
return shared ? ES_NOFIX : ES_FIX;
}
}}}
// 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::IntSetRanges
Range iterator for integer sets.
Definition int.hh:292
Gecode::IntSet
Integer sets.
Definition int.hh:174
Gecode::MixNaryOnePropagator< View0, PC_SET_ANY, View1, PC_SET_ANY >::MixNaryOnePropagator
MixNaryOnePropagator(Space &home, MixNaryOnePropagator &p)
Definition pattern.hpp:733
Gecode::MixNaryOnePropagator< View0, PC_SET_ANY, View1, PC_SET_ANY >::x
ViewArray< View0 > x
Definition pattern.hpp:275
Gecode::MixNaryOnePropagator< View0, PC_SET_ANY, View1, PC_SET_ANY >::y
View1 y
Definition pattern.hpp:277
Gecode::PropCost
Propagation cost.
Definition core.hpp:486
Gecode::PropCost::quadratic
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition core.hpp:4787
Gecode::PropCost::LO
@ LO
Cheap.
Definition core.hpp:513
Gecode::Propagator::Space
friend class Space
Definition core.hpp:1066
Gecode::Propagator::med
ModEventDelta med
A set of modification events (used during propagation).
Definition core.hpp:1075
Gecode::Set::BndSetRanges
Range iterator for integer sets.
Definition var-imp.hpp:185
Gecode::Set::GlbRanges
Range iterator for the greatest lower bound.
Definition var-imp.hpp:359
Gecode::Set::RelOp::PartitionN::shared
bool shared
Whether the any views share a variable implementation.
Definition rel-op.hh:261
Gecode::Set::RelOp::PartitionN::PartitionN
PartitionN(Space &home, PartitionN &p)
Constructor for cloning p.
Definition partition.hpp:66
Gecode::Set::RelOp::PartitionN::unionOfDets
GLBndSet unionOfDets
Union of the determined (which are dropped).
Definition rel-op.hh:263
Gecode::Set::RelOp::PartitionN::post
static ExecStatus post(Home home, ViewArray< View0 > &y, View1 x)
Post propagator .
Definition partition.hpp:79
Gecode::Set::RelOp::PartitionN::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition partition.hpp:74
Gecode::Set::RelOp::PartitionN::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition partition.hpp:107
Gecode::Set::RelOp::PartitionN::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition partition.hpp:101
Gecode::Set::Rel::Eq::post
static ExecStatus post(Home home, View0 x, View1 y)
Post propagator .
Definition eq.hpp:54
Gecode::ViewArray
View arrays.
Definition array.hpp:253
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_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::Set::RelOp
Standard set operation propagators.
Definition rel-op.hh:46
Gecode::Set::RelOp::partitionNCard
ExecStatus partitionNCard(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition common.hpp:308
Gecode::Set::RelOp::partitionNYLB
ExecStatus partitionNYLB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition common.hpp:560
Gecode::Set::RelOp::partitionNXiUB
ExecStatus partitionNXiUB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition common.hpp:467
Gecode::Set::RelOp::unionNXiUB
ExecStatus unionNXiUB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &)
Definition common.hpp:294
Gecode::Set::RelOp::partitionNXiLB
ExecStatus partitionNXiLB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition common.hpp:513
Gecode::Set::RelOp::partitionNYUB
ExecStatus partitionNYUB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition common.hpp:587
Gecode::Set::Rel::testSetEventLB
bool testSetEventLB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition common.hpp:83
Gecode::Set::Rel::testSetEventCard
bool testSetEventCard(ModEvent me0, ModEvent me1, ModEvent me2)
Definition common.hpp:95
Gecode::Set::Rel::testSetEventUB
bool testSetEventUB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition common.hpp:87
Gecode::Set::Rel::testSetEventAnyB
bool testSetEventAnyB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition common.hpp:91
Gecode::Set
Finite integer sets.
Definition var-imp.hpp:137
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::viewarrayshared
bool viewarrayshared(const ViewArray< View0 > &va, const View1 &y)
Definition common.hpp:47
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_NOFIX
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition core.hpp:475
Gecode::shared
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Definition array.hpp:1466
Gecode::ModEvent
int ModEvent
Type for modification events.
Definition core.hpp:62
forceinline
#define forceinline
Definition config.hpp:187