Repository navigation
Conversation
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 was referenced Nov 20, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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()andspoke()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()withend_reason(), replacesMetaInfoand 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()replacesstopped()(and the experimentallimited()), with no compatibility alias. While an engine is still producing solutions it reportsNotEnded; once it stops, it reportsExhausted,Incomplete, orLimit. OnlyExhaustedis a proof.Incompleteinstead of looking like an exhausted search.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:
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 aMetaDecision:Restart,Continue, orFinish(which ends RBS asIncomplete). Choosing a decision that is not valid for the current event throwsIllegalMetaDecision;HubContext::legal()reports which decisions are allowed.spoke()declares aSpokeCoverage:Fullcovers the hub's search space.Reducedmay 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.Fullspoke are posted in the hub. In portfolio search, an exhaustedPartialspoke 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:Exhausted.nacrosskassets allowed up tok * nfailures. It now sees the combined statistics of all assets.next().Cutoff::copy()now gives each restart asset its own independent cutoff copy.status()afterhub(). If the hub had branchers and a spoke ends up with none afterspoke(), PBS throwsSearch::SpokeNoBrancherinstead of returning an unassigned space as a solution.hub(), so an override that skips the default still keeps the optimization bound.hub()could reuse the brancher ids of earlier spoke branchers, causing spoke no-goods to target the wrong variables. RBS now callsSpace::reserve_brancher_ids()on the hub after eachspoke().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
ExternalObjectivetest keeps its branchers in portfolio search now that a brancher-less spoke throws.Testing
Tested locally:
check: 518 of 518Sanitizer, fault-injection, and
docbuilds 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.