Hi!
I am sorry, I can not produce a MWE but I think you can still answer my question.
I need to use JuMP heuristic callbacks. However, the documentation only gives an exemple for a single variable. I need to submit a heuristic solution for different matrices, vectors and Float64 values.
function call_back_benders_heuristic(cb_data)
vars_submit = JuMP.VariableRef[]
vars_improve_two_opt_submit = Bool[]
for i in V
for j in i+1:n
push!(vars_submit, x[i,j])
push!(vars_improve_two_opt_submit, x_improve_two_opt[i,j])
end
end
status = MOI.submit(
m, MOI.HeuristicSolution(cb_data),
[vars_submit; y; JuMP.VariableRef[offset, λ]] ,
[vars_improve_two_opt_submit; y_improve_two_opt; Float64[bar_offset_improve_two_opt, λ_improve_two_opt]])
println("Submitted a heuristic solution with status $status")
end
MOI.set(m, MOI.HeuristicCallback(), call_back_benders_heuristic)
# Earlier in my JuMP model
@variable(m, x[i=V, j=i+1:n], Bin)
@variable(m, y[i=V], Bin)
@variable(m, offset >= 0)
@variable(m, λ >= 0)
As you can see, I have, a matrix of Bool, x, a vector of Bool x and two Float64 variables, offset and λ. My problem is that I get
Submitted a heuristic solution with status HEURISTIC_SOLUTION_REJECTED
My guess is that [vars_improve_two_opt_submit; y_improve_two_opt; Float64[bar_offset_improve_two_opt, λ_improve_two_opt]] becomes an array of {Any} because there are both arrays of Bool and Float64
Please note that MOI.submit:
status = MOI.submit(
m, MOI.HeuristicSolution(cb_data),
[vars_submit; y],
[vars_improve_two_opt_submit; y_improve_two_opt])
Works and give HEURISTIC_SOLUTION_ACCEPTED with the major flaw that my two Float64 variables offset and λ do not get heuristically submitted!
Thanks a lot!