Repository navigation
Fix wrong answers and overflows in set, scheduling, and FlatZinc - #302
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix Merge Risk:
|
cb89bcc to
0804038
Compare
When the selector and result views alias, the SOT_UNION element propagators modified the selector before consuming an iterator over the result's lower bound, which could drop valid solutions (including from MiniZinc's roots(x, s, s)). Cache the lower-bound difference before modifying the selector for variable sets, and check the subset condition before modifying the selector for constant sets.
Posting ChannelInt bounds every integer variable to 0..ys.size()-1. With a single set variable that assigns every x[i] to 0, which matches the initial cache, so propagate() never sees x[i] as modified and never includes i in y[0]. This let the channel accept invalid solutions and broke MiniZinc's roots when the largest image value is 0. Include i in ys[xs[i].val()] at posting whenever xs[i] is already assigned.
OmegaNode and OmegaLambdaNode summed task processing and earliest completion times in int. When task durations summed beyond the integer limits, the sum overflowed and unary overload detection (also used for cumulative constraints reduced to unary) missed the overload. Store processing and completion times in long long int, clamp completion times to [-Limits::infinity, Limits::infinity] when reading from the trees, and subtract in long long int when updating task start bounds.
not_last() reset j to -1 on every iteration of the outer loop, so among tasks with equal latest completion or start times only the first in storage order received the tighter bound. Because not_first_not_last() runs not_last() forward and backward, propagation could differ between equivalent spaces with different task orders. Keep j across iterations and insert tasks with equal latest start time together, following Vilím's algorithm, in a shared not_last_bounds() helper used by both mandatory and optional tasks.
Gecode's fzn_regular.mzn overrides MiniZinc's standard definition to call the native gecode_regular propagator. Because that drops fzn_regular_is_decomposed = true, MiniZinc compiled reified regular (b <-> regular(...)) into a plain regular over a larger automaton with a final marker symbol for b (S+1 for false, S+2 for true). That encoding assumes every input is in 1..S; values outside 1..S either collided with a marker symbol or lay outside the alphabet, so valid assignments with b = false were ruled out (for instance, x in 2..3, S = 2, not regular([x], ...) reported unsatisfiable instead of x = 3). Add gecode/flatzinc/mznlib/fzn_regular_reif.mzn to encode reified regular directly as a single gecode_regular call instead of falling back to a decomposition with auxiliary state variables. Non-reified regular is unchanged. Each input x is mapped to 1..S+1, keeping values in 1..S and sending all other values to S+1: - inputs whose domain is inside 1..S are passed directly; - bounded inputs with ub(x) - lb(x) < 1024 map through an element constraint on a constant array (domain consistent); - remaining inputs use an if-then-else expression. The extended automaton adds a dead state (reached on S+1 and on every missing transition) and an end state. A final marker symbol carries b: from accepting states only S+3 (true) reaches the end state, and from all other states (including the dead state) only S+2 (false) does.
When posting cumulative, Gecode checks whether the two smallest task usages exceed the capacity so it can reduce to unary. With a single task, the second-smallest usage stays INT_MAX, so min_u + min_u2 overflowed signed int when min_u was positive. Sum in long long int to avoid signed overflow; a single task now takes the unary branch.
RangeList::copy() stored the incoming value of its output pointer r in its sentinel before overwriting it. Integer and set trace views pass an uninitialized RangeList* when created or cloned, so that dead store read uninitialized memory. Remove the dead sentinel.next(r) call.
For the order relations SRT_LQ, SRT_LT, SRT_GQ, and SRT_GR, rel(home, x, op, y, r, z) created its auxiliary set variable for x op y over the full set universe. Because the set order propagator walks every value of the upper bound, posting these relations was extremely slow and memory-intensive. Bound the auxiliary set by the union of lub(x) and lub(y) for SOT_UNION and SOT_DISJOINT_UNION, their intersection for SOT_INTERSECTION, and lub(x) for SOT_MINUS.
0804038 to
71ef30d
Compare
Gecode 6.6.2 was released on 5 December from release/6.6.2. Its fixes came from PRs #305, #304, and #302, whose changelog entries already end the 7.0.0 section directly above 6.6.1. Insert the 6.6.2 release header above them, so that they move into 6.6.2. The 6.6-only Boost.Interval entry has no counterpart on main. The set order relation entry now names SRT_LE, as in the released 6.6.2 changelog: 6.6 has no SRT_LT, which main introduced in 7.0.0.
Gecode 6.6.2 was released on 5 December from release/6.6.2. Its fixes came from PRs #305, #304, and #302, whose changelog entries already end the 7.0.0 section directly above 6.6.1. Insert the 6.6.2 release header above them, so that they move into 6.6.2. The 6.6-only Boost.Interval entry has no counterpart on main. The set order relation entry now names SRT_LE, as in the released 6.6.2 changelog: 6.6 has no SRT_LT, which main introduced in 7.0.0.
Gecode 6.6.2 was released on 5 December from release/6.6.2. Its fixes came from PRs #305, #304, and #302, whose changelog entries already end the 7.0.0 section directly above 6.6.1. Insert the 6.6.2 release header above them, so that they move into 6.6.2. The 6.6-only Boost.Interval entry has no counterpart on main. The set order relation entry now names SRT_LE, as in the released 6.6.2 changelog: 6.6 has no SRT_LT, which main introduced in 7.0.0.
Fixes seven bugs across set constraints, unary and cumulative scheduling, MiniZinc
regular, and trace-view range lists, and bounds the auxiliary set created by set order relations with a set operation. Each fix has a regression test that fails (or triggers ASan/UBSan) onmainand passes on this branch.Fixes
SOT_UNION(variable and constant set arrays) when the selector is also the result, as inroots(x, s, s). The propagator modified the selector before consuming an iterator over the result's lower bound. Tests:Set::Element::Union::SharedandSet::Element::UnionConst::Shared— both fail onmain, pass here.rootswhen the largest value its image can contain is 0). Boundingx[i]to0..0matched the initial cache, sopropagate()never includediiny[0]. Test:Set::Channel::Int::Single— fails onmain, passes here.intlimits.OmegaNodeandOmegaLambdaNodenow accumulate inlong long intand clamp when reading back. Test:Int::Unary::LongTaskOverload(three tasks of length 10^9 must end by 2*10^9) — onmainthe space does not fail and UBSan reports signed overflow ingecode/int/unary/tree.hpp; here it fails as expected and UBSan is clean.Int::Unary::TiedNotLast(posts the same tasks in two orders and expects the same bound 12) — fails onmain, passes here. The sweep replayInt::Unary::Opt::Fix::0::[4,0,3,3,0,5]::Def+A, which previously reported "different result after re-enable", also passes.regular(Gecode'smznlib) when an input can take a value outside1..S. Overridingfzn_regular.mznto callgecode_regulardroppedfzn_regular_is_decomposed = true, so MiniZinc compiled reifiedregularwith a marker-symbol encoding (S+1/S+2) that assumes inputs are in1..Sand ruled out out-of-alphabet values instead of makingbfalse. Newgecode/flatzinc/mznlib/fzn_regular_reif.mznencodes reifiedregulardirectly as one nativegecode_regular(keeping the propagator instead of falling back to a state-variable decomposition; non-reifiedregularis unchanged): values outside1..Smap toS+1(direct if the domain is inside1..S, a constant-array element constraint for bounded inputs withub(x) - lb(x) < 1024to stay domain consistent, otherwiseif-then-else), a dead state absorbsS+1and missing transitions, and a final marker symbol reaches an end state onS+3(true) from accepting states andS+2(false) from all other states. Tests: smoke case in.github/ci/flatzinc-tools-smoke.sh(run in CI with MiniZinc 2.10.1; the FlatZinc test framework starts from FlatZinc text and cannot seemznlib) — by hand with MiniZinc 2.11.0,=====UNSATISFIABLE=====onmain,regular-x=3here; all-solutions comparison against a reference implementation over 600 random reified instances (1–3 states, 1–3 symbols, 1–3 inputs, domains reaching outside1..S) — every sampled instance mismatched without the fix, no mismatches here; unboundedvar intinputs and negatedregularalso give the right answer.cumulativewith a single task while deciding whether to use the unary propagator; results were not affected in practice. Tests:Int::Cumulative::SingleTask::TypedandInt::Cumulative::SingleTask::Untyped— both pass in Release either way; under UBSan,mainreportssigned integer overflow: 1 + 2147483647atgecode/int/cumulative.cpp:70, clean here.RangeList::copy()read its uninitialized output pointer before overwriting it. Test: existingFlatZinc::Branching::AuxVarClone— under ASan+UBSan,mainreportsupcast of misaligned address 0xbebebebebebebebeinrange-list.hpp, clean here.Performance
rel(home, x, op, y, r, z)forSRT_LQ,SRT_LT,SRT_GQ, andSRT_GRpreviously created its auxiliary set variable over the whole set universe; it is now bounded by the operands' upper bounds. Solutions are unchanged. New tests:Set::RelOp::Order::*(16 tests; order relations were not covered forrelwith an operation before) — onmainthey did not finish within 10 minutes and reached 8 GB of memory; here all 16 pass in 0.7 s.Left out
A FlatZinc parser change that checks the argument count of equality, domain, and on-restart constraints before reading fixed argument positions. On
mainthe constraint posters do not check argument counts either, so guarding only the parser would just move the out-of-range read into the poster. Adding argument-count checks to the posters first is a separate change. Because the parser is unchanged, no regeneration was needed.Testing
All run on this branch:
mainand passes with its fix, as above.Set::Element(27),Set::Channel(15),Int::Unary(152),Int::Cumulative(5095, includesCumulatives),Set::RelOp(856),Set::Rel(20),FlatZinc(161), andInt::NoOverlap(17) — all pass.Set::Element,Set::Channel,Int::Unary,Int::Cumulative,Set::RelOp, andFlatZinc(all tags) — all pass with no report; check suite: 570 tests, all pass with no report.check-standardtarget (7012 tests) — all pass.misc/check.py lint(full tree, clang-tidy 22) exited 0;format-checkclean;misc/tidy.py --checkpassed.Summary by CodeRabbit
regularconstraints when input values fall outside the automaton’s valid range.