Getting the optimal solution

Let us consider the following optimization problem:

using JuMP, Ipopt
function Opti_model(A,b)
    m = Model(with_optimizer(Ipopt.Optimizer))
    @variable(m,x[1:5],lower_bound=0,upper_bound=1)
    @objective(m,Max,sum(A[i,j]*x[i]*x[j] for i=1:5, j=1:5)+sum(c[i]*x[i] for i=1:5))
    JuMP.optimize!(m)
    return (getvalue(x))
end
B = rand(5,5).*2 .- 1
c = rand(5,1)
Primal_sol = Opti_model(B'*B,c)

There is an obvious bug using

getvalue()

This does not work with JuMP 0.19, so I find the following format:

JuMP.value(x[i])

If we use the above solution, then we need to run a loop and also need an extra variable to store the values. Is there any other efficient way to do this?

Does “dot” syntax work?

JuMP.value.(x)
1 Like

See Query Solutions · JuMP

1 Like