Skip to content
Merged
Show file tree
Hide file tree
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 Nov 19, 2026
5134431
Replace stopped() with end_reason()
zayenz Nov 19, 2026
7569d14
Report LDS at its discrepancy limit as incomplete
zayenz Nov 14, 2026
6f2a5af
End a portfolio when an asset exhausts its search space
zayenz Nov 14, 2026
c44af9e
Run every asset of a parallel portfolio
zayenz Nov 14, 2026
cfef78f
Check the portfolio stop object with portfolio-wide statistics
zayenz Nov 14, 2026
66750e7
Park a portfolio asset whose own stop object fires
zayenz Nov 14, 2026
b32b2f6
Replace MetaInfo with hub and spoke contexts
zayenz Nov 15, 2026
b9a62fb
Honour spoke coverage for no-goods and in portfolio search
zayenz Nov 19, 2026
911dfe4
Constrain the hub with each solution in the engine
zayenz Nov 19, 2026
f8b43da
Propagate the hub of portfolio search and require spoke branchers
zayenz Nov 19, 2026
62cca9a
Add the Finish decision and per-event defaults for meta search
zayenz Nov 19, 2026
9840098
Keep hub branchers from taking the ids of spoke branchers
zayenz Nov 19, 2026
2af7674
Delete the spoke when spoke() throws at a restart
zayenz Nov 19, 2026
ee6cba4
Test an exception from an asset of portfolio search
zayenz Nov 19, 2026
035f646
Advance the repeated generator of Cutoff::repeat()
zayenz Nov 19, 2026
4595b12
Keep the restart budget of RBS within each worker and episode
zayenz Nov 24, 2026
f50d613
Report an incomplete search in the time mode of the driver
zayenz Nov 24, 2026
ad4cea1
Keep AStar and CABS exhausted when their stop object fires later
zayenz Nov 24, 2026
a88bf74
Forget the end reason of parallel DFS and BAB on reset
zayenz Nov 24, 2026
c13dffe
Count a worker that steals work before its victim can go idle
zayenz Nov 24, 2026
66a1a3f
Run a single asset of a sequential portfolio without slices
zayenz Nov 24, 2026
d1bbca0
Keep the most important stop cause of a portfolio asset
zayenz Nov 24, 2026
d6a89cf
Check the end reason more strictly in search tests
zayenz Nov 24, 2026
9f46950
Fix the accounting and launch of parallel portfolio assets
zayenz Nov 24, 2026
040b349
Document the RBS hook calls and the PBS cutoff and statistics rules
zayenz Nov 24, 2026
18e9024
Resume a parallel portfolio after a single limit
zayenz Nov 25, 2026
4c0e82a
Declare the switchable stop of the search tests in every build
zayenz Nov 25, 2026
a0753c5
Keep sequential portfolio assets valid after one ends
zayenz Nov 25, 2026
0632e34
Document the limits of Continue, cutoff copies and resuming
zayenz Nov 25, 2026
16314f5
Record the final statistics of a portfolio asset outside the lock
zayenz Nov 25, 2026
96696b3
Collect the statistics of other assets only for a portfolio stop
zayenz Nov 25, 2026
eb12d3c
Document which statistics the assets of a sequential portfolio contri…
zayenz Nov 25, 2026
55abe96
Guard the shared stop information of a sequential portfolio
zayenz Nov 25, 2026
bdab736
Report CABS exhausted when it stops after its last solution
zayenz Nov 25, 2026
f8f9ff5
Leave the hub constraint of the PBS test to propagation
zayenz Nov 25, 2026
f1196fb
Say which solution a meta-search hook sees as the last one
zayenz Nov 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 146 additions & 3 deletions changelog.in
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,158 @@ Date: unreleased
[DESCRIPTION]
This is the development changelog for the next Gecode release.

[ENTRY]
Module: search
What: bug
Rank: minor
[DESCRIPTION]
Advance the generator that a cutoff generator from Cutoff::repeat()
repeats.
[MORE]
It read the current value of that generator without advancing it, so after
the first value it repeated the same value forever.

[ENTRY]
Module: search
What: bug
Rank: minor
[DESCRIPTION]
Delete the spoke of restart-based search when spoke() throws an exception at
a restart.

[ENTRY]
Module: search
What: bug
Rank: minor
[DESCRIPTION]
Do not let a brancher that hub() posts take the identity of a brancher that
spoke() posted earlier.
[MORE]
Restart-based search then posted the no-goods of that spoke for the wrong
brancher, which could lose solutions.

[ENTRY]
Module: search
What: change
Rank: minor
[DESCRIPTION]
Throw Search::SpokeNoBrancher when a spoke of portfolio search has no
brancher but the hub had branchers, unless the spoke failed.
[MORE]
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.

[ENTRY]
Module: search
What: bug
Rank: minor
[DESCRIPTION]
Propagate the hub of portfolio search after hub() and before cloning the
spokes.
[MORE]
A hub() that posted a constraint made the portfolio throw SpaceNotStable.

[ENTRY]
Module: search
What: bug
Rank: minor
[DESCRIPTION]
Constrain the hub of restart-based branch-and-bound search with each
solution in the engine itself.
[MORE]
The default hub() did it, so an override that did not call the default lost
the bound and found the same solutions again.

[ENTRY]
Module: search
What: change
Rank: minor
[DESCRIPTION]
Keep the other assets of a portfolio running when the stop object of an
engine builder stops its engine.
[MORE]
The whole portfolio stopped instead. The stopped asset is now parked until
the next call to next().

[ENTRY]
Module: search
What: change
Rank: minor
[DESCRIPTION]
Check the stop object of a portfolio with the statistics of the whole
portfolio.
[MORE]
It was checked for each asset with the statistics of that asset. See
docs/gecode-7-migration.md.

[ENTRY]
Module: search
What: change
Rank: minor
[DESCRIPTION]
Run every asset of a parallel portfolio, also when there are more assets
than threads.
[MORE]
Parallel portfolio search ran only as many assets as it had threads and
silently dropped the others.

[ENTRY]
Module: search
What: bug
Rank: minor
[DESCRIPTION]
End a portfolio when an asset exhausts its search space.
[MORE]
The exhausted asset proves that no further solution exists, so the other
assets no longer run until they are stopped. An asset whose spoke declares
SpokeCoverage::Partial is still dropped.

[ENTRY]
Module: search
What: change
Rank: minor
[DESCRIPTION]
Report limited discrepancy search at its discrepancy limit as incomplete.

[ENTRY]
Module: search
What: change
Rank: major
[DESCRIPTION]
Replace stopped() of search engines by end_reason().
[MORE]
end_reason() tells why next() returned no solution: EndReason::Exhausted is a
proof, EndReason::Incomplete is an end without one, and EndReason::Limit is a
stop. stopped() and the experimental limited() are removed. FlatZinc reports
optimality or unsatisfiability only for an exhausted search. See
docs/gecode-7-migration.md.

[ENTRY]
Module: search
What: change
Rank: major
[DESCRIPTION]
Give each restart-based asset of a portfolio its own copy of the cutoff.
Comment thread
zayenz marked this conversation as resolved.
Resolved
[MORE]
Cutoff has a new pure virtual function copy(), which custom cutoff generators
must implement. Copies of a random cutoff use different seeds, so the assets
can restart at different times. A portfolio with a single asset that does not
declare SpokeCoverage::Partial uses the cutoff itself. See
docs/gecode-7-migration.md.

[ENTRY]
Module: search
What: change
Rank: major
[DESCRIPTION]
Rename the meta-search Space hooks master() and slave() to hub() and spoke().
Replace the meta-search Space hooks master() and slave() and the class
MetaInfo by hub(HubContext&) and spoke(SpokeContext&).
[MORE]
There are no compatibility aliases. An old override marked override fails to
compile; one without it is never called. See docs/gecode-7-migration.md.
hub() sets a MetaDecision and spoke() declares a SpokeCoverage instead of
returning a Boolean. Restart-based search also calls hub() when search
starts and after an episode that ends without a proof. There are no
compatibility aliases, also not for the FlatZincSpace override of slave().
See docs/gecode-7-migration.md.

[ENTRY]
Module: search
Expand Down
191 changes: 172 additions & 19 deletions docs/gecode-7-migration.md
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);
```
15 changes: 8 additions & 7 deletions examples/crossword.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,14 @@ class Crossword : public Script {
<< ((a == 0) ? "<=" : ">") << " "
<< n;
}
/// Do not perform a restart when a solution is found
bool hub(const MetaInfo& mi) {
if (mi.type() == MetaInfo::RESTART)
// Post no-goods
mi.nogoods().post(*this);
// Do not perform a restart if a solution has been found
return false;
/// Post no-goods, and do not perform a restart when a solution is found
void hub(HubContext& hc) {
if (hc.engine() == MetaEngine::Restart) {
hc.nogoods().post(*this);
if (hc.event() == MetaEvent::Solution)
hc.decision(MetaDecision::Continue);
}
// For portfolio search, keep the branchers
}

/// Constructor for cloning \a s
Expand Down
Loading
Loading