Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions changelog.in
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,46 @@ Rank: minor
Define the GECODE_FREELIST32_SIZE_MAX and GECODE_FREELIST64_SIZE_MAX build
options as numbers in config.hpp. A quoted value broke compilation.

[ENTRY]
Module: int
What: bug
Rank: minor
[DESCRIPTION]
Post nothing for no_overlap with zero rectangles. Debug builds aborted with a
failed assertion in the memory manager.

[ENTRY]
Module: int
What: bug
Rank: minor
[DESCRIPTION]
Decide count with an array of counts (global cardinality) and bin_packing
with no variables or items when posting: every count and load becomes 0.
Count with variables but no values fails. Branching with LDSB symmetries,
for integer, Boolean, and set variables, ignores symmetries over no
variables or values and accepts an empty Symmetries. Debug builds aborted
with failed assertions. Distinct over an open list with maximum length 0
also posts nothing.

[ENTRY]
Module: set
What: bug
Rank: minor
[DESCRIPTION]
Post nothing for channel_sorted, channel with Boolean variables, and union
or disjoint-union element over constant sets when the array is empty, and
make the set variables empty. Debug builds aborted with failed assertions.
Element over set variables, rel with union or disjoint union and a constant
set, and weights also post nothing for empty arrays.

[ENTRY]
Module: search
What: bug
Rank: minor
[DESCRIPTION]
Post nothing for relax with empty variable arrays. Debug builds aborted with
a failed assertion.

[ENTRY]
Module: other
What: performance
Expand Down
28 changes: 16 additions & 12 deletions gecode/float/linear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,27 @@ namespace Gecode {
using namespace Float;
GECODE_POST;
Region re;
Linear::Term* t = re.alloc<Linear::Term>(x.size());
for (int i = x.size(); i--;) {
int n = x.size();
Linear::Term* t = (n > 0) ? re.alloc<Linear::Term>(n) : nullptr;
for (int i = 0; i < n; i++) {
t[i].a = 1.0;
t[i].x = x[i];
}
Linear::post(home, t, x.size(), frt, c);
Linear::post(home, t, n, frt, c);
}

void
linear(Home home, const FloatVarArgs& x, FloatRelType frt, FloatVal c, Reify r) {
using namespace Float;
GECODE_POST;
Region re;
Linear::Term* t = re.alloc<Linear::Term>(x.size());
for (int i = x.size(); i--;) {
int n = x.size();
Linear::Term* t = (n > 0) ? re.alloc<Linear::Term>(n) : nullptr;
for (int i = 0; i < n; i++) {
t[i].a = 1.0;
t[i].x = x[i];
}
Linear::post(home, t, x.size(), frt, c, r);
Linear::post(home, t, n, frt, c, r);
}

void
Expand All @@ -69,12 +71,13 @@ namespace Gecode {
throw ArgumentSizeMismatch("Float::linear");
GECODE_POST;
Region re;
Linear::Term* t = re.alloc<Linear::Term>(x.size());
for (int i = x.size(); i--;) {
int n = x.size();
Linear::Term* t = (n > 0) ? re.alloc<Linear::Term>(n) : nullptr;
for (int i = 0; i < n; i++) {
t[i].a = a[i];
t[i].x = x[i];
}
Linear::post(home, t, x.size(), frt, c);
Linear::post(home, t, n, frt, c);
}

void
Expand All @@ -84,12 +87,13 @@ namespace Gecode {
throw ArgumentSizeMismatch("Float::linear");
GECODE_POST;
Region re;
Linear::Term* t = re.alloc<Linear::Term>(x.size());
for (int i = x.size(); i--;) {
int n = x.size();
Linear::Term* t = (n > 0) ? re.alloc<Linear::Term>(n) : nullptr;
for (int i = 0; i < n; i++) {
t[i].a = a[i];
t[i].x = x[i];
}
Linear::post(home, t, x.size(), frt, c, r);
Linear::post(home, t, n, frt, c, r);
}

void
Expand Down
2 changes: 2 additions & 0 deletions gecode/float/relax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ namespace Gecode {
throw Float::ArgumentSizeMismatch("Float::relax");
if ((p < 0.0) || (p > 1.0))
throw Float::OutOfLimits("Float::relax");
if (x.size() == 0)
return;
Float::Relax fr;
Search::relax<FloatVarArgs, Float::Relax>(home, x, sx, r, p, fr);
}
Expand Down
4 changes: 4 additions & 0 deletions gecode/int/bin-packing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ namespace Gecode {
}
}

// Without items there are no conflicts
if (n == 0)
return IntSet::empty;

// Clique Finding and distinct posting
{
// First construct the conflict graph
Expand Down
3 changes: 2 additions & 1 deletion gecode/int/bin-packing/propagate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ namespace Gecode { namespace Int { namespace BinPacking {
ExecStatus
Pack::post(Home home, ViewArray<OffsetView>& l, ViewArray<Item>& bs, IntPropLevel ipl) {
// Sort according to size
Support::quicksort(&bs[0], bs.size());
if (bs.size() > 0)
Support::quicksort(&bs[0], bs.size());
// Total size of items
int s = 0;
// Constrain bins
Expand Down
4 changes: 4 additions & 0 deletions gecode/int/distinct/open.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ namespace Gecode { namespace Int { namespace Distinct {
x.subscribe(home, *this, PC_INT_VAL, false);
}
processed = size;
if (active_count == 0)
return closed() ? home.ES_SUBSUMED(*this) : ES_FIX;

Region region;
const int capacity = active_count;
Expand Down Expand Up @@ -190,6 +192,8 @@ namespace Gecode { namespace Int { namespace Distinct {

static void
post(Home home, OpenViewList<View> list) {
if (list.length().max() == 0)
return;
(void)new (home) Open(home, list);
}
};
Expand Down
27 changes: 27 additions & 0 deletions gecode/int/gcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ namespace Gecode {

GECODE_POST;

if (x.size() == 0) {
// Without variables, every value occurs zero times
for (int i = 0; i < c.size(); i++)
GECODE_ME_FAIL(IntView(c[i]).eq(home, 0));
return;
}
if (v.size() == 0) {
// No value is allowed for the variables
home.fail();
return;
}

remove_duplicates(home, c, v);

ViewArray<IntView> xv(home, x);
Expand Down Expand Up @@ -156,6 +168,21 @@ namespace Gecode {

GECODE_POST;

if (x.size() == 0) {
// Without variables, every value occurs zero times
for (int i = 0; i < c.size(); i++)
if (!c[i].in(0)) {
home.fail();
return;
}
return;
}
if (v.size() == 0) {
// No value is allowed for the variables
home.fail();
return;
}

remove_duplicates(home, c, v);

ViewArray<IntView> xv(home, x);
Expand Down
65 changes: 45 additions & 20 deletions gecode/int/ldsb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ namespace Gecode { namespace Int { namespace LDSB {
return std::pair<int, int>(-1, -1);
}

bool
is_empty(const SymmetryHandle& s) {
if (VariableSymmetryObject* varref = dynamic_cast<VariableSymmetryObject*>(s.ref))
return varref->nxs == 0;
if (ValueSymmetryObject* valref = dynamic_cast<ValueSymmetryObject*>(s.ref))
return valref->values.size() == 0;
if (VariableSequenceSymmetryObject* varseqref = dynamic_cast<VariableSequenceSymmetryObject*>(s.ref))
return varseqref->nxs == 0;
if (ValueSequenceSymmetryObject* valseqref = dynamic_cast<ValueSequenceSymmetryObject*>(s.ref))
return valseqref->values.size() == 0;
return false;
}

}}} // namespace Gecode::Int::LDSB

namespace Gecode {
Expand Down Expand Up @@ -242,6 +255,30 @@ namespace Gecode { namespace Int { namespace LDSB {
GECODE_NEVER;
return nullptr;
}

/**
* \brief Create implementations of the non-empty symmetries in \a syms
*
* Each implementation is created by \a create_sym. Stores their number
* in \a nsyms and returns nullptr if there are none.
*/
template <class View>
SymmetryImp<View>**
create_syms(Space& home, const Symmetries& syms, const VariableMap& variable_map,
SymmetryImp<View>* (*create_sym)(Space&, const SymmetryHandle&, VariableMap), int& nsyms) {
nsyms = 0;
for (int i = 0; i < syms.size(); i++)
if (!is_empty(syms[i]))
nsyms++;
if (nsyms == 0)
return nullptr;
SymmetryImp<View>** array = home.alloc<SymmetryImp<View>*>(nsyms);
int created = 0;
for (int i = 0; i < syms.size(); i++)
if (!is_empty(syms[i]))
array[created++] = create_sym(home, syms[i], variable_map);
return array;
}
}}} // namespace Gecode::Int::LDSB

namespace Gecode {
Expand Down Expand Up @@ -281,11 +318,8 @@ namespace Gecode {

// Convert the modelling-level Symmetries object into an array of
// SymmetryImp objects.
int n = syms.size();
SymmetryImp<IntView>** array = static_cast<Space&>(home).alloc<SymmetryImp<IntView>*>(n);
for (int i = 0; i < n; i++) {
array[i] = create_int_sym(home, syms[i], variable_map);
}
int n = 0;
SymmetryImp<IntView>** array = create_syms(home, syms, variable_map, create_int_sym, n);

post_ldsb_brancher<IntView, 1, int, 2>(home, xv, vs, Branch::value_selection_commit(home, vals), array, n,
bf, vvp);
Expand Down Expand Up @@ -319,11 +353,8 @@ namespace Gecode {

// Convert the modelling-level Symmetries object into an array of
// SymmetryImp objects.
int n = syms.size();
SymmetryImp<IntView>** array = static_cast<Space&>(home).alloc<SymmetryImp<IntView>*>(n);
for (int i = 0; i < n; i++) {
array[i] = create_int_sym(home, syms[i], variable_map);
}
int n = 0;
SymmetryImp<IntView>** array = create_syms(home, syms, variable_map, create_int_sym, n);

ViewArray<IntView> xv(home, x);
if (vars.c.select() == IntVarBranch::SEL_NONE) {
Expand Down Expand Up @@ -413,11 +444,8 @@ namespace Gecode {

// Convert the modelling-level Symmetries object into an array of
// SymmetryImp objects.
int n = syms.size();
SymmetryImp<BoolView>** array = static_cast<Space&>(home).alloc<SymmetryImp<BoolView>*>(n);
for (int i = 0; i < n; i++) {
array[i] = create_bool_sym(home, syms[i], variable_map);
}
int n = 0;
SymmetryImp<BoolView>** array = create_syms(home, syms, variable_map, create_bool_sym, n);

// Technically these "bad" value selection could in fact work with
// LDSB, because they degenerate to binary splitting for
Expand Down Expand Up @@ -463,11 +491,8 @@ namespace Gecode {

// Convert the modelling-level Symmetries object into an array of
// SymmetryImp objects.
int n = syms.size();
SymmetryImp<BoolView>** array = static_cast<Space&>(home).alloc<SymmetryImp<BoolView>*>(n);
for (int i = 0; i < n; i++) {
array[i] = create_bool_sym(home, syms[i], variable_map);
}
int n = 0;
SymmetryImp<BoolView>** array = create_syms(home, syms, variable_map, create_bool_sym, n);

// Technically these "bad" value selection could in fact work with
// LDSB, because they degenerate to binary splitting for
Expand Down
11 changes: 10 additions & 1 deletion gecode/int/ldsb.hh
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ namespace Gecode { namespace Int { namespace LDSB {
ValueSequenceSymmetryObject(IntArgs vs, int ss);
};

/**
* \brief Test whether the symmetry \a s describes neither variables nor
* values
*
* Such a symmetry maps nothing, so branching ignores it. The test does
* not allocate.
*/
GECODE_INT_EXPORT bool is_empty(const SymmetryHandle& s);

/// Implementation of a single symmetry.
template <class View>
class SymmetryImp {
Expand Down Expand Up @@ -331,7 +340,7 @@ namespace Gecode { namespace Int { namespace LDSB {
class LDSBBrancher : public ViewValBrancher<View, n, Val, a, Filter, Print> {
public:
using typename ViewValBrancher<View, n, Val, a, Filter, Print>::Var;
/// Array of symmetry implementations
/// Array of symmetry implementations, nullptr when \a _nsyms is 0
SymmetryImp<View>** _syms;
/// Number of symmetry implementations
int _nsyms;
Expand Down
10 changes: 7 additions & 3 deletions gecode/int/ldsb/brancher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ namespace Gecode { namespace Int { namespace LDSB {
LDSBBrancher<View, n, Val, a, Filter, Print>::LDSBBrancher(Space& home,
LDSBBrancher<View, n, Val, a, Filter, Print>& b)
: ViewValBrancher<View, n, Val, a, Filter, Print>(home, b), _nsyms(b._nsyms), _prev_pos(b._prev_pos) {
_syms = home.alloc<SymmetryImp<View>*>(_nsyms);
for (int i = 0; i < _nsyms; i++)
_syms[i] = b._syms[i]->copy(home);
if (_nsyms > 0) {
_syms = home.alloc<SymmetryImp<View>*>(_nsyms);
for (int i = 0; i < _nsyms; i++)
_syms[i] = b._syms[i]->copy(home);
} else {
_syms = nullptr;
}
}

template <class View, int n, class Val, unsigned int a, class Filter, class Print>
Expand Down
Loading
Loading