Call back with matrix

Hi, the following code fom Jump manual works a scalar value, x and x_val

x_val = callback_value(cb_data, x)
status = MOI.submit(
    model, MOI.HeuristicSolution(cb_data), [x], [floor(Int, x_val)]
)

how about submit a intere matrix without having to make a for loop?

I tried with coomplhension like

[u[i,j] for i in 1:gmax, j in 1:hmax]… but does not work
any hint or pointer to understand the behaviour?

Additionally how to get the current value of the OF? Before i was using MathProgBase.cbgetobj(cb)

Thank very much
Fabrizio

I think you should use vcat() for that. For instance, something like

vars = vcat( [model[:u][i,j] for i in 1:gmax for j in 1:hmax]  )
vals = vcat( u_vals[i,j] for i in 1:gmax for j in 1:hmax]  )
status = MOI.submit( model, MOI.HeuristicSolution(cb_data), vars, vals )
println("$status")

but I am not sure. Probably also reshaping helps (see here ). Regarding the objective function value: I always computed it manually with the current variable values.

1 Like

Thanks @mike_k, indeed the only issue was the that u_vars must be of type “sub::AbstractSubmittable”

so with the syntiax you suggested, and not the simple way i used before, the following code works fine:

        u_vars = [MyMod[:u][i,h] for i in 1:gmax for h in 1:hmax]
        u_vals = [u_vals[i,h] for i in 1:gmax for h in 1:hmax]
        status = MOI.submit(MyMod, MOI.HeuristicSolution(cb), u_vars, u_vals)

moreover it must be a Vector{VariableRef} if you pass a Matrix{VariableRef} again you get an error.

Again i did not find an equivalent for getting the Obj value in the callback with MOI, i do need it since i want to run the heur callback only until the solver (gurobi) did non find a primal solution

2 Likes

You could try to use a Gurobi-specific callback as given in the example of Gurobi.jl, and use the callback codes you need.
I neither found a MOI function for that.

2 Likes

The functionality in the generic callbacks is intentionally limited. Use a solver dependant callback instead

2 Likes