refactor: split the backtrack engine into focused collaborators#948
Merged
Conversation
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.
What changed
Decompose the backtrack
BacktrackSolver/engine monolith into focused, single-responsibility pieces. Seven commits, each behavior-preserving:private inner class ResumableMinimize) out ofBacktrackSolverinto its own top-levelinternal class.BacktrackSolver(976 lines) becomes a ~245-lineSolver/Optimizerfacade; the engine takes the solver via its constructor.PhaseSaving(phase-saving + target-phasing + rephase schedule), shared by the satisfaction path (driveSearch) and the engine — removing the duplicated phase logic and the loose array threading throughapplyPhase/capturePhase/backjumpAndLearn.DeadlinePoller(the adaptive cancel-check cadence), also shared by both paths.RestartController(Luby/Glucose restart policy + the Luby math), shared by both paths.PortfolioBoundExchange(level-0 cross-arm objective-floor and variable-bound sharing).runUntilEventloop body into nameddescendStep/backtrackStepmethods.The incumbent state (
best/bestObj/objVarBest) stays in the engine by design: it is read across pruning, both terminal builders, and the leaf handler, so hiding it behind a collaborator would be a leaky abstraction rather than an improvement.Why
BacktrackSolver.kt(52K) welded a thin API facade to a giant stateful search engine, and the phase/cancel/restart bookkeeping was duplicated between the satisfaction and optimize paths. Splitting them separates concerns and dedups the two drivers.Testing
Behavior-preserving throughout; covered by the existing backtrack/optimize suites, full
check lintDocsgreen across JVM + native + wasm. Benchmarked A/B (core suite, branch vs merge-base): identical solve outcomes, and wall-time differences within the run-to-run noise floor (the same binary swings ~230ms between repeats on these sub-second instances), i.e. no measurable regression.