Accessing solver from BestBoundCallback in CP-SAT

56 views
Skip to first unread message

Patrik Mandelin

unread,
Oct 31, 2025, 7:35:33 AMOct 31
to or-tools-discuss
Hi,
I am trying to do a more advanced monitoring of relative gap in the solver, to terminate when the gap is small and we have a slow evolution of the gap.

Doing so in a CpSolverSolutionCallback works just fine, since we have full access to the solver parameters.
However, since I have more frequent updates of bound, i wish to implement the same logic in the bound callback.

This is where I have problems trying to access the `solver.objectiveValue()`.
A reference to 'solver' has been passed to the class managing the callback (which is a plain Consumer<Double> in java), but calling objectiveValue() generates error:
`Cannot invoke "com.google.ortools.sat.CpSolverResponse.getObjectiveValue()" because "this.solveResponse" is null`.

I am sure the solution is obvious to many of you, but I have had some frustrating days trying to progress this - any hints are highly appreciated.
Is there a way to access the objective from a bounds callback?

Cheers,
Patrik

Laurent Perron

unread,
Oct 31, 2025, 7:55:43 AMOct 31
to or-tools-discuss
No. You need to store it on your side. 

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/or-tools-discuss/c3cccc4f-5878-41b3-b57a-7d119bec9701n%40googlegroups.com.

Patrik Mandelin

unread,
Oct 31, 2025, 8:02:53 AMOct 31
to or-tools-discuss
Thank you - that is easily done.
But what about 'wall time' - then I presume this is not readily available in a bounds callback either?

Cheers,
Patrik

Laurent Perron

unread,
Oct 31, 2025, 11:41:07 AMOct 31
to or-tools-discuss
No, but you can use your own timer. 

--Laurent


Reply all
Reply to author
Forward
0 new messages