what does the summary information in logfile for callback means
AnsweredHi,
I use a callback in my model and call another solver in it. After my problem is solved by Gurobi solver, at log output it mentions that
"User-callback calls 62, time in user-callback 2.76 sec"
I didn't understand what does it mean. I was wondering to know the interpretation of these numerical values.
Thanks
-
Hi Amir,
The number of calls tells you how many times your callback function has been called during the optimization. The reported time is the summed time spent over all calls of your callback function.
For example, you have a callback function \(\texttt{myCallback}\) which you pass to Gurobi via
m.optimize(myCallback)
The mentioned LOG line then tells you that your function \(\texttt{myCallback}\) has been called 62 times and Gurobi spent 2.76s in it during the whole optimization process. If you are interested in the number of calls to a particular part of your callback function, you can define a private counter variable
model._counter = 0
and increase it in your callback function
def myCallback(model,where):
# some code
model._counter += 1Best regards,
Jaromił0 -
Thanks for your response
I have added this model._counter to the callback, and when the model is solved, I print the value of it. However, it is not as same as the LOG value. Why it could happen?
0 -
Hi Amir,
Gurobi does not count every call, e.g., the POLLING callbacks are not counted. Thus, it is best to work with your own counter to determine the exact number of calls to your callback function.
Best regards,
Jaromił0 -
Hi,I want to know to define a private variable with Gurobi in Julia, just like:
model._counter = 0
0 -
Hi Jacob,
I assume you are using JuMP and are looking for a way to track some information across callbacks as we do in some of the Python example codes? Julia does not support dynamic attribute assignment the way Python does, so you'll need to define this variable in an enclosing scope. Here is a short example:
using JuMP, Gurobi
function solve()
# build your model
model = Model(Gurobi.Optimizer)
@variable(model, 0 <= x <= 10, Int)
@variable(model, 0 <= y <= 10, Int)
@constraint(model, x + y <= 5)
@objective(model, Max, x)
# create 'counter' in the outer scope so that the
# callback can access it
counter = 0
function callback(cb_data)
counter += 1
println("Lazy constraint callback")
end
MOI.set(model, MOI.LazyConstraintCallback(), callback)
# solve
optimize!(model)
println("Calls: ", counter)
end
solve()There is some further explanation given in this forum post (although, be aware that this is a few years old, so the JuMP API has changed) https://discourse.julialang.org/t/jump-solver-callback-arguments/13936/3
Is this what you are after?
Best regards,
Simon0
Please sign in to leave a comment.
Comments
5 comments