Skip to content

Fix how restart-based and portfolio search end and stop - #280

Merged
zayenz merged 6 commits into
mainfrom
fix/meta-search-engine-ends
Nov 15, 2026
Merged

zayenz merged 6 commits into
mainfrom
fix/meta-search-engine-ends

Conversation

@zayenz

@zayenz zayenz commented Nov 15, 2026

Copy link
Copy Markdown
Member

These are bug fixes in how search engines end and stop, intended for 6.6.0. Each fix is a separate commit with a regression test that fails without it. No public API is removed or changed. The only additions are two exported pbsstop overloads.

Fixes

  • A portfolio of restart-based engines crashed when deleted. Every asset took ownership of the same cutoff, so it was deleted once per asset. Now the assets draw from one shared, reference-counted cutoff sequence, deleted exactly once. This also holds when the root or an asset's root fails while the portfolio is built.
  • Restart-based search with no-goods could restart forever on unsatisfiable models. When the search tree was exhausted at the same failure that reached the limit, sequential DFS and BAB reported stopped(). Each restart then added no new no-goods and repeated the same search. An exhausted search now finishes before the stop object is checked.
  • A proof after a restart was reported as unknown. When the master failed at a restart after a cutoff limit, for example by posting no-goods, RBS still reported stopped(). FlatZinc then printed an unknown result instead of the proof.
  • A failed root was not counted as a failure on reset. Restart-based search resets its engine at every restart. When large neighbourhood search's slave failed right away, failure limits and portfolio slices did not advance. RBS now also checks its stop object before each restart after an incomplete slave search, because a parallel engine could otherwise restart forever.
  • A portfolio built from engine builders ignored its own stop object. Only the builders' stop objects were checked. The portfolio's stop object is now checked as well, against each builder engine's own statistics, so a time limit on the portfolio works. A node or fail limit given to the portfolio applies to each asset separately, as documented.
  • LDS (documentation only). LDS does not report reaching its discrepancy limit as a stop, so finding no solution is a proof only if the limit covers every path of the tree. This is now documented. Changing the behaviour needs an API change, which is left for Gecode 7.

Each fix has a changelog entry.

Not included

The photo -restart constant -restart-scale 5 -nogoods true -seed 4 segfault does not reproduce on current main; cc578a0 fixed it. 150 runs under AddressSanitizer and UndefinedBehaviorSanitizer were clean, also with the #277 guard bypassed.

Testing

Release build on macOS:

Suite Result
-test Search 25821 of 25821 passed
-tag check 537 of 537 passed

Fault-injection (gecode-fault-test) and AddressSanitizer plus UndefinedBehaviorSanitizer runs (-test Search, -tag check) on Linux with GCC are in progress. I'll add the results here.

When the slave search hit its cutoff, RBS restarted by calling the
master configuration function. If the master then failed, for example
because the posted no-goods proved that no better solution exists, RBS
returned no solution but left the stopped slave engine in place, so
stopped() kept returning true. FlatZinc then printed an unknown result
instead of the proof, and the statistics counted the last slave search
twice.

Dispose of the failed master and reset the slave engine, as after a
master that fails following a solution. RBS reports a stop only while it
still has a master, and next() and constrain() do nothing once the
master has failed.
The constructors of DFS, BAB, and LDS count a root space that fails at
status() as a failure, but reset() checked the status before resetting
the statistics, so the failure and the root's propagations were lost.
RBS resets its engine for every restart, so when the slave space of
large neighbourhood search failed right away, neither a FailStop or
NodeStop nor the failure slice of a portfolio advanced: RBS with LNS
under FailStop(5000) ran 960k episodes with no failure counted.

Reset the statistics first and count a failed root, in the sequential
and parallel engines. A null space, which RBS passes after its master
has failed, is not counted.

RBS also relied on the slave engine to check the stop object of the
meta engine. A parallel engine without work never checks it, so with a
slave failing at the root, restarts continued forever whatever the stop
object said. RBS now checks that stop object itself before each restart
after an incomplete slave search.
Sequential DFS and BAB checked the stop object before checking whether
the search tree was exhausted. When the last failure of the tree
exceeded a failure limit, the engine reported a stop although nothing
was left to explore. With an empty path there are no no-goods, so RBS
restarted from the same master and repeated the same slave search
forever. RBS with no-goods on an unsatisfiable pigeonhole model did not
terminate for most constant cutoffs between 5 and 17: the search got
stuck once the remaining subtree had exactly one failure more than the
cutoff.

Return as exhausted before checking the stop object, as LDS already
does. The parallel engines check the stop object only when they have
work, so they were not affected.
A portfolio created from engine builders, PBS(s, sebs, o), wrapped
the stop object of each builder in its portfolio stop and never looked
at o.stop. A portfolio with a 200 ms TimeStop ran for about 3 seconds
and then reported that it had not been stopped.

The portfolio stop of each asset now checks the stop object of the
portfolio as well as that of the builder, with the statistics of the
asset, as the homogeneous portfolio already does for its stop object.
New overloads of Seq::pbsstop and Par::pbsstop pass both stop objects;
the existing ones are kept.
A homogeneous portfolio of restart-based engines, PBS<T,RBS>, passed
the same options to every asset, so every RBS engine took ownership of
the cutoff in o.cutoff. The cutoff was deleted once per asset: a
portfolio of two RBS assets crashed when it was deleted, and parallel
assets also advanced the same cutoff concurrently.

A cutoff cannot be copied without adding a virtual function, so each
asset that takes ownership of the cutoff now gets a PbsCutoff, which
draws the next value from the shared cutoff under a mutex. The shared
cutoff is deleted with the last asset cutoff, and only if the portfolio
was built: if building throws, the caller keeps the cutoff, as with
RBS. Nested portfolios of restart-based engines are handled the same
way; other engines do not take the cutoff and are left unchanged.

RBS also deleted the cutoff before creating the engine for a failed
root, so a failing allocation there would leave the caller with a
deleted cutoff. Delete it once that engine exists.
When LDS reaches its discrepancy limit with parts of the tree left
unexplored, next() returns nullptr and stopped() returns false, exactly
as after exhausting the tree. A caller cannot tell an incomplete search
from a proof.

Reporting the limit through stopped() would change how RBS and PBS
treat an LDS asset: RBS would restart it as if a cutoff had been
reached, and PBS would stop the whole portfolio. The 6.x engine
interface has no other way to report it outside experimental builds,
so document the behaviour for LDS, lds(), and the discrepancy limit.
@zayenz
zayenz force-pushed the fix/meta-search-engine-ends branch from 23e17b8 to 8eff1d5 Compare November 15, 2026 08:40
@zayenz
zayenz merged commit 2f3080e into main Nov 15, 2026
16 checks passed
@zayenz
zayenz deleted the fix/meta-search-engine-ends branch November 15, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant