Skip to content

Rank solutions with Space::compare in best-solution search - #242

Draft
zayenz wants to merge 15 commits into
mainfrom
feature/comparison
Draft

zayenz wants to merge 15 commits into
mainfrom
feature/comparison

Conversation

@zayenz

@zayenz zayenz commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Adds a read-only Space::compare() that ranks two solutions as better, equivalent, worse, or incomparable. Every space used for optimization must now implement both constrain() and compare(). constrain() still posts the improvement restriction; compare() decides which of two solutions to keep. The default compare() throws SpaceNoComparison.

Engines:

  • Sequential BAB and RBS: when an external solution arrives through constrain, compare() decides whether it replaces the incumbent.
  • Parallel BAB and PBS portfolios: every solution is compared with the retained incumbent. Only SC_BETTER replaces it, so equivalent and worse solutions are dropped. If compare() throws, the exception reaches the caller, and the engine has to be deleted.
  • A* and CABS (experimental): compare() decides which solutions become the incumbent. The guidance bound still orders and prunes open nodes.
  • All engines reject incomparable solutions with Search::Incomparable.

Models and helpers:

  • Gecode::Sense (minimize, maximize) is a shared optimization direction. compare_int(x, y, sense) compares two integer objective values, so an integer compare() is one line, like constrain().
  • The experimental HeuristicGuidance now uses Gecode::Sense instead of its own MINIMIZE/MAXIMIZE enum.
  • The MiniModel integer, lexicographic and float optimization spaces, FlatZinc and car-sequencing implement compare(). Float spaces compare the bound their cuts use, ignoring the step.

Tests:

  • Comparison tests cover the engines, portfolios, external incumbents, failure transport, FlatZinc and compare_int.
  • RBS and worker-control tests had relied on BAB enumerating equal solutions, which no longer happens. They now check strict improvement.
  • Static counters shared across tests caused races under the concurrent harness. Each test now has its own counter.

Verified locally on macOS: search and FlatZinc tests pass in both the default and the experimental build, and the doc target builds.

Before this leaves draft, .zdev/ will be dropped from the branch.

@zayenz zayenz left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The one-argument CarSequencing::compare() hid the inherited Gist display overload. Added using Script::compare to restore the two-argument call.
  • Parallel PBS broadcast a solution before handling a stored worker failure. That could call into a failed asset and replace the original exception. The failure guard now runs before solution processing.

@zayenz
zayenz force-pushed the feature/comparison branch from fdd5080 to 08b56e6 Compare October 8, 2026 15:15
Zdev-Change-Id: Zd450758a16d392690607cf153a5160083ad5c3a5cd6812f461a16610075fc80a
…iness

Zdev-Change-Id: Z5c772894bb48c0852974820982b13020d663b002850618c6bcba63a53e9e4571
Zdev-Change-Id: Zd3bd5210f7a14908a3b4cf47a040ce93d4488f82ec178872c8b90824895e3f87
Zdev-Change-Id: Z1c007f6a8f418dab7835ce3c161f32811819842b08897f39166326aacd7afcb5
@zayenz
zayenz force-pushed the feature/comparison branch from 65e455e to 5aece80 Compare November 3, 2026 12:04
@zayenz zayenz changed the title Provisional: non-mutating solution comparison for Gecode 7 (breaking changes) Rank solutions with Space::compare in best-solution search (Gecode 7, ABI break) Nov 3, 2026
@zayenz zayenz changed the title Rank solutions with Space::compare in best-solution search (Gecode 7, ABI break) Rank solutions with Space::compare in best-solution search Nov 3, 2026
@zayenz
zayenz force-pushed the feature/comparison branch from 5aece80 to 9c72d67 Compare November 3, 2026 13:34
zayenz added 11 commits November 3, 2026 16:41
Zdev-Change-Id: Z87d7de4220478ed2e6d58d55f4648cde323acfbbb28ecb589c39215a802aeb03
Zdev-Change-Id: Z738bbca9dd306371480ab382cbd9492a52cd416d460e53b9512a5f83e57476d7
Zdev-Change-Id: Zc9f2540cb25a8b2bc131505b4314c6ea435ced462e808cb28c0b3f57b66f8f34
Arbitrate candidates and external incumbents with non-mutating comparison, invalidate superseded queued results, and deliver comparison failures safely through next().

Preserve restart support by clearing failure state during reset, with focused parallel BAB regressions.

Zdev-Change-Id: Z7926867238a6c0cfb64f226c42bf1df0d6994fedf653be929d33ef60ec652f92
Use non-mutating comparison for PBS incumbent arbitration and safely return collector or nested-asset failures after portfolio workers quiesce.

Add mixed portfolio regressions and document model-defined comparability, float ranking, migration, and the possible future best-effort incomparability policy.

Zdev-Change-Id: Ze012cd6e1d4ae7aebf1483d8aabd40f2204a99b09907e93c1a7e61d6dfc7b911
Zdev-Change-Id: Z4e4e39fd1665c0addf3e5726ab9bfb5ef3c6d49a7ca7b636d665bb672dccf5c5
Zdev-Change-Id: Z779d79cd0461e169a13d69dddf214ef27fe9499b996e28b9f44c29b66ff7cb97
Parallel BAB now discards solutions that compare as equivalent, so BAB
tests can no longer enumerate all solutions of a model without an
objective. The restart and worker-control pause tests now give BAB a
lexicographic objective and check for improving solutions ending with the
best one. The restart test model tightens its bound on the last solution
when it has an objective.

The comparison tests counted spaces and posted constraints in static
counters shared by tests that the harness runs concurrently. Give each
test its own atomic counter instead.
A* and CABS chose between solutions by their guidance bound, unlike the
other best-solution engines and the portfolios they can run in. They now
replace the incumbent only when Space::compare reports SC_BETTER, both
for their own solutions and for external incumbents, and report
incomparable and missing comparisons like BAB. Parallel workers pass
solutions that tie with the incumbent bound on to comparison. The bound
still orders and prunes open nodes.
Space::compare now says what compare returns, how it must agree with
constrain, and what the default does, at about the length of the constrain
documentation. Model-specific ranking stays with the MiniModel and FlatZinc
classes. The BAB and PBS notes and the changelog entry drop the repeated
and speculative parts.
Implementing Space::compare for an integer objective took four lines of
value comparisons, against a single rel call in constrain. compare_int
compares two values for a Sense, an optimization direction now shared by the
kernel, MiniModel, FlatZinc, and the experimental heuristic guidance, which
had its own MINIMIZE/MAXIMIZE enum.
@zayenz
zayenz force-pushed the feature/comparison branch from 9c72d67 to 2fdfdc9 Compare November 3, 2026 16:17

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