Skip to content

Add MIP solver callback for incumbent solutions#50

Open
ryantenney wants to merge 1 commit intojvail:masterfrom
ryantenney:mip-callback
Open

Add MIP solver callback for incumbent solutions#50
ryantenney wants to merge 1 commit intojvail:masterfrom
ryantenney:mip-callback

Conversation

@ryantenney
Copy link
Copy Markdown

This adds support to receieve notifications when the MIP solver finds a better feasible solution. The callback provides the objective value, solver status, and relative MIP gap. If you also need the full variable and row values, you can set solutions: true on the callback and call getSolution() from within the callback, otherwise we don't expend the effort to read the current status of all the decision variables. While this only supports IBINGO events at the moment, the GLPK reason code is passed through and all seven constants are exported, so additional events can be supported if desired later, though I have no idea if there is a good use case for supporting the others.

The web worker entry point needed updating too as it was only wired up for LP callbacks. Since functions can't be serialized across postMessage, the worker calls getSolution() on its side and the main thread wraps the result back up to keep the interface consistent.

Rebuilt wasm and dist are included. The additional Emscripten flags add 22 bytes to the binary.

Please let me know what you think, I'm perfectly happy to iterate on this with you.

Wire up GLPK's branch-and-cut callback so callers can get notified
when the solver finds a better integer feasible solution. Passes through
the current objective value, variables, and relative MIP gap on each
IBINGO event. Also extract get_mip_vars into its own helper since we
now need it in two places.
@jvail
Copy link
Copy Markdown
Owner

jvail commented Mar 15, 2026

Hallo @ryantenney, sorry for the late reply - seems I do not get notified by email for PRs. I'll look into it.

@jvail
Copy link
Copy Markdown
Owner

jvail commented Mar 22, 2026

Thank you for the proposed changes @ryantenney. I have looked into it and it will break one of the examples:

objEl.textContent = p.z;

I don't think it is a big deal to add this tiny breaking change to a 5.1 release. But maybe we could add an example for a MIP that runs for a while and displays callback results in a meaningful way. Do you have any useful MIP problem that could illustrate the feature? I'd be grateful if you could sketch/provide one.

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.

2 participants