Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cpp/src/branch_and_bound/branch_and_bound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2691,6 +2691,9 @@ mip_status_t branch_and_bound_t<i_t, f_t>::solve(mip_solution_t<i_t, f_t>& solut
if (settings_.deterministic) {
queue_external_solution_deterministic(user_assignment, work_units);
} else {
if (settings_.solution_callback != nullptr) {
settings_.solution_callback(user_assignment, obj);
}
Comment on lines +2694 to +2696

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Unconditional solution_callback invocation bypasses the incumbent-improvement/feasibility gate used elsewhere.

Every other call site (repair_heuristic_solutions, add_feasible_solution) only invokes settings_.solution_callback after confirming the solution actually improves the incumbent (improves_incumbent(...)) and is feasibility-checked. Here the callback fires unconditionally for any CPUFJ improvement, before set_solution_from_heuristics validates feasibility via check_guess. Since the callback drives dm->rins.new_best_incumbent_callback, which is documented/named to represent a genuine new best incumbent, this can report non-improving or not-yet-validated solutions to RINS/population, polluting downstream state.

🐛 Proposed fix to gate the callback on actual incumbent improvement
       } else {
-        if (settings_.solution_callback != nullptr) {
-          settings_.solution_callback(user_assignment, obj);
-        }
+        if (settings_.solution_callback != nullptr && improves_incumbent(obj)) {
+          settings_.solution_callback(user_assignment, obj);
+        }
         set_solution_from_heuristics(user_assignment);
       }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (settings_.solution_callback != nullptr) {
settings_.solution_callback(user_assignment, obj);
}
if (settings_.solution_callback != nullptr && improves_incumbent(obj)) {
settings_.solution_callback(user_assignment, obj);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/src/branch_and_bound/branch_and_bound.cpp` around lines 2694 - 2696, The
`solution_callback` call in `branch_and_bound.cpp` is firing too early inside
the CPUFJ improvement path. Update this branch to mirror the gating used in
`repair_heuristic_solutions` and `add_feasible_solution`: only invoke
`settings_.solution_callback` after `improves_incumbent(...)` succeeds and the
candidate has passed feasibility validation through
`set_solution_from_heuristics`/`check_guess`. Keep the callback aligned with a
genuine new incumbent so `dm->rins.new_best_incumbent_callback` is only notified
for validated incumbent improvements.

set_solution_from_heuristics(user_assignment);
}
};
Expand Down
11 changes: 11 additions & 0 deletions cpp/src/mip_heuristics/solver.cu
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,17 @@ solution_t<i_t, f_t> mip_solver_t<i_t, f_t>::run_solver()
sol = dm.run_solver();
} // implicit barrier for all tasks created in B&B and heuristics

if (!context.settings.heuristics_only && branch_and_bound->has_solver_space_incumbent()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? The callback already registers it on the heuristic thread, right? Is it because of the different thread completion orders?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not, I added this to err on the safe side in case future additions neglect to run the gpu heuristic callback

solution_t<i_t, f_t> branch_and_bound_sol(*context.problem_ptr);
branch_and_bound_sol.copy_new_assignment(branch_and_bound_solution.x);
branch_and_bound_sol.compute_feasibility();

if (branch_and_bound_sol.get_feasible() &&
(!sol.get_feasible() || branch_and_bound_sol.get_objective() < sol.get_objective())) {
sol = std::move(branch_and_bound_sol);
}
}

if (!context.settings.heuristics_only) {
if (branch_and_bound_solution.lower_bound > -std::numeric_limits<f_t>::infinity()) {
context.stats.set_solution_bound(
Expand Down
Loading