Skip to content

Give meta search hub and spoke contexts and report why search ended - #283

Draft
zayenz wants to merge 16 commits into
feature/rename-master-slave-termsfrom
feature/meta-search-protocol
Draft

zayenz wants to merge 16 commits into
feature/rename-master-slave-termsfrom
feature/meta-search-protocol

Conversation

@zayenz

@zayenz zayenz commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

The meta-search protocol had two structural gaps. First, callers treated any search that was not stopped() as a proof of optimality or unsatisfiability, even though several engines can finish without exhausting the search space. Second, hub() and spoke() answered through bare Booleans, leaving no way to distinguish a full search from a symmetry-reduced search or a partial neighbourhood, or to ask RBS to stop early.

This PR replaces stopped() with end_reason(), replaces MetaInfo and the Boolean hook returns with typed contexts, and fixes a set of engine bugs that surfaced while working out the protocol.

Reporting why search ended

end_reason() replaces stopped() (and the experimental limited()), with no compatibility alias. While an engine is still producing solutions it reports NotEnded; once it stops, it reports Exhausted, Incomplete, or Limit. Only Exhausted is a proof.

  • LDS at its discrepancy limit, CABS at its width limit, and the parallel frontier engine at its frontier limit now report Incomplete instead of looking like an exhausted search.
  • FlatZinc reports optimality or unsatisfiability only after Exhausted, and the script driver reports incomplete searches explicitly.

Hub and spoke contexts

The hooks now take context objects and record their answers on them:

void hub(HubContext& hc);
void spoke(SpokeContext& sc);

Both contexts expose the calling engine (MetaEngine), why the hook was called (MetaEvent), the episode and asset indices, the last solution, the statistics, and the no-goods from the episode that ended.

  • hub() selects a MetaDecision: Restart, Continue, or Finish (which ends RBS as Incomplete). Choosing a decision that is not valid for the current event throws IllegalMetaDecision; HubContext::legal() reports which decisions are allowed.
  • spoke() declares a SpokeCoverage:
    • Full covers the hub's search space.
    • Reduced may prune solutions (for example with symmetry breaking or dominance constraints) while preserving an optimal one, so exhausting it is still a proof.
    • Partial (such as an LNS neighbourhood) proves nothing when exhausted.
  • Only no-goods from a Full spoke are posted in the hub. In portfolio search, an exhausted Partial spoke is dropped instead of ending the portfolio.

Engine fixes

Designing the protocol turned up several bugs in PBS, RBS, and Cutoff. Each is fixed in its own commit:

  • Parallel PBS previously ran only as many assets as it had threads and quietly ignored the rest; every asset now runs.
  • An asset that exhausted its search space was dropped while the other assets kept running until a stop object fired. A proving asset now ends the portfolio as Exhausted.
  • The portfolio stop object was checked against one asset's statistics at a time, so a failure limit of n across k assets allowed up to k * n failures. It now sees the combined statistics of all assets.
  • When an engine builder's own stop object fired, it stopped the entire portfolio. That asset is now parked while the other assets continue, and resumes on the next call to next().
  • Restart assets inside a portfolio previously shared one cutoff sequence behind a mutex. Cutoff::copy() now gives each restart asset its own independent cutoff copy.
  • PBS now propagates the hub via status() after hub(). If the hub had branchers and a spoke ends up with none after spoke(), PBS throws Search::SpokeNoBrancher instead of returning an unassigned space as a solution.
  • RBS now constrains the hub with each solution itself before calling hub(), so an override that skips the default still keeps the optimization bound.
  • Branchers posted by hub() could reuse the brancher ids of earlier spoke branchers, causing spoke no-goods to target the wrong variables. RBS now calls Space::reserve_brancher_ids() on the hub after each spoke().
  • RBS now deletes the spoke if spoke() or brancher-id reservation throws during a restart.
  • Cutoff::repeat() now advances its underlying generator instead of repeating the first value indefinitely.

One test edit here belongs to #242: its ExternalObjective test keeps its branchers in portfolio search now that a brancher-less spoke throws.

Testing

Tested locally:

  • Search: 25,872 of 25,872
  • FlatZinc: 151 of 151
  • check: 518 of 518
  • CTest: 7 of 7
  • Experimental A*, CABS, and meta-search: 363 of 363

Sanitizer, fault-injection, and doc builds have not been run on this PR.

Stack

Merge in this order. #242 targets main, and each later PR builds on the one before it so its diff shows only its own commits. The first four PRs are standalone search and random-number changes; #284 through #274 are the Gecode 7 changes split out of what used to be a single branch.

  1. Rank solutions with Space::compare in best-solution search #242 Rank solutions with Space::compare
  2. Rename the meta-search hooks to hub and spoke #282 Rename the meta-search hooks to hub and spoke
  3. Give meta search hub and spoke contexts and report why search ended #283 Hub and spoke contexts and end reasons ← this PR
  4. Add extensible random generators with reproducible stream splitting #241 Splittable random generators
  5. Gecode 7: CMake-only C++23 build baseline #284 Gecode 7: build baseline
  6. Gecode 7: format the sources with LLVM 22 #285 Gecode 7: reformat
  7. Gecode 7: normalized API names, LT constants and Clang checks #286 Gecode 7: API names, LT constants, checks
  8. Gecode 7: post nothing for empty arrays #287 Gecode 7: empty arrays
  9. Gecode 7: pass large parameters by const reference #288 Gecode 7: const& parameters
  10. Gecode 7: state and assert the heap size contract #289 Gecode 7: heap contract
  11. Gecode 7: trivially copyable handles and defaulted special members #290 Gecode 7: modern classes
  12. Gecode 7: native float interval instead of Boost #291 Gecode 7: native float interval
  13. Gecode 7: bug fixes and Doxygen warnings #292 Gecode 7: bug fixes and Doxygen
  14. Gecode 7: scoped enums and descriptive constant names #293 Gecode 7: scoped enums
  15. Gecode 7: clang-tidy sweep #274 Gecode 7: clang-tidy sweep

A homogeneous portfolio of restart-based engines, PBS<T,RBS>, gave every
asset a PbsCutoff that drew its values from one cutoff shared under a
mutex. The assets thus advanced a single sequence together, and a random
cutoff made all assets restart from the same sequence of values.

Cutoff now has a pure virtual copy() that returns a generator in the
same state, and each asset that takes ownership of the cutoff gets its
own copy. A copy of a random cutoff draws its own sequence. The portfolio
deletes the original once it has been built; if building throws, the
caller keeps the cutoff, as with RBS. Nested portfolios of restart-based
engines are handled the same way, and other engines do not take the
cutoff and are left unchanged. This replaces PbsCutoffs, PbsCutoff,
make_pbs_cutoffs(), and release_pbs_cutoffs().
stopped() could not tell an exhausted search from a search that ended
without exhausting its search space, so callers took a search that was
not stopped as a proof. Search engines now report why next() returned
no solution with end_reason(): Exhausted, Incomplete, or Limit, and
NotEnded while next() returns solutions. stopped() and the experimental
limited() are removed without a replacement alias.

Restart-based search reports Exhausted when its hub fails, Limit only
for its own stop object, and the end reason of a complete spoke search
otherwise. CABS and the parallel frontier engine report Incomplete at
their width or frontier limit. Portfolio search keeps its previous
behaviour in terms of the new end reasons.

FlatZinc reports optimality and unsatisfiability only for an exhausted
search, and the script driver reports an incomplete search.
Limited discrepancy search that reached its discrepancy limit reported
the same end as a search that explored the whole tree, so its end could
be taken as a proof. It now reports EndReason::Incomplete, and only a
search whose last probe explored every alternative reports
EndReason::Exhausted.
An asset that exhausted its search space was dropped and the remaining
assets continued. A portfolio next to an asset that never ends, such as
restart-based large neighbourhood search, then ran until a stop object
fired, although the exhausted asset had proven that no further solution
exists. The portfolio now ends with EndReason::Exhausted.

Every spoke is still taken to cover the search space of the hub. The
check is kept in pbs_asset_proof() so that a spoke covering only part
of the search space can be excluded once spokes declare their coverage.
An asset ending without a proof is dropped as before, and a portfolio
whose assets all end that way reports EndReason::Incomplete.
Parallel portfolio search ran only as many assets, or engine builders,
as it had threads and silently dropped the others. A portfolio of three
assets with two threads therefore ran two of them. Every asset now runs
in its own thread, and the threads are divided among the assets with at
least one thread for each asset's engine, as in sequential portfolios.
The stop object in the options of a portfolio was checked for each asset
with the statistics of that asset. A failure limit of n for a portfolio
of k assets therefore allowed up to k * n failures, and with engine
builders the portfolio stop object was checked like a builder's.

The portfolio stop object is now checked with the sum of the statistics
of all assets. A sequential portfolio adds the statistics of the other
assets before running an asset. A parallel portfolio records the latest
statistics of each asset under a mutex, only when the portfolio has a
stop object. The stop objects of engine builders are still checked with
the statistics of their engine.
When the stop object of an engine builder stopped its engine, the whole
portfolio stopped and reported a limit, although the other assets could
still have found solutions or exhausted the search space.

The portfolio stop objects now record which stop object stopped an
asset. An asset stopped by its own stop object is parked and the other
assets continue. The portfolio reports EndReason::Limit when only parked
assets remain, or when its own stop object fires, and parked assets
resume with the next call to next().
The meta search hooks now take contexts and answer through them:

    void hub(HubContext& hc);
    void spoke(SpokeContext& sc);

Both contexts tell the hook which engine calls it (MetaEngine), why
(MetaEvent), the episode, the asset and the number of assets, the last
solution, the statistics and the no-goods of the episode that ended.
hub() sets a MetaDecision (Restart or Continue), Restart by default.
spoke() declares a SpokeCoverage (Full or Partial), Full by default.
MetaInfo, the Boolean results and the deleted master() and slave()
declarations are removed, and with them the compile tests for the
deleted declarations.

The engines call the hooks at the same points and with the same
semantics as before. Restart-based search calls hub() after a solution,
at the cutoff, and when a Partial spoke is exhausted or ends without a
proof, honours Continue only after a solution, and ends after a Full
spoke is exhausted or ends without a proof. Episodes count from zero and
increase for every new spoke. Portfolio search calls hub() once with
Start and spoke() for each asset.

FlatZinc derives the on_restart status from the event and declares its
on_restart and LNS spokes Partial. The examples, tests, documentation
and migration notes use the new hooks.
SpokeCoverage::Reduced declares a spoke that prunes solutions but keeps
one, or an optimal one, if any exists, such as a spoke with symmetry
breaking or dominance constraints. Exhausting it is a proof, as for
Full, but its no-goods do not hold in the hub.

Restart-based search posts only the no-goods of a Full spoke in the
hub, so the no-goods of a Reduced spoke stay in that spoke, as those of
a Partial spoke already did.

Portfolio search honours the coverage of every asset: an asset with a
Partial spoke that is exhausted is dropped instead of ending the
portfolio. This also holds for a portfolio of a single asset, which then
runs inside a portfolio engine instead of as the bare asset engine.
For a best solution engine, restart-based search now constrains the hub
with each solution before it calls hub(), instead of leaving it to the
default hub(). An override that did not call the default lost the bound
and found the same solutions again. The default hub() now only posts the
no-goods.
Portfolio search now calls status() on the hub after hub() and before
it clones the spokes. A hub() that posted a constraint made the
portfolio throw SpaceNotStable, and a hub that fails now ends the
portfolio as exhausted.

After spoke(), a spoke without branchers throws Search::SpokeNoBrancher
when the hub had branchers. The default hub() removes all branchers, so
a spoke() that forgot to post the branching of its asset returned the
unassigned spoke as a solution.
hub() can now set MetaDecision::Finish to end restart-based search as
incomplete, and Continue after MetaEvent::Limit to resume the same spoke
with the next cutoff as a fresh budget. A decision that is illegal for
the event throws IllegalMetaDecision, and HubContext::legal() tells
which decisions are legal.

Restart-based search calls hub() with Start before the first spoke, and
after every episode that does not end with a proof, also when the inner
engine of a Full or Reduced spoke ends incomplete. The engine sets a
default decision for each event: Restart, except Finish after an
Incomplete episode whose spoke is not Partial, since a new spoke would
repeat the same search. A restart is counted when the engine restarts,
after hub() returns and the hub is not failed.
A brancher that spoke() posts gets the next brancher id of the spoke.
The hub, from which the spoke was cloned, still has the same counter, so
a brancher that hub() posts later got the same id. Restart-based search
then posted the no-goods of the spoke, which refer to the spoke's
brancher by its id, for the hub's brancher: the no-goods could prune the
wrong variables and lose solutions, or reach a brancher of another type.

The engine now calls Space::reserve_brancher_ids() on the hub after each
spoke(), so the hub's later branchers get fresh ids and no-goods for the
spoke's branchers find no brancher in the hub. Branchers that other
branchers post during the search of a spoke are not covered; the hub()
documentation says so.
Restart-based search took the old hub as the spoke and called spoke() on
it before handing it to the engine. An exception from spoke() or from
reserving the brancher ids leaked the spoke. Hold it in a unique_ptr until
the engine takes it.
An exception that a hook throws in an asset, such as IllegalMetaDecision
from the hub of a restart-based asset, must not leave the thread of a
parallel asset. Parallel portfolio search already catches it, stops the
other assets, and rethrows it from next(). Check this for sequential and
parallel portfolios.
CutoffRepeat read the current value of the generator it repeats without
advancing it, so after the first value it repeated the same value forever.

This branch has not been deployed

No deployments
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