Skip to content
Open
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ foreach(i RANGE ${length})
set(CONFIG_OUT "${CONFIG_OUT}${line}")
endforeach()

file(WRITE ${GECODE_BINARY_DIR}/gecode/support/config.hpp
file(CONFIGURE OUTPUT "${GECODE_BINARY_DIR}/gecode/support/config.hpp" CONTENT
"/* gecode/support/config.hpp. Generated from config.hpp.in by configure. */
/* gecode/support/config.hpp.in. Generated from configure.ac by autoheader. */
Expand Down
30 changes: 30 additions & 0 deletions changelog.in
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,36 @@ This release modernizes the Gecode build infrastructure, adds a
first-class CMake package for downstream consumers, refreshes the
autoconf build path, and updates CI coverage for current platforms.

[ENTRY]
Module: flatzinc
What: bug
Rank: minor
Issue: 207
Thanks: Nathan Tran
[DESCRIPTION]
Include the upper endpoint when generating FlatZinc on_restart
uniform integer and float values.

[ENTRY]
Module: other
What: change
Rank: minor
Issue: 203
Thanks: Bruce Mitchener
[DESCRIPTION]
Avoid rewriting the generated CMake config.hpp file when its
contents have not changed.

[ENTRY]
Module: search
What: bug
Rank: minor
Issue: 150
Thanks: Stefan Brüns
[DESCRIPTION]
Send CPProfiler's DONE message before disconnecting from the
profiler socket.

[ENTRY]
Module: other
What: change
Expand Down
15 changes: 13 additions & 2 deletions gecode/flatzinc/flatzinc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
*
* Contributing authors:
* Gabriel Hjort Blindell <gabriel.hjort.blindell@gmail.com>
* Nathan Tran <kieron.qtran@gmail.com>
*
* Copyright:
* Guido Tack, 2007-2012
* Gabriel Hjort Blindell, 2012
* Nathan Tran, 2025
*
* This file is part of Gecode, the generic constraint
* development environment:
Expand Down Expand Up @@ -2040,7 +2042,13 @@ namespace Gecode { namespace FlatZinc {
// Assign uniform_int random values
for (size_t i = 0; i < restart_data().uniform_range_int.size(); ++i) {
const auto& range = restart_data().uniform_range_int[i];
const int rndVal = range.first + _random(static_cast<unsigned int>(range.second - range.first));
const unsigned long long int width =
static_cast<unsigned long long int>(
static_cast<long long int>(range.second) -
static_cast<long long int>(range.first)) + 1ULL;
const int rndVal =
static_cast<int>(static_cast<long long int>(range.first) +
static_cast<long long int>(_random(width)));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle large uniform_int ranges inclusively

When the inclusive width is larger than 2^31 but not larger than UINT_MAX (for example gecode_on_restart_uniform_int(-2147483648, 0, y)), this call still cannot draw the last offset. The Rnd unsigned-long-long path delegates to the 32-bit generator for n <= UINT_MAX, and that generator's maximum result for these bounds is n - 2, so range.second remains unreachable even though the predicate is documented as inclusive.

Useful? React with 👍 / 👎.

rel(*this, on_restart_iv[base + i], IRT_EQ, rndVal);
}
base += restart_data().uniform_range_int.size();
Expand Down Expand Up @@ -2164,7 +2172,10 @@ namespace Gecode { namespace FlatZinc {
for (size_t i = 0; i < restart_data().uniform_range_float.size(); ++i) {
const auto& range = restart_data().uniform_range_float[i];
/* rndVal will be an element of [range.first, range.second] */
const FloatVal rndVal = (static_cast<FloatVal>(_random(INT_MAX)) / INT_MAX)*(range.second - range.first) + range.first;
const FloatVal rndVal =
(static_cast<FloatVal>(_random(INT_MAX)) /
static_cast<FloatVal>(INT_MAX - 1)) *
(range.second - range.first) + range.first;
rel(*this, on_restart_fv[base + i], FRT_EQ, rndVal);
}
base += restart_data().uniform_range_float.size();
Expand Down
3 changes: 3 additions & 0 deletions gecode/search/cpprofiler/tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
* Contributing authors:
* Kevin Leo <kevin.leo@monash.edu>
* Christian Schulte <schulte@gecode.dev>
* Stefan Brüns <stefan.bruens@rwth-aachen.de>
*
* Copyright:
* Kevin Leo, 2017
* Christian Schulte, 2017
* Maxim Shishmarev, 2017
* Stefan Brüns, 2022
*
* This file is part of Gecode, the generic constraint
* development environment:
Expand Down Expand Up @@ -146,6 +148,7 @@ namespace Gecode {

void
CPProfilerSearchTracer::done(void) {
connector->done();
connector->disconnect();
}

Expand Down
16 changes: 16 additions & 0 deletions test/flatzinc/on_restart_last_val_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
* Main authors:
* Jip J. Dekker <jip.dekker@monash.edu>
*
* Contributing authors:
* Nathan Tran <kieron.qtran@gmail.com>
*
* Copyright:
* Jip J. Dekker, 2023
* Nathan Tran, 2025
*
* This file is part of Gecode, the generic constraint
* development environment:
Expand Down Expand Up @@ -80,6 +84,18 @@ y = 3;
----------
==========
)OUT", true, {"--restart", "constant", "--restart-base", "100"});

(void) new FlatZincTest("on_restart::uniform_int_upper_bound",
R"FZN(
predicate gecode_on_restart_uniform_int(int: low,int: high,var int: out);
var 0..1: y:: output_var;
constraint gecode_on_restart_uniform_int(0,1,y);
constraint int_eq(y,1);
solve satisfy;
)FZN",
R"OUT(y = 1;
----------
)OUT", true, {"--restart", "constant", "--restart-base", "100", "--seed", "2"});
}
};

Expand Down