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
13 changes: 13 additions & 0 deletions .github/ci/flatzinc-tools-smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,17 @@ MZN
)
[[ "$result" == *"capacity=3 empty-capacity=1 large-usage=0"* ]]

# Reified regular is false, not unsatisfiable, on a value outside 1..S.
result=$("$prefix/bin/mzn-gecode" - <<'MZN'
include "regular.mzn";
var 2..3: x;
var bool: b;
constraint b <-> regular([x],1,2,[|1,1|],1,{1});
constraint not b;
solve satisfy;
output ["regular-x=",show(x),"\n"];
MZN
)
[[ "$result" == *"regular-x=3"* ]]

fi
68 changes: 68 additions & 0 deletions changelog.in
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ Rank: minor
Avoid zero-byte heap allocations and null memcpy calls for empty Action, CHB,
Archive, and Space::realloc from an empty block.

[ENTRY]
Module: kernel
What: bug
Rank: minor
[DESCRIPTION]
Fix an uninitialized read in RangeList::copy() when creating or cloning
integer and set trace views.

[ENTRY]
Module: support
What: new
Expand Down Expand Up @@ -538,6 +546,31 @@ Rank: minor
Avoid zero-byte heap allocations for arity-zero TupleSets, and allow
constructing an empty IntSet from an empty initializer list.

[ENTRY]
Module: int
What: bug
Rank: minor
[DESCRIPTION]
Fix signed overflow in unary propagation (also used for cumulative
constraints reduced to unary), which missed overload failure when the total
duration of the tasks exceeds the integer limits.

[ENTRY]
Module: int
What: bug
Rank: minor
[DESCRIPTION]
Make not-first/not-last propagation for unary resources prune all tasks with
equal start or completion bounds, so propagation no longer depends on the
order in which the tasks are stored.

[ENTRY]
Module: int
What: bug
Rank: minor
[DESCRIPTION]
Fix signed overflow when posting cumulative with a single task.

[ENTRY]
Module: set
What: bug
Expand Down Expand Up @@ -570,6 +603,24 @@ Rank: minor
Handle empty arrays when posting channel_sorted, Boolean channel, element,
union/disjoint-union rel with a constant set, and weights.

[ENTRY]
Module: set
What: bug
Rank: minor
[DESCRIPTION]
Fix set element with SOT_UNION (for both variable and constant set arrays),
which missed solutions when the selector and result are the same variable.
This also fixes MiniZinc's roots(x, s, s).

[ENTRY]
Module: set
What: bug
Rank: minor
[DESCRIPTION]
Fix the channel between integer variables and a single set variable, which
accepted wrong solutions. This also fixes MiniZinc's roots when the largest
value its image can contain is 0.

[ENTRY]
Module: set
What: documentation
Expand All @@ -578,6 +629,15 @@ Rank: minor
Document the exceptions thrown by sequence and integer-indexed element for
empty arrays and out-of-limits sets.

[ENTRY]
Module: set
What: performance
Rank: minor
[DESCRIPTION]
Bound the auxiliary set created by rel(home, x, op, y, r, z) for SRT_LQ,
SRT_LT, SRT_GQ, and SRT_GR by the upper bounds of x and y instead of the
whole set universe, so the order propagator no longer walks the universe.

[ENTRY]
Module: float
What: change
Expand Down Expand Up @@ -706,6 +766,14 @@ Rank: minor
Avoid zero-byte heap allocations for empty variable domains (var {}, var set
of {}) and empty final-state intervals in regular.

[ENTRY]
Module: flatzinc
What: bug
Rank: minor
[DESCRIPTION]
Make reified MiniZinc regular over 1..S evaluate to false when a variable
takes a value outside 1..S, instead of making the problem unsatisfiable.

[ENTRY]
Module: example
What: bug
Expand Down
4 changes: 4 additions & 0 deletions gecode/flatzinc/mznlib/fzn_regular.mzn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
%
%

% Keep the standard decomposition for reified regular; MiniZinc's native
% reification fails on values outside 1..S instead of reifying them to false.
fzn_regular_is_decomposed = true;

predicate gecode_regular(array[int] of var int: x, int: Q, int: S,
array[int] of int: d, int: q0, set of int: F);

Expand Down
6 changes: 4 additions & 2 deletions gecode/int/cumulative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ namespace Gecode::Int::Cumulative {
}
max_u = std::max(ui, max_u);
}
bool disjunctive = (min_u > c.max() / 2) || (min_u2 > c.max() / 2 && min_u + min_u2 > c.max());
bool disjunctive =
(min_u > c.max() / 2) || (min_u2 > c.max() / 2 && static_cast<long long int>(min_u) + min_u2 > c.max());
if (disjunctive) {
GECODE_ME_FAIL(c.gq(home, max_u));
unary(home, t, s, p, ipl);
Expand Down Expand Up @@ -191,7 +192,8 @@ namespace Gecode::Int::Cumulative {
}
max_u = std::max(ui, max_u);
}
bool disjunctive = (min_u > c.max() / 2) || (min_u2 > c.max() / 2 && min_u + min_u2 > c.max());
bool disjunctive =
(min_u > c.max() / 2) || (min_u2 > c.max() / 2 && static_cast<long long int>(min_u) + min_u2 > c.max());
if (disjunctive) {
GECODE_ME_FAIL(c.gq(home, max_u));
unary(home, s, p, ipl);
Expand Down
3 changes: 0 additions & 3 deletions gecode/int/task.hh
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,6 @@ namespace Gecode::Int {

namespace Gecode::Int {

/// Safe addition in case \a x is -Int::Limits::infinity
int plus(int x, int y);

/// Safe addition in case \a x is -Int::Limits::llinfinity
long long int plus(long long int x, long long int y);

Expand Down
6 changes: 0 additions & 6 deletions gecode/int/task/tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@

namespace Gecode::Int {

forceinline int
plus(int x, int y) {
assert(y != -Limits::infinity);
return (x == -Limits::infinity) ? x : x + y;
}

forceinline long long int
plus(long long int x, long long int y) {
assert(y != -Limits::llinfinity);
Expand Down
16 changes: 11 additions & 5 deletions gecode/int/unary.hh
Original file line number Diff line number Diff line change
Expand Up @@ -644,13 +644,19 @@ namespace Gecode::Int {

namespace Gecode::Int::Unary {

/// Node for an omega tree
/**
* \brief Node for an omega tree
*
* Processing and completion times of task sets can exceed the integer
* limits, so they are kept as long long. The tree accessors clamp
* completion times with clamp_ect().
*/
class OmegaNode {
public:
/// Processing time for subtree
int p;
long long int p;
/// Earliest completion time for subtree
int ect;
long long int ect;
/// Initialize node from left child \a l and right child \a r
void init(const OmegaNode& l, const OmegaNode& r);
/// Update node from left child \a l and right child \a r
Expand Down Expand Up @@ -686,9 +692,9 @@ namespace Gecode::Int::Unary {
/// Undefined task
static const int undef = -1;
/// Processing times for subtree
int lp;
long long int lp;
/// Earliest completion times for subtree
int lect;
long long int lect;
/// Node which is responsible for lect
int res_ect;
/// Node which is responsible for lp
Expand Down
77 changes: 44 additions & 33 deletions gecode/int/unary/not-first-not-last.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,59 @@

namespace Gecode::Int::Unary {

template <class ManTaskView>
forceinline ExecStatus
not_last(Space& home, TaskViewArray<ManTaskView>& t) {
sort<ManTaskView, STO_LCT, true>(t);

Region r;

OmegaTree<ManTaskView> o(r, t);
TaskViewIter<ManTaskView, STO_LST, true> q(r, t);
int* lct = r.alloc<int>(t.size());
/**
* \brief Compute in \a lct the not-last bounds for the tasks \a t
*
* The tasks \a t must be sorted by increasing latest completion time
* and \a q iterates the mandatory tasks by increasing latest start
* time. Tasks with equal latest completion or start times receive
* bounds that do not depend on their order in \a t, so the bounds are a
* function of the task domains alone.
*/
template <class TaskView, class Iter>
forceinline void
not_last_bounds(Region& r, TaskViewArray<TaskView>& t, Iter& q, int* lct) {
OmegaTree<TaskView> o(r, t);
int* tied = r.alloc<int>(t.size());

for (int i = 0; i < t.size(); i++)
lct[i] = t[i].lct();

// The inserted task with the largest latest start time
int j = -1;
for (int i = 0; i < t.size(); i++) {
int j = -1;
while (q() && (t[i].lct() > t[q.task()].lst())) {
if ((j >= 0) && (o.ect() > t[q.task()].lst()))
lct[q.task()] = std::min(lct[q.task()], t[j].lst());
j = q.task();
o.insert(j);
++q;
// Insert all tasks with the same latest start time at once
int lst = t[q.task()].lst();
bool precedes_inserted = (j >= 0) && (o.ect() > lst);
int n = 0;
while (q() && (t[q.task()].lst() == lst)) {
tied[n++] = q.task();
o.insert(q.task());
++q;
}
for (int k = 0; k < n; k++)
if (precedes_inserted)
lct[tied[k]] = std::min(lct[tied[k]], t[j].lst());
else if ((n > 1) && (o.ect(tied[k]) > lst))
lct[tied[k]] = std::min(lct[tied[k]], lst);
j = tied[n - 1];
}
if ((j >= 0) && (o.ect(i) > t[i].lst()))
lct[i] = std::min(lct[i], t[j].lst());
}
}

template <class ManTaskView>
forceinline ExecStatus
not_last(Space& home, TaskViewArray<ManTaskView>& t) {
sort<ManTaskView, STO_LCT, true>(t);

Region r;

TaskViewIter<ManTaskView, STO_LST, true> q(r, t);
int* lct = r.alloc<int>(t.size());
not_last_bounds(r, t, q, lct);

for (int i = 0; i < t.size(); i++)
GECODE_ME_CHECK(t[i].lct(home, lct[i]));
Expand All @@ -83,25 +110,9 @@ namespace Gecode::Int::Unary {

Region r;

OmegaTree<OptTaskView> o(r, t);
ManTaskViewIter<OptTaskView, STO_LST, true> q(r, t);
int* lct = r.alloc<int>(t.size());

for (int i = 0; i < t.size(); i++)
lct[i] = t[i].lct();

for (int i = 0; i < t.size(); i++) {
int j = -1;
while (q() && (t[i].lct() > t[q.task()].lst())) {
if ((j >= 0) && (o.ect() > t[q.task()].lst()))
lct[q.task()] = std::min(lct[q.task()], t[j].lst());
j = q.task();
o.insert(j);
++q;
}
if ((j >= 0) && (o.ect(i) > t[i].lst()))
lct[i] = std::min(lct[i], t[j].lst());
}
not_last_bounds(r, t, q, lct);

{
int n = t.size();
Expand Down
8 changes: 4 additions & 4 deletions gecode/int/unary/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ namespace Gecode::Int::Unary {
}
forceinline ModEvent
ManFixPTask::ect(Space& home, int n) {
return _s.gq(home, n - _p);
return _s.gq(home, static_cast<long long int>(n) - _p);
}
forceinline ModEvent
ManFixPTask::lst(Space& home, int n) {
return _s.lq(home, n);
}
forceinline ModEvent
ManFixPTask::lct(Space& home, int n) {
return _s.lq(home, n - _p);
return _s.lq(home, static_cast<long long int>(n) - _p);
}
forceinline ModEvent
ManFixPTask::norun(Space& home, int e, int l) {
Expand Down Expand Up @@ -283,7 +283,7 @@ namespace Gecode::Int::Unary {
case TT_FIXED_END:
return (n <= _p) ? ME_INT_NONE : ME_INT_FAILED;
case TT_FIXED_PROCESSING:
return _s.gq(home, n - _p);
return _s.gq(home, static_cast<long long int>(n) - _p);
case TT_FIXED_START:
return _s.gq(home, n);
default:
Expand All @@ -310,7 +310,7 @@ namespace Gecode::Int::Unary {
case TT_FIXED_END:
return (n >= _p) ? ME_INT_NONE : ME_INT_FAILED;
case TT_FIXED_PROCESSING:
return _s.lq(home, n - _p);
return _s.lq(home, static_cast<long long int>(n) - _p);
case TT_FIXED_START:
return _s.lq(home, n);
default:
Expand Down
Loading