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
10 changes: 9 additions & 1 deletion .github/ci/generated-source-freshness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,17 @@ generated_files=(
gecode/flatzinc/lexer.yy.cpp
)

# Flex builds number the #line directives that name the output file itself
# differently: Debian's count one line further than Homebrew's. Those numbers
# carry no meaning, so the comparison ignores them.
without_output_line_numbers() {
sed -E 's|^#line [0-9]+ "gecode/flatzinc/lexer\.yy\.cpp"$|#line "gecode/flatzinc/lexer.yy.cpp"|' "$1"
}

stale=0
for file in "${generated_files[@]}"; do
if cmp -s "$repo_root/$file" "$source_copy/$file"; then
if cmp -s <(without_output_line_numbers "$repo_root/$file") \
<(without_output_line_numbers "$source_copy/$file"); then
continue
fi
if [ "$mode" = update ]; then
Expand Down
4 changes: 2 additions & 2 deletions .github/ci/qt-gist-consumer-smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ cat > "$work/main.cpp" <<'EOF'
#include <string>

#ifdef GECODE_HAS_SET_VARS
using SetCompare = std::string (*)(std::string, Gecode::SetVar, Gecode::SetVar);
using SetCompare = std::string (*)(const std::string&, Gecode::SetVar, Gecode::SetVar);
SetCompare set_compare = &Gecode::Gist::Comparator::compare;
#endif

#ifdef GECODE_HAS_FLOAT_VARS
using FloatCompare = std::string (*)(std::string, Gecode::FloatVar, Gecode::FloatVar);
using FloatCompare = std::string (*)(const std::string&, Gecode::FloatVar, Gecode::FloatVar);
FloatCompare float_compare = &Gecode::Gist::Comparator::compare;
#endif

Expand Down
4 changes: 2 additions & 2 deletions .github/ci/qt5-gist-consumer-smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ cat > "$work/main.cpp" <<'EOF'
#include <string>

#ifdef GECODE_HAS_SET_VARS
using SetCompare = std::string (*)(std::string, Gecode::SetVar, Gecode::SetVar);
using SetCompare = std::string (*)(const std::string&, Gecode::SetVar, Gecode::SetVar);
SetCompare set_compare = &Gecode::Gist::Comparator::compare;
#endif

#ifdef GECODE_HAS_FLOAT_VARS
using FloatCompare = std::string (*)(std::string, Gecode::FloatVar, Gecode::FloatVar);
using FloatCompare = std::string (*)(const std::string&, Gecode::FloatVar, Gecode::FloatVar);
FloatCompare float_compare = &Gecode::Gist::Comparator::compare;
#endif

Expand Down
152 changes: 151 additions & 1 deletion changelog.in
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,146 @@ Date: unreleased
This release contains breaking changes. See the entries below for the
changes downstream code needs.

[ENTRY]
Module: kernel
What: change
Rank: minor
[DESCRIPTION]
The Rnd constructor taking a seed is explicit. Code that passes a number where
a Rnd is expected, such as INT_VAR_RND(1U), must now write Rnd(1U). The implicit
conversion also accepted floating-point values, which hid the bug in
IntBoolVarBranch fixed in this release.

[ENTRY]
Module: flatzinc
What: bug
Rank: minor
[DESCRIPTION]
IntBoolVarBranch keeps its decay factor, which was discarded so that AFC and
action used a decay of 1. The default branchers follow the -decay option, which
only search annotations honoured before.

[ENTRY]
Module: flatzinc
What: bug
Rank: minor
[DESCRIPTION]
Choices from set_search and set_default_search print the relations of their
value selection. Before, set_search printed none, and set_default_search printed
"in" and "not in" the wrong way round for outdomain_min and outdomain_max.

[ENTRY]
Module: flatzinc
What: bug
Rank: minor
[DESCRIPTION]
Searching for an extension to introduced variables follows the default search
annotations after the space has been cloned, and no longer leaks the random
number generator of a random selection.

[ENTRY]
Module: int
What: bug
Rank: minor
[DESCRIPTION]
The assign overloads for integer and Boolean variables with tie-breaking
variable selection link. The Boolean overload now takes BoolBranchFilter and
BoolVarValPrint arguments, as the overload without tie-breaking does.

[ENTRY]
Module: int
What: bug
Rank: minor
[DESCRIPTION]
Assigning integer and Boolean variables follows the variable selection, which
was ignored unless a tie-breaking selection was also in effect. Models that
pass a selection to assign, such as the job-shop example, now assign variables
in that order and can find different solutions first.

[ENTRY]
Module: set
What: bug
Rank: minor
[DESCRIPTION]
Assigning set variables follows the variable selection, which was ignored
unless a tie-breaking selection was also in effect.

[ENTRY]
Module: float
What: bug
Rank: minor
[DESCRIPTION]
Assigning float variables follows the variable selection, which was ignored
unless a tie-breaking selection was also in effect.

[ENTRY]
Module: int
What: bug
Rank: minor
[DESCRIPTION]
values_reflect for the domain of an integer variable links.

[ENTRY]
Module: set
What: bug
Rank: minor
[DESCRIPTION]
The default constructors of SetVarGlbValues, SetVarLubValues, and
SetVarUnknownValues link.

[ENTRY]
Module: float
What: bug
Rank: minor
[DESCRIPTION]
Constructing FloatValArgs from an initializer list links.

[ENTRY]
Module: search
What: bug
Rank: minor
[DESCRIPTION]
The declaration of the pbs engine builder takes the engine as a template
argument, as its definition does. Calling it with only the space type failed
to link and is now a compile error.

[ENTRY]
Module: int
What: bug
Rank: minor
[DESCRIPTION]
Multi-dimensional bin_packing throws Int::OutOfLimits for fewer than one
dimension. It divided by zero for zero dimensions, and a negative number of
dimensions now gives Int::OutOfLimits instead of Int::ArgumentSizeMismatch.

[ENTRY]
Module: int
What: bug
Rank: minor
[DESCRIPTION]
Two-dimensional element throws Int::TooFewArguments for an empty array, as
one-dimensional element does, instead of Int::VariableEmptyDomain from an
internal variable or Int::ArgumentSizeMismatch. It throws
Int::ArgumentSizeMismatch for a width or height that is not positive and when
the product overflows, where it could post a failing or wrong constraint.

[ENTRY]
Module: set
What: bug
Rank: minor
[DESCRIPTION]
Two-dimensional element throws Set::ArgumentSizeMismatch for a width or height
that is not positive and when the product overflows, where it could post a
failing or wrong constraint.

[ENTRY]
Module: set
What: documentation
Rank: minor
[DESCRIPTION]
Document the exceptions that sequence and element with an integer index throw
for an empty array and for sets outside the limits.

[ENTRY]
Module: kernel
What: change
Expand Down Expand Up @@ -150,6 +290,16 @@ constructor and its bool conversion.
Support::BitSetData::operator== is now defaulted and takes its argument by
const reference. Int::LDSB::Literal now also has ==, !=, <=, >, and >=.

[ENTRY]
Module: kernel
What: bug
Rank: minor
[DESCRIPTION]
Fix shrinking with Space::realloc and Region::realloc. The size of the removed
tail was computed with the wrong sign, so shrinking destroyed objects past the
block and handed memory outside it to the space. Space::realloc for pointers
also used the size of the pointed-to type, which lost pointers on growing.

[ENTRY]
Module: int
What: bug
Expand All @@ -171,7 +321,7 @@ GECODE_VERSION_NUMBER instead, or Gecode_VERSION from the CMake package.
[MORE]
CMake now generates config.hpp with configure_file. Feature macros that were
defined as empty, such as GECODE_HAS_FLOAT_VARS, are now defined as 1; tests
with #ifdef behave as before.
of whether they are defined behave as before.

[ENTRY]
Module: support
Expand Down
1 change: 1 addition & 0 deletions cmake/GecodeSources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ set(GECODE_TEST_SOURCES
test/flatzinc/blocksworld_instance_1.cpp
test/flatzinc/blocksworld_instance_2.cpp
test/flatzinc/bool_clause.cpp
test/flatzinc/branching.cpp
test/flatzinc/bug232.cpp
test/flatzinc/bug319.cpp
test/flatzinc/bugfix_r6746.cpp
Expand Down
7 changes: 7 additions & 0 deletions docs/cmake-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ cmake -S . -B build/asan-ubsan \
cmake --build build/asan-ubsan --target check
```

On macOS, `std::thread` stacks are 512 KiB, while the main thread has 8 MiB, and
the check targets run `gecode-test` on worker threads. In a Debug build with
AddressSanitizer, forced inlining gives some propagators a frame of about
400 KiB, so a test can overflow its worker stack. This is a limit of that build,
not unbounded recursion. Use an optimized sanitizer build, or run
`gecode-test -threads 1` on the main thread.

## Using Gecode From Other CMake Projects

### Recommended aggregate target
Expand Down
2 changes: 0 additions & 2 deletions examples/sudoku-instances.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1799,8 +1799,6 @@ namespace {
* 1 to 36. A file may contain several puzzles, one after the other;
* select one with \c -param \c instance=K. See Instance::Spec for the
* spec language.
*
* \relates Sudoku
*/
const char* instance_spec = R"(format sudoku

Expand Down
2 changes: 1 addition & 1 deletion gecode/flatzinc/branch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ namespace Gecode { namespace FlatZinc {

template <class Merit>
forceinline
IntBoolBrancher<Merit>::IntBoolBrancher(Space& home, IntBoolBrancher<Merit>& b)
IntBoolBrancher<Merit>::IntBoolBrancher(Space& home, IntBoolBrancher& b)
: IntBoolBrancherBase(home, b), merit(home, b.merit) {}

template <class Merit>
Expand Down
43 changes: 35 additions & 8 deletions gecode/flatzinc/flatzinc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,22 @@ namespace Gecode { namespace FlatZinc {
float_varsel(std::move(float_varsel0)), float_valsel(std::move(float_valsel0))
#endif
{
home.notice(*this, AP_DISPOSE);
}
/// Copy constructor
AuxVarBrancher(Space& home, AuxVarBrancher& b) : Brancher(home, b), done(b.done) {}
AuxVarBrancher(Space& home, AuxVarBrancher& b)
: Brancher(home, b), done(b.done), int_varsel(b.int_varsel), int_valsel(b.int_valsel),
bool_varsel(b.bool_varsel), bool_valsel(b.bool_valsel)
#ifdef GECODE_HAS_SET_VARS
,
set_varsel(b.set_varsel), set_valsel(b.set_valsel)
#endif
#ifdef GECODE_HAS_FLOAT_VARS
,
float_varsel(b.float_varsel), float_valsel(b.float_valsel)
#endif
{
}

/// %Choice that only signals failure or success
class Choice : public Gecode::Choice {
Expand Down Expand Up @@ -269,7 +282,21 @@ namespace Gecode { namespace FlatZinc {
}
/// Delete brancher and return its size
size_t
dispose(Space&) override {
dispose(Space& home) override {
home.ignore(*this, AP_DISPOSE);
int_varsel.~TieBreak();
int_valsel.~IntValBranch();
bool_varsel.~TieBreak();
bool_valsel.~BoolValBranch();
#ifdef GECODE_HAS_SET_VARS
set_varsel.~SetVarBranch();
set_valsel.~SetValBranch();
#endif
#ifdef GECODE_HAS_FLOAT_VARS
float_varsel.~TieBreak();
float_valsel.~FloatValBranch();
#endif
(void)Brancher::dispose(home);
return sizeof(*this);
}
};
Expand Down Expand Up @@ -668,7 +695,7 @@ namespace Gecode { namespace FlatZinc {
}

SetValBranch
annotation_to_set_val_branch(AST::Node* ann, std::string r0, std::string r1, const Rnd& rnd) {
annotation_to_set_val_branch(AST::Node* ann, std::string& r0, std::string& r1, const Rnd& rnd) {
(void)rnd;
if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
if (s->id == "indomain_min") {
Expand Down Expand Up @@ -746,7 +773,7 @@ namespace Gecode { namespace FlatZinc {
}

FloatValBranch
annotation_to_float_val_branch(AST::Node* ann, std::string r0, std::string r1) {
annotation_to_float_val_branch(AST::Node* ann, std::string& r0, std::string& r1) {
if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
if (s->id == "indomain_split") {
r0 = "<=";
Expand Down Expand Up @@ -1066,17 +1093,17 @@ namespace Gecode { namespace FlatZinc {
std::ostream& err) {
double decay = opt.decay();
Rnd rnd = opt.rnd();
TieBreak<IntVarBranch> def_int_varsel = INT_VAR_AFC_SIZE_MAX(0.99);
IntBoolVarBranch def_intbool_varsel = int_bool_var_afc_size_max(0.99);
TieBreak<IntVarBranch> def_int_varsel = INT_VAR_AFC_SIZE_MAX(decay);
IntBoolVarBranch def_intbool_varsel = int_bool_var_afc_size_max(decay);
IntValBranch def_int_valsel = INT_VAL_MIN();
std::string def_int_rel_left = "=";
std::string def_int_rel_right = "!=";
TieBreak<BoolVarBranch> def_bool_varsel = BOOL_VAR_AFC_MAX(0.99);
TieBreak<BoolVarBranch> def_bool_varsel = BOOL_VAR_AFC_MAX(decay);
BoolValBranch def_bool_valsel = BOOL_VAL_MIN();
std::string def_bool_rel_left = "=";
std::string def_bool_rel_right = "!=";
#ifdef GECODE_HAS_SET_VARS
SetVarBranch def_set_varsel = SET_VAR_AFC_SIZE_MAX(0.99);
SetVarBranch def_set_varsel = SET_VAR_AFC_SIZE_MAX(decay);
SetValBranch def_set_valsel = SET_VAL_MIN_INC();
std::string def_set_rel_left = "in";
std::string def_set_rel_right = "not in";
Expand Down
5 changes: 2 additions & 3 deletions gecode/float.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1970,9 +1970,8 @@ namespace Gecode {
*
* \ingroup TaskModelFloatBranch
*/
GECODE_FLOAT_EXPORT void assign(Home home, const FloatVarArgs& x, const FloatVarBranch& vars,
const FloatAssign& vals, FloatBranchFilter bf = nullptr,
FloatVarValPrint vvp = nullptr);
GECODE_FLOAT_EXPORT void assign(Home home, const FloatVarArgs& x, FloatVarBranch vars, const FloatAssign& vals,
FloatBranchFilter bf = nullptr, FloatVarValPrint vvp = nullptr);
/**
* \brief Assign all \a x with tie-breaking variable selection \a vars and value selection \a vals
*
Expand Down
2 changes: 1 addition & 1 deletion gecode/float/arithmetic/min-max.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ namespace Gecode { namespace Float { namespace Arithmetic {

template <class View>
forceinline
NaryMax<View>::NaryMax(Space& home, NaryMax<View>& p)
NaryMax<View>::NaryMax(Space& home, NaryMax& p)
: NaryOnePropagator<View, PC_FLOAT_BND>(home, p) {}

template <class View>
Expand Down
2 changes: 1 addition & 1 deletion gecode/float/arithmetic/sqr-sqrt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ namespace Gecode { namespace Float { namespace Arithmetic {

template <class View>
forceinline
Sqr<View>::Sqr(Space& home, Sqr<View>& p)
Sqr<View>::Sqr(Space& home, Sqr& p)
: BinaryPropagator<View, PC_FLOAT_BND>(home, p) {}

template <class View>
Expand Down
5 changes: 5 additions & 0 deletions gecode/float/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ namespace Gecode {
forceinline
FloatValArgs::FloatValArgs(const std::vector<FloatVal>& x)
: ArgArray<FloatVal>(x) {}

forceinline
FloatValArgs::FloatValArgs(std::initializer_list<FloatVal> x)
: ArgArray<FloatVal>(x) {}

template <class InputIterator>
forceinline
FloatValArgs::FloatValArgs(InputIterator first, InputIterator last)
Expand Down
2 changes: 1 addition & 1 deletion gecode/float/bool/ite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace Gecode { namespace Float { namespace Bool {

template <class View>
forceinline
Ite<View>::Ite(Space& home, Ite<View>& p)
Ite<View>::Ite(Space& home, Ite& p)
: Propagator(home, p) {
b.update(home, p.b);
x0.update(home, p.x0);
Expand Down
Loading
Loading