bnd.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Patrick Pekczynski <pekczynski@ps.uni-sb.de>
*
* Contributing authors:
* Christian Schulte <schulte@gecode.org>
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Patrick Pekczynski, 2004/2005
* Christian Schulte, 2009
* Guido Tack, 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 GCC {
template<class Card>
forceinline
Bnd<Card>::
Bnd(Home home, ViewArray<IntView>& x0, ViewArray<Card>& k0,
bool cf, bool nolbc) :
Propagator(home), x(x0), y(home, x0), k(k0),
card_fixed(cf), skip_lbc(nolbc) {
y.subscribe(home, *this, PC_INT_BND);
k.subscribe(home, *this, PC_INT_BND);
}
template<class Card>
forceinline
Bnd<Card>::
Bnd(Space& home, Bnd<Card>& p)
: Propagator(home, p),
card_fixed(p.card_fixed), skip_lbc(p.skip_lbc) {
x.update(home, p.x);
y.update(home, p.y);
k.update(home, p.k);
}
template<class Card>
forceinline size_t
Bnd<Card>::dispose(Space& home) {
y.cancel(home,*this, PC_INT_BND);
k.cancel(home,*this, PC_INT_BND);
(void) Propagator::dispose(home);
return sizeof(*this);
}
template<class Card>
Actor*
Bnd<Card>::copy(Space& home) {
return new (home) Bnd<Card>(home,*this);
}
template<class Card>
PropCost
Bnd<Card>::cost(const Space&,
const ModEventDelta& med) const {
int n_k = Card::propagate ? k.size() : 0;
if (IntView::me(med) == ME_INT_VAL)
return PropCost::linear(PropCost::LO, y.size() + n_k);
else
return PropCost::quadratic(PropCost::LO, x.size() + n_k);
}
template<class Card>
void
Bnd<Card>::reschedule(Space& home) {
y.reschedule(home, *this, PC_INT_BND);
k.reschedule(home, *this, PC_INT_BND);
}
template<class Card>
forceinline ExecStatus
Bnd<Card>::lbc(Space& home, int& nb,
HallInfo hall[], Rank rank[], int mu[], int nu[]) {
int n = x.size();
/*
* Let I(S) denote the number of variables whose domain intersects
* the set S and C(S) the number of variables whose domain is containded
* in S. Let further min_cap(S) be the minimal number of variables
* that must be assigned to values, that is
* min_cap(S) is the sum over all l[i] for a value v_i that is an
* element of S.
*
* A failure set is a set F if
* I(F) < min_cap(F)
* An unstable set is a set U if
* I(U) = min_cap(U)
* A stable set is a set S if
* C(S) > min_cap(S) and S intersetcs nor
* any failure set nor any unstable set
* forall unstable and failure sets
*
* failure sets determine the satisfiability of the LBC
* unstable sets have to be pruned
* stable set do not have to be pruned
*
* hall[].ps ~ stores the unstable
* sets that have to be pruned
* hall[].s ~ stores sets that must not be pruned
* hall[].h ~ contains stable and unstable sets
* hall[].d ~ contains the difference between interval bounds, i.e.
* the minimal capacity of the interval
* hall[].t ~ contains the critical capacity pointer, pointing to the
* values
*/
// LBC lower bounds
int i = 0;
int j = 0;
int w = 0;
int z = 0;
int v = 0;
//initialization of the tree structure
int rightmost = nb + 1; // rightmost accesible value in bounds
int bsize = nb + 2;
w = rightmost;
// test
// unused but uninitialized
hall[0].d = 0;
hall[0].s = 0;
hall[0].ps = 0;
for (i = bsize; --i; ) { // i must not be zero
int pred = i - 1;
hall[i].s = pred;
hall[i].ps = pred;
hall[i].d = lps.sumup(hall[pred].bounds, hall[i].bounds - 1);
/* Let [hall[i].bounds,hall[i-1].bounds]=:I
* If the capacity is zero => min_cap(I) = 0
* => I cannot be a failure set
* => I is an unstable set
*/
if (hall[i].d == 0) {
hall[pred].h = w;
} else {
hall[w].h = pred;
w = pred;
}
}
w = rightmost;
for (i = bsize; i--; ) { // i can be zero
hall[i].t = i - 1;
if (hall[i].d == 0) {
hall[i].t = w;
} else {
hall[w].t = i;
w = i;
}
}
/*
* The algorithm assigns to each value v in bounds
* empty buckets corresponding to the minimal capacity l[i] to be
* filled for v. (the buckets correspond to hall[].d containing the
* difference between the interval bounds) Processing it
* searches for the smallest value v in dom(x_i) that has an
* empty bucket, i.e. if all buckets are filled it is guaranteed
* that there are at least l[i] variables that will be
* instantiated to v. Since the buckets are initially empty,
* they are considered as FAILURE SETS
*/
for (i = 0; i < n; i++) {
// visit intervals in increasing max order
int x0 = rank[mu[i]].min;
int y = rank[mu[i]].max;
int succ = x0 + 1;
z = pathmax_t(hall, succ);
j = hall[z].t;
/*
* POTENTIALLY STABLE SET:
* z \neq succ \Leftrigharrow z>succ, i.e.
* min(D_{\mu(i)}) is guaranteed to occur min(K_i) times
* \Rightarrow [x0, min(y,z)] is potentially stable
*/
if (z != succ) {
w = pathmax_ps(hall, succ);
v = hall[w].ps;
pathset_ps(hall, succ, w, w);
w = std::min(y, z);
pathset_ps(hall, hall[w].ps, v, w);
hall[w].ps = v;
}
/*
* STABLE SET:
* being stable implies being potentially stable, i.e.
* [hall[y].ps, hall[y].bounds-1] is the largest stable subset of
* [hall[j].bounds, hall[y].bounds-1].
*/
if (hall[z].d <= lps.sumup(hall[y].bounds, hall[z].bounds - 1)) {
w = pathmax_s(hall, hall[y].ps);
pathset_s(hall, hall[y].ps, w, w);
// Path compression
v = hall[w].s;
pathset_s(hall, hall[y].s, v, y);
hall[y].s = v;
} else {
/*
* FAILURE SET:
* If the considered interval [x0,y] is neither POTENTIALLY STABLE
* nor STABLE there are still buckets that can be filled,
* therefore d can be decreased. If d equals zero the intervals
* minimum capacity is met and thepath can be compressed to the
* next value having an empty bucket.
* see DOMINATION in "ubc"
*/
if (--hall[z].d == 0) {
hall[z].t = z + 1;
z = pathmax_t(hall, hall[z].t);
hall[z].t = j;
}
/*
* FINDING NEW LOWER BOUND:
* If the lower bound belongs to an unstable or a stable set,
* remind the new value we might assigned to the lower bound
* in case the variable doesn't belong to a stable set.
*/
if (hall[x0].h > x0) {
hall[i].newBound = pathmax_h(hall, x0);
w = hall[i].newBound;
pathset_h(hall, x0, w, w); // path compression
} else {
// Do not shrink the variable: take old min as new min
hall[i].newBound = x0;
}
/* UNSTABLE SET
* If an unstable set is discovered
* the difference between the interval bounds is equal to the
* number of variables whose domain intersect the interval
* (see ZEROTEST in "gcc")
*/
// CLEARLY THIS WAS NOT STABLE == UNSTABLE
if (hall[z].d == lps.sumup(hall[y].bounds, hall[z].bounds - 1)) {
if (hall[y].h > y)
/*
* y is not the end of the potentially stable set
* thus ensure that the potentially stable superset is marked
*/
y = hall[y].h;
// Equivalent to pathmax since the path is fully compressed
pathset_h(hall, hall[y].h, j-1, y);
// mark the new unstable set [j,y]
hall[y].h = j-1;
}
}
pathset_t(hall, succ, z, z); // path compression
}
/* If there is a FAILURE SET left the minimum occurences of the values
* are not guaranteed. In order to satisfy the LBC the last value
* in the stable and unstable datastructure hall[].h must point to
* the sentinel at the beginning of bounds.
*/
if (hall[nb].h != 0)
return ES_FAILED;
// Perform path compression over all elements in
// the stable interval data structure. This data
// structure will no longer be modified and will be
// accessed n or 2n times. Therefore, we can afford
// a linear time compression.
for (i = bsize; --i;)
if (hall[i].s > i)
hall[i].s = w;
else
w = i;
/*
* UPDATING LOWER BOUND:
* For all variables that are not a subset of a stable set,
* shrink the lower bound, i.e. forall stable sets S we have:
* x0 < S_min <= y <=S_max or S_min <= x0 <= S_max < y
* that is [x0,y] is NOT a proper subset of any stable set S
*/
for (i = n; i--; ) {
int x0 = rank[mu[i]].min;
int y = rank[mu[i]].max;
// update only those variables that are not contained in a stable set
if ((hall[x0].s <= x0) || (y > hall[x0].s)) {
// still have to check this out, how skipping works (consider dominated indices)
int m = lps.skipNonNullElementsRight(hall[hall[i].newBound].bounds);
GECODE_ME_CHECK(x[mu[i]].gq(home, m));
}
}
// LBC narrow upper bounds
w = 0;
for (i = 0; i <= nb; i++) {
hall[i].d = lps.sumup(hall[i].bounds, hall[i + 1].bounds - 1);
if (hall[i].d == 0) {
hall[i].t = w;
} else {
hall[w].t = i;
w = i;
}
}
hall[w].t = i;
w = 0;
for (i = 1; i <= nb; i++)
if (hall[i - 1].d == 0) {
hall[i].h = w;
} else {
hall[w].h = i;
w = i;
}
hall[w].h = i;
for (i = n; i--; ) {
// visit intervals in decreasing min order
// i.e. minsorted from right to left
int x0 = rank[nu[i]].max;
int y = rank[nu[i]].min;
int pred = x0 - 1; // predecessor of x0 in the indices
z = pathmin_t(hall, pred);
j = hall[z].t;
/* If the variable is not in a discovered stable set
* (see above condition for STABLE SET)
*/
if (hall[z].d > lps.sumup(hall[z].bounds, hall[y].bounds - 1)) {
// FAILURE SET
if (--hall[z].d == 0) {
hall[z].t = z - 1;
z = pathmin_t(hall, hall[z].t);
hall[z].t = j;
}
// FINDING NEW UPPER BOUND
if (hall[x0].h < x0) {
w = pathmin_h(hall, hall[x0].h);
hall[i].newBound = w;
pathset_h(hall, x0, w, w); // path compression
} else {
hall[i].newBound = x0;
}
// UNSTABLE SET
if (hall[z].d == lps.sumup(hall[z].bounds, hall[y].bounds - 1)) {
if (hall[y].h < y) {
y = hall[y].h;
}
int succj = j + 1;
// mark new unstable set [y,j]
pathset_h(hall, hall[y].h, succj, y);
hall[y].h = succj;
}
}
pathset_t(hall, pred, z, z);
}
// UPDATING UPPER BOUND
for (i = n; i--; ) {
int x0 = rank[nu[i]].min;
int y = rank[nu[i]].max;
if ((hall[x0].s <= x0) || (y > hall[x0].s)) {
int m = lps.skipNonNullElementsLeft(hall[hall[i].newBound].bounds - 1);
GECODE_ME_CHECK(x[nu[i]].lq(home, m));
}
}
return ES_OK;
}
template<class Card>
forceinline ExecStatus
Bnd<Card>::ubc(Space& home, int& nb,
HallInfo hall[], Rank rank[], int mu[], int nu[]) {
int rightmost = nb + 1; // rightmost accesible value in bounds
int bsize = nb + 2; // number of unique bounds including sentinels
//Narrow lower bounds (UBC)
/*
* Initializing tree structure with the values from bounds
* and the interval capacities of neighboured values
* from left to right
*/
hall[0].h = 0;
hall[0].t = 0;
hall[0].d = 0;
for (int i = bsize; --i; ) {
hall[i].h = hall[i].t = i-1;
hall[i].d = ups.sumup(hall[i-1].bounds, hall[i].bounds - 1);
}
int n = x.size();
for (int i = 0; i < n; i++) {
// visit intervals in increasing max order
int x0 = rank[mu[i]].min;
int succ = x0 + 1;
int y = rank[mu[i]].max;
int z = pathmax_t(hall, succ);
int j = hall[z].t;
/* DOMINATION:
* v^i_j denotes
* unused values in the current interval. If the difference d
* between to critical capacities v^i_j and v^i_z
* is equal to zero, j dominates z
*
* i.e. [hall[l].bounds, hall[nb+1].bounds] is not left-maximal and
* [hall[j].bounds, hall[l].bounds] is a Hall set iff
* [hall[j].bounds, hall[l].bounds] processing a variable x_i uses up a value in the interval
* [hall[z].bounds,hall[z+1].bounds] according to the intervals
* capacity. Therefore, if d = 0
* the considered value has already been used by processed variables
* m-times, where m = u[i] for value v_i. Since this value must not
* be reconsidered the path can be compressed
*/
if (--hall[z].d == 0) {
hall[z].t = z + 1;
z = pathmax_t(hall, hall[z].t);
if (z >= bsize)
z--;
hall[z].t = j;
}
pathset_t(hall, succ, z, z); // path compression
/* NEGATIVE CAPACITY:
* A negative capacity results in a failure.Since a
* negative capacity signals that the number of variables
* whose domain is contained in the set S is larger than
* the maximum capacity of S => UBC is not satisfiable,
* i.e. there are more variables than values to instantiate them
*/
if (hall[z].d < ups.sumup(hall[y].bounds, hall[z].bounds - 1))
return ES_FAILED;
/* UPDATING LOWER BOUND:
* If the lower bound min_i lies inside a Hall interval [a,b]
* i.e. a <= min_i <=b <= max_i
* min_i is set to min_i := b+1
*/
if (hall[x0].h > x0) {
int w = pathmax_h(hall, hall[x0].h);
int m = hall[w].bounds;
GECODE_ME_CHECK(x[mu[i]].gq(home, m));
pathset_h(hall, x0, w, w); // path compression
}
/* ZEROTEST:
* (using the difference between capacity pointers)
* zero capacity => the difference between critical capacity
* pointers is equal to the maximum capacity of the interval,i.e.
* the number of variables whose domain is contained in the
* interval is equal to the sum over all u[i] for a value v_i that
* lies in the Hall-Intervall which can also be thought of as a
* Hall-Set
*
* ZeroTestLemma: Let k and l be succesive critical indices.
* v^i_k=0 => v^i_k = max_i+1-l+d
* <=> v^i_k = y + 1 - z + d
* <=> d = z-1-y
* if this equation holds the interval [j,z-1] is a hall intervall
*/
if (hall[z].d == ups.sumup(hall[y].bounds, hall[z].bounds - 1)) {
/*
*mark hall interval [j,z-1]
* hall pointers form a path to the upper bound of the interval
*/
int predj = j - 1;
pathset_h(hall, hall[y].h, predj, y);
hall[y].h = predj;
}
}
/* Narrow upper bounds (UBC)
* symmetric to the narrowing of the lower bounds
*/
for (int i = 0; i < rightmost; i++) {
hall[i].h = hall[i].t = i+1;
hall[i].d = ups.sumup(hall[i].bounds, hall[i+1].bounds - 1);
}
for (int i = n; i--; ) {
// visit intervals in decreasing min order
int x0 = rank[nu[i]].max;
int pred = x0 - 1;
int y = rank[nu[i]].min;
int z = pathmin_t(hall, pred);
int j = hall[z].t;
// DOMINATION:
if (--hall[z].d == 0) {
hall[z].t = z - 1;
z = pathmin_t(hall, hall[z].t);
hall[z].t = j;
}
pathset_t(hall, pred, z, z);
// NEGATIVE CAPACITY:
if (hall[z].d < ups.sumup(hall[z].bounds,hall[y].bounds-1))
return ES_FAILED;
/* UPDATING UPPER BOUND:
* If the upper bound max_i lies inside a Hall interval [a,b]
* i.e. min_i <= a <= max_i < b
* max_i is set to max_i := a-1
*/
if (hall[x0].h < x0) {
int w = pathmin_h(hall, hall[x0].h);
int m = hall[w].bounds - 1;
GECODE_ME_CHECK(x[nu[i]].lq(home, m));
pathset_h(hall, x0, w, w);
}
// ZEROTEST
if (hall[z].d == ups.sumup(hall[z].bounds, hall[y].bounds - 1)) {
//mark hall interval [y,j]
pathset_h(hall, hall[y].h, j+1, y);
hall[y].h = j+1;
}
}
return ES_OK;
}
template<class Card>
ExecStatus
Bnd<Card>::pruneCards(Space& home) {
// Remove all values with 0 max occurrence
// and remove corresponding occurrence variables from k
// The number of zeroes
int n_z = 0;
for (int i=k.size(); i--;)
if (k[i].max() == 0)
n_z++;
if (n_z > 0) {
Region r;
int* z = r.alloc<int>(n_z);
n_z = 0;
int n_k = 0;
for (int i=0; i<k.size(); i++)
if (k[i].max() == 0) {
z[n_z++] = k[i].card();
} else {
k[n_k++] = k[i];
}
k.size(n_k);
Support::quicksort(z,n_z);
for (int i=x.size(); i--;) {
Iter::Values::Array zi(z,n_z);
GECODE_ME_CHECK(x[i].minus_v(home,zi,false));
}
lps.reinit(); ups.reinit();
}
return ES_OK;
}
template<class Card>
ExecStatus
Bnd<Card>::propagate(Space& home, const ModEventDelta& med) {
if (IntView::me(med) == ME_INT_VAL) {
GECODE_ES_CHECK(prop_val<Card>(home,*this,y,k));
return home.ES_NOFIX_PARTIAL(*this,IntView::med(ME_INT_BND));
}
if (Card::propagate)
GECODE_ES_CHECK(pruneCards(home));
Region r;
int* count = r.alloc<int>(k.size());
for (int i = k.size(); i--; )
count[i] = 0;
bool all_assigned = true;
int noa = 0;
for (int i = x.size(); i--; ) {
if (x[i].assigned()) {
noa++;
int idx;
// reduction is essential for order on value nodes in dom
// hence introduce test for failed lookup
if (!lookupValue(k,x[i].val(),idx))
return ES_FAILED;
count[idx]++;
} else {
all_assigned = false;
// We only need the counts in the view case or when all
// x are assigned
if (!Card::propagate)
break;
}
}
if (Card::propagate) {
// before propagation performs inferences on cardinality variables:
if (noa > 0)
for (int i = k.size(); i--; )
if (!k[i].assigned()) {
GECODE_ME_CHECK(k[i].lq(home, x.size() - (noa - count[i])));
GECODE_ME_CHECK(k[i].gq(home, count[i]));
}
if (!card_consistent<Card>(x, k))
return ES_FAILED;
GECODE_ES_CHECK(prop_card<Card>(home, x, k));
// Cardinalities may have been modified, so recompute
// count and all_assigned
for (int i = k.size(); i--; )
count[i] = 0;
all_assigned = true;
for (int i = x.size(); i--; ) {
if (x[i].assigned()) {
int idx;
// reduction is essential for order on value nodes in dom
// hence introduce test for failed lookup
if (!lookupValue(k,x[i].val(),idx))
return ES_FAILED;
count[idx]++;
} else {
// We won't need the remaining counts, they're only used when
// all x are assigned
all_assigned = false;
break;
}
}
}
if (all_assigned) {
for (int i = k.size(); i--; )
GECODE_ME_CHECK(k[i].eq(home, count[i]));
return home.ES_SUBSUMED(*this);
}
if (Card::propagate)
GECODE_ES_CHECK(pruneCards(home));
int n = x.size();
int* mu = r.alloc<int>(n);
int* nu = r.alloc<int>(n);
for (int i = n; i--; )
nu[i] = mu[i] = i;
// Create sorting permutation mu according to the variables upper bounds
MaxInc<IntView> max_inc(x);
Support::quicksort<int, MaxInc<IntView> >(mu, n, max_inc);
// Create sorting permutation nu according to the variables lower bounds
MinInc<IntView> min_inc(x);
Support::quicksort<int, MinInc<IntView> >(nu, n, min_inc);
// Sort the cardinality bounds by index
MinIdx<Card> min_idx;
Support::quicksort<Card, MinIdx<Card> >(&k[0], k.size(), min_idx);
if (!lps) {
assert(!ups);
lps.init(home, k, false);
ups.init(home, k, true);
} else if (Card::propagate) {
// if there has been a change to the cardinality variables
// reconstruction of the partial sum structure is necessary
if (lps.check_update_min(k))
lps.init(home, k, false);
if (ups.check_update_max(k))
ups.init(home, k, true);
}
// assert that the minimal value of the partial sum structure for
// LBC is consistent with the smallest value a variable can take
assert(lps.minValue() <= x[nu[0]].min());
// assert that the maximal value of the partial sum structure for
// UBC is consistent with the largest value a variable can take
/*
* Setup rank and bounds info
* Since this implementation is based on the theory of Hall Intervals
* additional datastructures are needed in order to represent these
* intervals and the "partial-sum" data structure (cf."gcc/bnd-sup.hpp")
*
*/
HallInfo* hall = r.alloc<HallInfo>(2 * n + 2);
Rank* rank = r.alloc<Rank>(n);
int nb = 0;
// setup bounds and rank
int min = x[nu[0]].min();
int max = x[mu[0]].max() + 1;
int last = lps.firstValue + 1; //equivalent to last = min -2
hall[0].bounds = last;
/*
* First the algorithm merges the arrays minsorted and maxsorted
* into bounds i.e. hall[].bounds contains the ordered union
* of the lower and upper domain bounds including two sentinels
* at the beginning and at the end of the set
* ( the upper variable bounds in this union are increased by 1 )
*/
{
int i = 0;
int j = 0;
while (true) {
if (i < n && min < max) {
if (min != last) {
last = min;
hall[++nb].bounds = last;
}
rank[nu[i]].min = nb;
if (++i < n)
min = x[nu[i]].min();
} else {
if (max != last) {
last = max;
hall[++nb].bounds = last;
}
rank[mu[j]].max = nb;
if (++j == n)
break;
max = x[mu[j]].max() + 1;
}
}
}
int rightmost = nb + 1; // rightmost accesible value in bounds
hall[rightmost].bounds = ups.lastValue + 1 ;
if (Card::propagate) {
skip_lbc = true;
for (int i = k.size(); i--; )
if (k[i].min() != 0) {
skip_lbc = false;
break;
}
}
if (!card_fixed && !skip_lbc)
GECODE_ES_CHECK((lbc(home, nb, hall, rank, mu, nu)));
GECODE_ES_CHECK((ubc(home, nb, hall, rank, mu, nu)));
if (Card::propagate)
GECODE_ES_CHECK(prop_card<Card>(home, x, k));
for (int i = k.size(); i--; )
count[i] = 0;
for (int i = x.size(); i--; )
if (x[i].assigned()) {
int idx;
if (!lookupValue(k,x[i].val(),idx))
return ES_FAILED;
count[idx]++;
} else {
// We won't need the remaining counts, they're only used when
// all x are assigned
return ES_NOFIX;
}
for (int i = k.size(); i--; )
GECODE_ME_CHECK(k[i].eq(home, count[i]));
return home.ES_SUBSUMED(*this);
}
template<class Card>
ExecStatus
Bnd<Card>::post(Home home,
ViewArray<IntView>& x, ViewArray<Card>& k) {
bool cardfix = true;
for (int i=k.size(); i--; )
if (!k[i].assigned()) {
cardfix = false; break;
}
bool nolbc = true;
for (int i=k.size(); i--; )
if (k[i].min() != 0) {
nolbc = false; break;
}
GECODE_ES_CHECK(postSideConstraints<Card>(home, x, k));
if (isDistinct<Card>(x,k))
return Distinct::Bnd<IntView>::post(home,x);
(void) new (home) Bnd<Card>(home,x,k,cardfix,nolbc);
return ES_OK;
}
}}}
// STATISTICS: int-prop
Gecode::Actor
Base-class for both propagators and branchers.
Definition core.hpp:628
Gecode::Actor::dispose
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition core.hpp:3252
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::Int::Distinct::Bnd::post
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator for view array x.
Definition bnd.hpp:476
Gecode::Int::GCC::Bnd::ups
PartialSum< Card > ups
Data structure storing the sum of the views upper bounds.
Definition gcc.hh:128
Gecode::Int::GCC::Bnd::Bnd
Bnd(Space &home, Bnd< Card > &p)
Constructor for cloning p.
Definition bnd.hpp:56
Gecode::Int::GCC::Bnd::skip_lbc
bool skip_lbc
Stores whether the minium required occurences of the cardinalities are all zero. If so,...
Definition gcc.hh:141
Gecode::Int::GCC::Bnd::post
static ExecStatus post(Home home, ViewArray< IntView > &x, ViewArray< Card > &k)
Post propagator for views x and cardinalities k.
Definition bnd.hpp:808
Gecode::Int::GCC::Bnd::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition bnd.hpp:75
Gecode::Int::GCC::Bnd::k
ViewArray< Card > k
Array containing either fixed cardinalities or CardViews.
Definition gcc.hh:120
Gecode::Int::GCC::Bnd::ubc
ExecStatus ubc(Space &home, int &nb, HallInfo hall[], Rank rank[], int mu[], int nu[])
Upper Bounds constraint (UBC) stating Hence the ubc constraints the variables such that no value oc...
Definition bnd.hpp:404
Gecode::Int::GCC::Bnd::pruneCards
ExecStatus pruneCards(Space &home)
Prune cardinality variables with 0 maximum occurrence.
Definition bnd.hpp:562
Gecode::Int::GCC::Bnd::card_fixed
bool card_fixed
Stores whether cardinalities are all assigned.
Definition gcc.hh:135
Gecode::Int::GCC::Bnd::y
ViewArray< IntView > y
Views on which to perform value-propagation (subset of x).
Definition gcc.hh:118
Gecode::Int::GCC::Bnd::dispose
virtual size_t dispose(Space &home)
Destructor.
Definition bnd.hpp:66
Gecode::Int::GCC::Bnd::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition bnd.hpp:596
Gecode::Int::GCC::Bnd::reschedule
virtual void reschedule(Space &home)
Schedule function.
Definition bnd.hpp:93
Gecode::Int::GCC::Bnd::x
ViewArray< IntView > x
Views on which to perform bounds-propagation.
Definition gcc.hh:116
Gecode::Int::GCC::Bnd::lps
PartialSum< Card > lps
Data structure storing the sum of the views lower bounds Necessary for reasoning about the interval c...
Definition gcc.hh:126
Gecode::Int::GCC::Bnd::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost funtion.
Definition bnd.hpp:81
Gecode::Int::GCC::Bnd::lbc
ExecStatus lbc(Space &home, int &nb, HallInfo hall[], Rank rank[], int mu[], int nu[])
Lower Bounds constraint (LBC) stating Hence the lbc constraints the variables such that every value...
Definition bnd.hpp:100
Gecode::Int::GCC::HallInfo
Container class provding information about the Hall structure of the problem variables.
Definition bnd-sup.hpp:456
Gecode::Int::GCC::HallInfo::t
int t
Critical capacity pointer t represents a predecessor function where denotes the predecessor of i in ...
Definition bnd-sup.hpp:465
Gecode::Int::GCC::HallInfo::newBound
int newBound
Bound update.
Definition bnd-sup.hpp:493
Gecode::Int::GCC::HallInfo::h
int h
Hall set pointer.
Definition bnd-sup.hpp:482
Gecode::Int::GCC::HallInfo::bounds
int bounds
Represents the union of all lower and upper domain bounds.
Definition bnd-sup.hpp:459
Gecode::Int::GCC::HallInfo::s
int s
Stable Set pointer.
Definition bnd-sup.hpp:484
Gecode::Int::GCC::HallInfo::ps
int ps
Potentially Stable Set pointer.
Definition bnd-sup.hpp:486
Gecode::Int::GCC::HallInfo::d
int d
Difference between critical capacities.
Definition bnd-sup.hpp:473
Gecode::Int::GCC::MaxInc
Compares two indices i, j of two views according to the ascending order of the views upper bounds.
Definition bnd-sup.hpp:176
Gecode::Int::GCC::MinIdx
Compares two cardinality views according to the index.
Definition bnd-sup.hpp:221
Gecode::Int::GCC::MinInc
Compares two indices i, j of two views according to the ascending order of the views lower bounds.
Definition bnd-sup.hpp:199
Gecode::Int::GCC::Rank
Maps domain bounds to their position in hall[].bounds.
Definition bnd-sup.hpp:154
Gecode::Int::GCC::Rank::min
int min
Definition bnd-sup.hpp:160
Gecode::Int::GCC::Rank::max
int max
Definition bnd-sup.hpp:165
Gecode::Int::IntView::med
int med(void) const
Return median of domain (greatest element not greater than the median).
Definition int.hpp:66
Gecode::Iter::Values::Array
Value iterator for array of integers
Definition values-array.hpp:46
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::linear
static PropCost linear(PropCost::Mod m, unsigned int n)
Linear complexity for modifier pcm and size measure n.
Definition core.hpp:4796
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::Propagator::Propagator
Propagator(Home home)
Constructor for posting.
Definition core.hpp:3498
Gecode::Region
Handle to region.
Definition region.hpp:55
Gecode::VarImpView< IntVar >::me
static ModEvent me(const ModEventDelta &med)
Definition view.hpp:552
Gecode::ViewArray
View arrays.
Definition array.hpp:253
Gecode::Int::GCC::card_consistent
bool card_consistent(ViewArray< IntView > &x, ViewArray< Card > &k)
Consistency check, whether the cardinality values are feasible.
Definition bnd-sup.hpp:139
Gecode::Int::GCC::prop_card
ExecStatus prop_card(Space &home, ViewArray< IntView > &x, ViewArray< Card > &k)
Bounds consistency check for cardinality variables.
Definition bnd-sup.hpp:74
Gecode::Space::ES_NOFIX_PARTIAL
ExecStatus ES_NOFIX_PARTIAL(Propagator &p, const ModEventDelta &med)
Propagator p has not computed partial fixpoint
Definition core.hpp:3576
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::Int::GCC
Global cardinality propagators (Counting).
Gecode::Int::GCC::pathmin_h
int pathmin_h(const HallInfo hall[], int i)
Path minimum for hall pointer structure.
Definition bnd-sup.hpp:549
Gecode::Int::GCC::pathmax_t
int pathmax_t(const HallInfo hall[], int i)
Path maximum for capacity pointer structure.
Definition bnd-sup.hpp:579
Gecode::Int::GCC::pathset_ps
void pathset_ps(HallInfo hall[], int start, int end, int to)
Path compression for potentially stable set structure.
Definition bnd-sup.hpp:507
Gecode::Int::GCC::isDistinct
bool isDistinct(ViewArray< IntView > &x, ViewArray< Card > &k)
Check if GCC is equivalent to distinct.
Definition post.hpp:138
Gecode::Int::GCC::pathmax_s
int pathmax_s(const HallInfo hall[], int i)
Path maximum for stable set pointer structure.
Definition bnd-sup.hpp:587
Gecode::Int::GCC::pathset_t
void pathset_t(HallInfo hall[], int start, int end, int to)
Path compression for capacity pointer structure.
Definition bnd-sup.hpp:523
Gecode::Int::GCC::prop_val
ExecStatus prop_val(Space &home, Propagator &p, ViewArray< IntView > &x, ViewArray< Card > &k)
Definition val.hpp:92
Gecode::Int::GCC::pathmin_t
int pathmin_t(const HallInfo hall[], int i)
Path minimum for capacity pointer structure.
Definition bnd-sup.hpp:556
Gecode::Int::GCC::pathset_h
void pathset_h(HallInfo hall[], int start, int end, int to)
Path compression for hall pointer structure.
Definition bnd-sup.hpp:531
Gecode::Int::GCC::pathset_s
void pathset_s(HallInfo hall[], int start, int end, int to)
Path compression for stable set structure.
Definition bnd-sup.hpp:515
Gecode::Int::GCC::lookupValue
bool lookupValue(T &a, int v, int &i)
Return index of v in array a.
Definition view.hpp:45
Gecode::Int::GCC::pathmax_h
int pathmax_h(const HallInfo hall[], int i)
Path maximum for hall pointer structure.
Definition bnd-sup.hpp:572
Gecode::Int::GCC::postSideConstraints
ExecStatus postSideConstraints(Home home, ViewArray< IntView > &x, ViewArray< Card > &k)
Post side constraints for the GCC.
Definition post.hpp:60
Gecode::Int::GCC::pathmax_ps
int pathmax_ps(const HallInfo hall[], int i)
Path maximum for potentially stable set pointer structure.
Definition bnd-sup.hpp:594
Gecode::Int
Finite domain integers.
Gecode::Int::ME_INT_BND
const Gecode::ModEvent ME_INT_BND
Domain operation has changed the minimum or maximum of the domain.
Definition var-type.hpp:65
Gecode::Int::PC_INT_BND
const Gecode::PropCond PC_INT_BND
Propagate when minimum or maximum of a view changes.
Definition var-type.hpp:91
Gecode::Int::ME_INT_VAL
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable).
Definition var-type.hpp:56
Gecode::Support::quicksort
void quicksort(Type *l, Type *r, Less &less)
Standard quick sort.
Definition sort.hpp:130
Gecode
Gecode toplevel namespace
Gecode::count
void count(Home home, const IntVarArgs &x, int n, IntRelType irt, int m, IntPropLevel ipl=IPL_DEF)
Post propagator for .
Definition count.cpp:40
Gecode::min
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition arithmetic.cpp:67
Gecode::ExecStatus
ExecStatus
Definition core.hpp:472
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition core.hpp:476
Gecode::ES_FAILED
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:474
Gecode::ES_NOFIX
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition core.hpp:475
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition arithmetic.cpp:49
forceinline
#define forceinline
Definition config.hpp:187