How to output the first integer solution found in B&B process in Mosek


I want to know how to output the first integer solution and its objective value found within B&B process in Mosek.

This should work with a solver-specific callback (which is called each time an integer solution is found). According to the readme in the Mosek.jl this functionality is wrapped. Unfortunately, I did not find an example how to do that with JuMP.

Yes, apparently you can call putcallbackfunc(t::MSKtask, f::Function)

The Mosek MOI wrapper in MosekTools.jl does not have any special support for it so you’ll have to use JuMP.unsafe_backend:

optimizer = unsafe_backend(model) # Gives you a `MosekTools.Optimizer`
task = unsafe_backend(model).task # Gives you a `Mosek.MSKtask`
function my_callback(where::Callbackcode, dinf::Vector{Float64}, iinf::Vector{Int32}, liinf::Vector{Int64})
    # ...
putcallbackfunc(task, my_callback)

By careful that the mapping between the JuMP variables and the indices in the Mosek task may be a bit nontrivial. JuMP.optimizer_index gives you the MOI.VariableIndex associated to the MosekTools.Optimizer. So given a JuMP variable x, do

index = JuMP.optimizer_index(x) # Gives a `MOI.VariableIndex` corresponding to the index in `optimizer`
col = MosekTools.mosek_index(optimizer, index) # Gives a `MosekTools.ColumnIndex`
col.value # Gives a `Int32` corresponding to the column in `task`

Let us know how it goes, we could add MOI attributes in MosekTools to make this easier

1 Like