Skip to content
Merged
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 @@ -754,6 +754,74 @@ posting, so a parameter used by many constraints was held many times over:
190 table constraints over one 480,000-element tuple array took 2.1 GB to
parse, and now take 73 MB.

[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: 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: 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: int
What: bug
Rank: minor
[DESCRIPTION]
Fix signed overflow when posting cumulative with a single task.

[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: 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.

[RELEASE]
Version: 6.6.1
Date: 2026-11-29
Expand Down
77 changes: 77 additions & 0 deletions gecode/flatzinc/mznlib/fzn_regular_reif.mzn
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
%
% Main authors:
% Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
%
% Copyright:
% Mikael Zayenz Lagerkvist, 2026
%
% This file is part of Gecode, the generic constraint
% development environment:
% http://www.gecode.dev
%
% 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.
%
%

include "fzn_regular.mzn";

% Reified regular as one regular constraint over an extended automaton. Values
% outside 1..S read as the symbol S + 1, which leads to a dead state. A final
% symbol encodes b: from an accepting state only S + 3 (true) reaches the end
% state, and from any other state only S + 2 (false) does.
predicate fzn_regular_reif(array[int] of var int: xs, int: Q, int: S,
array[int,int] of int: d, int: q0, set of int: F,
var bool: b) =
if length(xs) = 0 then
b = (q0 in F)
else
let {
int: other = S + 1;
int: dead = Q + 1;
int: done = Q + 2;
array[1..Q+2, 1..S+3] of int: dd = array2d(1..Q+2, 1..S+3, [
if r <= Q /\ c <= S then
if d[r,c] = 0 then dead else d[r,c] endif
elseif c <= other then
if r <= dead then dead else 0 endif
elseif r = done then
0
elseif (c = S + 3) = (r in F) then
done
else
0
endif
| r in 1..Q+2, c in 1..S+3]);
array[int] of var 1..other: ys = [gecode_regular_symbol(x, S) | x in xs];
} in
gecode_regular(ys ++ [S + 2 + bool2int(b)], Q + 2, S + 3, array1d(dd), q0, {done})
endif;

% The symbol of x in fzn_regular_reif: x itself in 1..S, otherwise S + 1.
% Small domains map through an element constraint, which keeps propagation
% domain consistent.
function var int: gecode_regular_symbol(var int: x, int: S) =
if dom(x) subset 1..S then
x
elseif has_bounds(x) /\ ub(x) - lb(x) < 1024 then
array1d(lb(x)..ub(x), [if v in 1..S then v else S + 1 endif | v in lb(x)..ub(x)])[x]
else
if x in 1..S then x else S + 1 endif
endif;
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
8 changes: 4 additions & 4 deletions gecode/int/unary.hh
Original file line number Diff line number Diff line change
Expand Up @@ -648,9 +648,9 @@ namespace Gecode::Int::Unary {
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 +686,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