Repository navigation
feat: let the search callback stop the search - #37
Merged
Merged
Conversation
The SearchEvent callback now returns ControlFlow<()>. Break ends the descent or guided search at once, keeps the best solution, and still reports Done. Construction ignores it: no solution exists before every node is placed. Guided search now fires GuidedRound every round, so a monitor gets a tick even when nothing improves. examples/early_stop stops once no gain of 1% or more lands for 2 seconds. Breaking: callbacks must return ControlFlow::Continue(()) to go on.
thiagomoretto
marked this pull request as ready for review
October 8, 2026 14:02
Construction keeps a plain observer: it cannot stop, so its type no longer pretends it can. solve_with reads a Break on FirstSolution and skips the improvement phase. One stop closure in descend, a bool in GLS instead of a ControlFlow carried across rounds, and the example runs on X-n101-k25 through cvrplib instead of a hand-rolled instance.
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.
The
SearchEventcallback becomes a search monitor. Forsolve_with,local_search_withandguided_local_search_withit returnsControlFlow<()>;Breakstops the search, keeps the best solution, and still reportsDone.GuidedRound { iter, cost }event fires every round, so a monitor gets a tick even when nothing improves.FnMut(SearchEvent)observer: it cannot stop before every node is placed.solve_withreads aBreakonFirstSolutionand skips the improvement phase.examples/early_stop.rs: no built-in rule. On X-n101-k25, the example stops once no gain of 1% or more lands for 2 seconds (MIN_GAIN_PCT = 0gives plain "no improvement").Breaking: callbacks for
solve_with,local_search_withandguided_local_search_withmust now returnControlFlow::Continue(()).search_log()does this already.Tests:
monitor_stops_guided_search,monitor_stops_before_improving,monitor_stops_hill_climb.Known limit: GLS's first descent and each penalized descent run silent, so a stop lands between rounds, not inside one.