Repository navigation
Give meta search hub and spoke contexts and report why search ended #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
760af9c
Give each restart asset of a portfolio its own cutoff
zayenz 5134431
Replace stopped() with end_reason()
zayenz 7569d14
Report LDS at its discrepancy limit as incomplete
zayenz 6f2a5af
End a portfolio when an asset exhausts its search space
zayenz c44af9e
Run every asset of a parallel portfolio
zayenz cfef78f
Check the portfolio stop object with portfolio-wide statistics
zayenz 66750e7
Park a portfolio asset whose own stop object fires
zayenz b32b2f6
Replace MetaInfo with hub and spoke contexts
zayenz b9a62fb
Honour spoke coverage for no-goods and in portfolio search
zayenz 911dfe4
Constrain the hub with each solution in the engine
zayenz f8b43da
Propagate the hub of portfolio search and require spoke branchers
zayenz 62cca9a
Add the Finish decision and per-event defaults for meta search
zayenz 9840098
Keep hub branchers from taking the ids of spoke branchers
zayenz 2af7674
Delete the spoke when spoke() throws at a restart
zayenz ee6cba4
Test an exception from an asset of portfolio search
zayenz 035f646
Advance the repeated generator of Cutoff::repeat()
zayenz 4595b12
Keep the restart budget of RBS within each worker and episode
zayenz f50d613
Report an incomplete search in the time mode of the driver
zayenz ad4cea1
Keep AStar and CABS exhausted when their stop object fires later
zayenz a88bf74
Forget the end reason of parallel DFS and BAB on reset
zayenz c13dffe
Count a worker that steals work before its victim can go idle
zayenz 66a1a3f
Run a single asset of a sequential portfolio without slices
zayenz d1bbca0
Keep the most important stop cause of a portfolio asset
zayenz d6a89cf
Check the end reason more strictly in search tests
zayenz 9f46950
Fix the accounting and launch of parallel portfolio assets
zayenz 040b349
Document the RBS hook calls and the PBS cutoff and statistics rules
zayenz 18e9024
Resume a parallel portfolio after a single limit
zayenz 4c0e82a
Declare the switchable stop of the search tests in every build
zayenz a0753c5
Keep sequential portfolio assets valid after one ends
zayenz 0632e34
Document the limits of Continue, cutoff copies and resuming
zayenz 16314f5
Record the final statistics of a portfolio asset outside the lock
zayenz 96696b3
Collect the statistics of other assets only for a portfolio stop
zayenz eb12d3c
Document which statistics the assets of a sequential portfolio contri…
zayenz 55abe96
Guard the shared stop information of a sequential portfolio
zayenz bdab736
Report CABS exhausted when it stops after its last solution
zayenz f8f9ff5
Leave the hub constraint of the PBS test to propagation
zayenz f1196fb
Say which solution a meta-search hook sees as the last one
zayenz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,194 @@ | ||
| # Gecode 7 migration notes | ||
|
|
||
| ## Meta-search hooks: master() and slave() are now hub() and spoke() | ||
| ## Meta-search hooks: hub() and spoke() take contexts | ||
|
|
||
| Rename the overrides. Their signatures and return values are unchanged: | ||
| The hooks `master()` and `slave()` and the class `MetaInfo` are replaced: | ||
|
|
||
| ```cpp | ||
| // Gecode 6 | ||
| bool master(const Gecode::MetaInfo& mi) override; | ||
| bool slave(const Gecode::MetaInfo& mi) override; | ||
|
|
||
| // Gecode 7 | ||
| bool hub(const Gecode::MetaInfo& mi) override; | ||
| bool spoke(const Gecode::MetaInfo& mi) override; | ||
| void hub(Gecode::HubContext& hc) override; | ||
| void spoke(Gecode::SpokeContext& sc) override; | ||
| ``` | ||
|
|
||
| There are no compatibility aliases. An old override marked `override` fails | ||
| to compile; one without it compiles but is never called. Restart-based search (RBS) and portfolio-based search | ||
| (PBS) call the renamed hooks at the same points and with the same defaults | ||
| as before. | ||
| There are no compatibility aliases. `MetaInfo` no longer exists, so an old | ||
| override fails to compile. Restart-based search (RBS) calls `hub()` on its | ||
| hub and `spoke()` on each spoke, a clone of the hub that one episode | ||
| searches. Portfolio-based search (PBS) calls `hub()` once and `spoke()` on | ||
| the spoke of each asset. | ||
|
|
||
| The hooks run on these spaces: | ||
| Both contexts provide what `MetaInfo` provided: | ||
|
|
||
| - RBS calls `hub()` after each solution and at each restart. The hub | ||
| carries the last solution and the no-goods from one restart to the next. | ||
| RBS calls `spoke()` on each new spoke, a clone of the hub, including the | ||
| first. The default `hub()` constrains the hub with the last solution, if | ||
| any, and posts the no-goods. | ||
| - PBS calls `hub()` once, then calls `spoke()` with the asset number on the | ||
| spoke of each asset, the hub or a clone of it. The default `hub()` | ||
| removes all branchers, so `spoke()` must post the branching of each | ||
| asset. | ||
| | Gecode 6 | Gecode 7 | | ||
| |----------------------------------------|----------------------------------------------------| | ||
| | `mi.type()`: `RESTART`, `PORTFOLIO` | `engine()`: `MetaEngine::Restart`, `Portfolio` | | ||
| | `mi.reason()`: `RR_INIT` | `event()`: `MetaEvent::Start` | | ||
| | `RR_SOL` | `MetaEvent::Solution` | | ||
| | `RR_LIM` | `MetaEvent::Limit` | | ||
| | `RR_CMPL` | `MetaEvent::Exhausted` | | ||
| | (none) | `MetaEvent::Incomplete`, such as LDS at its limit | | ||
| | `RR_NO` (portfolio) | `MetaEvent::Start` | | ||
| | `mi.restart()` | `episode()` | | ||
| | `mi.fail()` | `statistics().fail` | | ||
| | `mi.solution()` | none: `event()` tells whether there was a solution | | ||
| | `mi.last()` | `last()` | | ||
| | `mi.nogoods()` | `nogoods()` | | ||
| | `mi.asset()` | `asset()`, and `assets()` for their number | | ||
|
|
||
| `episode()` counts from zero and increases by one for every new spoke, | ||
| whatever ended the previous episode. In `hub()` it is the episode that | ||
| ended, in `spoke()` the episode that starts. `statistics()` holds the | ||
| statistics of the episode that ended. `last()` is only valid while the hook | ||
| runs; clone the solution to keep it. | ||
|
|
||
| The return values become explicit decisions: | ||
|
|
||
| | Gecode 6 | Gecode 7 | | ||
| |----------------------------------------|--------------------------------------------------------| | ||
| | `master()` returns `true` | `hc.decision(MetaDecision::Restart)`, the default | | ||
| | `master()` returns `false` after a solution | `hc.decision(MetaDecision::Continue)` | | ||
| | (none) | `hc.decision(MetaDecision::Continue)` after a limit | | ||
| | (none) | `hc.decision(MetaDecision::Finish)` | | ||
| | `slave()` returns `true` | nothing, `SpokeCoverage::Full` is the default | | ||
| | `slave()` returns `false` | `sc.coverage(SpokeCoverage::Partial)` | | ||
| | (none) | `sc.coverage(SpokeCoverage::Reduced)` | | ||
|
|
||
| `Continue` is only legal after `MetaEvent::Solution` and `MetaEvent::Limit`; | ||
| setting it for another event throws `IllegalMetaDecision`. `Finish` ends the | ||
| engine with `EndReason::Incomplete`. To prove that no further solution | ||
| exists, fail the hub. | ||
|
|
||
| The coverage tells the engine what a spoke covers of the hub's search space: | ||
|
|
||
| - `Full`: the spoke adds only branching and constraints that the hub | ||
| implies. Exhausting it is a proof, and its no-goods hold in the hub. | ||
| - `Reduced`: the spoke prunes solutions but keeps one, or an optimal one, if | ||
| any exists, such as symmetry breaking. Exhausting it is a proof, but its | ||
| no-goods do not hold in the hub. Search for all solutions misses the | ||
| solutions that the spoke prunes. | ||
| - `Partial`: the spoke searches part of the hub's search space, such as a | ||
| large neighbourhood. Exhausting it is no proof, and its no-goods do not | ||
| hold in the hub. | ||
|
|
||
| The engine trusts the declared coverage. A spoke that declares more than it | ||
| covers, such as `Full` for a spoke that removes solutions, gives undefined | ||
| results. | ||
|
|
||
| `nogoods()` is empty unless the spoke of the episode that ended was `Full`. | ||
| PBS honours the coverage of each asset: an asset whose `Partial` spoke | ||
| exhausts is dropped instead of ending the portfolio. | ||
|
|
||
| Other changes to the hooks: | ||
|
|
||
| - RBS calls `hub()` with `MetaEvent::Start` before it clones the first | ||
| spoke. Gecode 6 did not call `master()` then. | ||
| - For a best solution engine such as `RBS<T, BAB>`, the engine constrains | ||
| the hub with the last solution before it calls `hub()`. The default | ||
| `hub()` no longer calls `constrain()`, and an override that does not call | ||
| the default keeps the bound. For other engines, such as `RBS<T, DFS>`, | ||
| RBS no longer calls `constrain()` at all. | ||
| - After an episode that ends without a proof, such as LDS at its | ||
| discrepancy limit, RBS calls `hub()` with `MetaEvent::Incomplete`. By | ||
| default, it finishes when the spoke was `Full` or `Reduced`, as a new | ||
| spoke would repeat the same search, and restarts when it was `Partial`. | ||
| Both `Restart` and `Finish` are legal. | ||
| - PBS calls `status()` on the hub after `hub()`, so `hub()` can post | ||
| constraints. In Gecode 6, cloning such a hub threw `SpaceNotStable`. | ||
| - The default PBS `hub()` still removes all branchers, so `spoke()` must post | ||
| the branching of each asset. When the hub had branchers but a spoke has | ||
| none after `spoke()`, PBS throws `Search::SpokeNoBrancher` instead of | ||
| returning the unassigned spoke as a solution. | ||
|
|
||
| The examples show typical overrides: | ||
|
|
||
| - `examples/crossword.cpp`: a `hub()` that posts no-goods and continues | ||
| after a solution instead of restarting. | ||
| - `examples/photo.cpp`: an RBS `spoke()` that relaxes the last solution for | ||
| large neighbourhood search. | ||
| large neighbourhood search and declares `SpokeCoverage::Partial`. | ||
| - `examples/qcp.cpp`: a PBS `spoke()` that posts a different branching for | ||
| each asset. | ||
|
|
||
| ## Cutoff generators implement copy() | ||
|
|
||
| `Search::Cutoff` has a new pure virtual member function: | ||
|
|
||
| ```cpp | ||
| virtual Gecode::Search::Cutoff* copy(void) const; | ||
| ``` | ||
|
|
||
| It returns a copy of the generator in its current state that continues the | ||
| sequence on its own. A copy of `Cutoff::rnd()` uses a different seed, so | ||
| the assets can restart at different times (unless every value of the range | ||
| is the same). A portfolio of restart-based engines, `PBS<T, RBS>`, gives | ||
| each asset its own copy of the cutoff in its options and deletes the | ||
| original once the portfolio is built. A portfolio of a single asset whose | ||
| spoke does not declare `SpokeCoverage::Partial` needs no portfolio engine | ||
| and passes the cutoff itself to that asset. | ||
| In Gecode 6.6, the assets drew their values from one shared cutoff sequence. | ||
|
|
||
| A custom cutoff generator must implement `copy()`. For a generator whose | ||
| state is plain data, the copy constructor suffices: | ||
|
|
||
| ```cpp | ||
| Gecode::Search::Cutoff* | ||
| MyCutoff::copy(void) const { | ||
| return new MyCutoff(*this); | ||
| } | ||
| ``` | ||
|
|
||
| A generator that owns other generators copies them with their own | ||
| `copy()`. | ||
|
|
||
| ## stopped() is replaced by end_reason() | ||
|
|
||
| `Search::Engine::stopped()` and `Search::Base<T>::stopped()` are removed, | ||
| and so is the experimental `limited()`. After `next()` returns no solution, | ||
| `end_reason()` tells why: | ||
|
|
||
| ```cpp | ||
| enum class Gecode::Search::EndReason : unsigned char { | ||
| NotEnded, Exhausted, Incomplete, Limit | ||
| }; | ||
| ``` | ||
|
|
||
| | Gecode 6 | Gecode 7 | | ||
| |-----------------------------------------------|-------------------------------------------------| | ||
| | `stopped()` is true | `end_reason() == EndReason::Limit` | | ||
| | `stopped()` is false after no solution | `end_reason() == EndReason::Exhausted` or `EndReason::Incomplete` | | ||
| | `limited()` is true (AStar, CABS) | `end_reason() == EndReason::Incomplete` | | ||
| | last `next()` returned a solution | `end_reason() == EndReason::NotEnded` | | ||
|
|
||
| `Exhausted` means that the engine explored everything it was asked to | ||
| explore: there is no further solution, and the last solution of a | ||
| branch-and-bound search is optimal. `Incomplete` means that the engine ended | ||
| on its own without that proof, for example limited discrepancy search at its | ||
| discrepancy limit or CABS at its width limit. Calling `next()` again does not | ||
| continue an incomplete search. `Limit` means that a stop object stopped the | ||
| engine, and calling `next()` again continues the search. | ||
|
|
||
| Code that used `!stopped()` as a proof, such as reporting optimality, should | ||
| test for `EndReason::Exhausted`. Code that resumes a search after a limit | ||
| should test for `EndReason::Limit`, and first lift the limit: a stop object | ||
| that still fires, such as an expired `TimeStop`, stops the search again | ||
| right away. Reset the `TimeStop` or raise the limit of a `NodeStop` or | ||
| `FailStop` before calling `next()` again. | ||
|
|
||
| ## Portfolio stop objects see the whole portfolio | ||
|
|
||
| The stop object in the options of `PBS` is now checked with the statistics | ||
| of the whole portfolio, the sum over all assets. In Gecode 6, it was checked | ||
| for each asset with the statistics of that asset, so a failure limit of | ||
| `n` for a portfolio of `k` assets allowed up to `k * n` failures. A stop | ||
| object that should limit each asset on its own belongs in the options of an | ||
| engine builder: | ||
|
|
||
| ```cpp | ||
| Gecode::Search::Options a, b; | ||
| a.stop = &dfs_stop; | ||
| b.stop = &lds_stop; | ||
| Gecode::SEBs sebs({Gecode::dfs<Model>(a), Gecode::lds<Model>(b)}); | ||
| Gecode::PBS<Model> engine(model, sebs, portfolio_options); | ||
| ``` |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.