Submitted arrays of different types in JuMP Heuristic Callbacks

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!

1 Like

Even though the variable are Bin, you need to pass the Float64 values 0.0 or 1.0. The solver doesn’t use true and false internally.

I don’t have your full code, so I couldn’t test to check this works, but you probably want something like:

function call_back_benders_heuristic(cb_data)
    vars_x = JuMP.VariableRef[]
    solution_x = Bool[]
    for i in V
        for j in i+1:n
            push!(vars_x, x[i,j])
            push!(solution_x, x_improve_two_opt[i,j])
        end
    end
    status = MOI.submit(
        m, 
        MOI.HeuristicSolution(cb_data), 
        vcat(vars_x, y, offset, λ),
        vcat(
            convert(Vector{Float64}, solution_x),
            convert(Vector{Float64}, y_improve_two_opt),
            bar_offset_improve_two_opt,
            λ_improve_two_opt,
        )
    println("Submitted a heuristic solution with status $status")
end
1 Like

That worked! Thanks :slight_smile:

1 Like