Fix inverted observer return-value javadoc in addNewSolutionObserver#2
Merged
Merged
Conversation
The method-level javadoc claimed the observer returns true "if the
algorithm should stop immediately", which is backwards. The C++ core
run loop implements the opposite convention:
bool run = true;
while (run) {
...
run &= callback(status); // false -> run=false -> stop
}
So returning true keeps the optimization running and false stops it.
This matches NewSolutionObserver.onNewSolution's @return, the native
bridge comment ("non-zero to keep running"), the MainComplete examples,
and docs/GUIDE.md. Align the javadoc with the actual behavior.
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
The method-level javadoc of
BrkgaMpIpr.addNewSolutionObserverdocumented the observer's return value backwards. It said the observer returnstrue"if the algorithm should stop immediately", when the opposite is true.Why it's wrong
The C++ core run loop (
brkga_mp_ipr.hpp) drives the observer like this:So a callback returning
falsestops the optimization andtruekeeps it running. Verified empirically too (returningfalsecut the search right after the first improvement).The corrected wording now matches every other (correct) place in the repo:
NewSolutionObserver.onNewSolution@return— "true to keep running, false to stop"brkga_bridge.cpp— "non-zero to keep running (false stops the optimization)"MainCompleteexamples (single & multi) —return true; // Don't stop the optimization.docs/GUIDE.mdNote
The inverted phrasing was inherited from the upstream C++ docs (
codeurjc/brkga_mp_ipr_cpp), whose observer documentation contradicts its ownrun()loop in several spots. A separate issue there is worth filing.