CPLEX.jl: how to call CPXcallbackgetinfoint?

Dear folks,

I try to call CPXcallbackgetinfoint within a callback but unfortunately fail to do so. From what I could extract from the source code of the CPLEX package, it should work something like this:

function myCallback( cb_data::CPLEX.CallbackContext )
    data_p = Ref{Cint}()
    ret = CPLEX.@cpx_ccall(callbackgetinfoint, Cint,
                                (Ptr{Cvoid}, Cint, Ref{Cint}),
                                 cb_data, 1, data_p) # "1" should correspond to CPXCALLBACKINFO_NODECOUNT
    mydata = data_p[]
    println("$mydata")
    
    do_something_else( cb_data )
    return 
end
MOI.set( model, MOI.UserCutCallback(), myCallback )     #"model" is a JuMP model 

Unfortunatly this throws an error stating MethodError(Base.unsafe_convert, ...).

Any ideas how to call such functions correctly? Thank you very much in advance!

I use:
JuMP.jl v0.21.2,
CPLEX.jl v0.6.5
MathOptInterface.jl v0.9.13
CPLEX 12.9

You need to pass cb_data.context to cpx_ccall instead of cb_data.

Note that you can access the full CPLEX generic callback if you use CPLEX.CallbackFunction() instead of MOI.UserCutCallback().

This isn’t really documented, but you can see an example here:

2 Likes