Skip to content

Add extensible random generators with reproducible stream splitting - #241

Draft
zayenz wants to merge 1 commit into
feature/meta-search-protocolfrom
feature/random
Draft

zayenz wants to merge 1 commit into
feature/meta-search-protocolfrom
feature/random

Conversation

@zayenz

@zayenz zayenz commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Randomized branching should make the same decisions regardless of how the search tree is explored. Previously, sharing mutable generator state meant cloning, recomputation, and parallel workers could drift apart, and reproducing a run from a printed state was not reliable.

This PR turns Rnd into a value type holding the complete state of a splittable generator, and splits that state wherever search branches. Cloning, recomputation, and parallel search then make identical random choices, and any printed state can be restored exactly.

Key changes

  • Rnd uses SplitMix by default, switches to xorshift64* when built with GECODE_RANDOM_ENGINE=xorshift64star, and supports custom engines through RndGenerator<Engine>. The seed constructor is now explicit (INT_VAL_RND(Rnd(42))).
  • Randomized selectors draw from a copy of their state and split it by the committed alternative, so choices do not need to store random state. Posting keys each selector by brancher id and role, and branchers with no random selectors skip the split.
  • RBS and PBS split each spoke's branchers by its episode or asset after Space::spoke() returns, so restarts and portfolio assets get distinct streams even when nested. Models that own a generator directly can split it with rnd.split(sc), as photo and FlatZinc now do for LNS. Copies of a random cutoff split their generator rather than reseeding it.
  • state() and state(text) replace seed(). The script drivers and FlatZinc accept -state, and gecode-test -replay accepts the state printed for a failing test.

Compatibility, overhead, and testing

Both the Rnd API and the sequences produced for a given seed change in this PR. Before rebasing onto #283, recomputation with random branching measured roughly 12% slower with SplitMix and 6% slower with xorshift64*. Also before the rebase, both engines passed check, all CTests, and the Search, Branch, Assign, FlatZinc, and NoGoods suites, and the fault-injection tests passed under ASan and UBSan.

This branch is a single commit on top of #283. After the rebase, the following pass:

  • Search: 25,872
  • check: 521
  • CTest: 8 of 8
  • FlatZinc: 152
  • Random: 40
  • Fault injection: 22 of 22

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
  4. Add extensible random generators with reproducible stream splitting #241 Splittable random generators ← this PR
  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

@zayenz zayenz changed the title Provisional: splittable random streams for Gecode 7 (breaking changes) Provisional: extensible random generators and splitting for Gecode 7 (breaking changes) Sep 10, 2026

@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.

  • RandomOption now stores validated state as Rnd and returns a copy, avoiding serialization and parsing in the accessor.
  • Documented selector hook buffer sizes, pointer advancement, capture timing, and restore/split behavior.
  • Completed override annotations in the two affected selector classes. This removes the missing-override warnings.

@zayenz zayenz changed the title Provisional: extensible random generators and splitting for Gecode 7 (breaking changes) Add extensible random generators with reproducible stream splitting Nov 3, 2026
Rnd becomes a value type holding the complete state of a splittable
engine, SplitMix by default, or any engine through RndGenerator<Engine>.
Its state can be printed and restored exactly, which drivers expose as
-state and the test harness uses for -replay.

Randomized selectors draw from a copy of their state and split it by the
committed alternative, so cloning, recomputation and parallel search make
the same decisions, and choices store no random state. Posting keys each
selector by brancher id and role. Branchers record whether any selector is
random and skip the split otherwise, so deterministic branching pays no
extra cost.

RBS and PBS split the branchers of every spoke by its episode or asset
after Space::spoke() returns, so spokes do not repeat each other, also
when nested. A model-owned generator is split with rnd.split(sc), as photo
and FlatZinc do for large neighbourhood search. Copies of a random cutoff
split its generator instead of reseeding it.

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