Skip to content

Fix inverted observer return-value javadoc in addNewSolutionObserver#2

Merged
OscarSotoSanchez merged 1 commit into
mainfrom
docs/fix-observer-return-javadoc
Jul 19, 2026
Merged

Fix inverted observer return-value javadoc in addNewSolutionObserver#2
OscarSotoSanchez merged 1 commit into
mainfrom
docs/fix-observer-return-javadoc

Conversation

@OscarSotoSanchez

Copy link
Copy Markdown
Member

What

The method-level javadoc of BrkgaMpIpr.addNewSolutionObserver documented the observer's return value backwards. It said the observer returns true "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:

bool run = true;
while (run) {
    ...
    run &= callback(status);   // callback returns false -> run=false -> loop stops
}

So a callback returning false stops the optimization and true keeps it running. Verified empirically too (returning false cut 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"
  • native bridge brkga_bridge.cpp"non-zero to keep running (false stops the optimization)"
  • the MainComplete examples (single & multi) — return true; // Don't stop the optimization.
  • docs/GUIDE.md

Note

The inverted phrasing was inherited from the upstream C++ docs (codeurjc/brkga_mp_ipr_cpp), whose observer documentation contradicts its own run() loop in several spots. A separate issue there is worth filing.

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.
@OscarSotoSanchez
OscarSotoSanchez merged commit f53fc41 into main Jul 19, 2026
1 check passed
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