How to get an optimal solution using JuMP in julia?

Viewed 145

I am using the JuMP package in julia with gurobi, and I can't seem to find any information online about how to print out an optimal solution. I can get the optimal objective value, but can't seem to find info on how to get an optimal solution. I tried solution_summary, but that gave me an error

1 Answers

Just use value(varname) such as:

m = Model(Gurobi.Optimizer);
@variable(m, x[1:2] >= 0)
@constraint(m, [1 2;3 4] * x .<= [10,20])
@objective(m, Max, [1,2]' * x )
optimize!(m)

and now:

julia> value.(x)
2-element Vector{Float64}:
 0.0
 5.0

Note that even if the model is MILP, the value will be always Float64 so usually you end up wanting to round it in some way or other.

Related