# Getting the optimal solution

**URL:** https://discourse.julialang.org/t/getting-the-optimal-solution/21167
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [February 25, 2019, 7:53am UTC](https://discourse.julialang.org/t/getting-the-optimal-solution/21167 "2019-02-25T07:53:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Rajat\_Sanyal](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@Rajat\_Sanyal](https://discourse.julialang.org/u/Rajat_Sanyal)
#### Post date: [February 25, 2019, 7:53am UTC](https://discourse.julialang.org/t/getting-the-optimal-solution/21167/1 "2019-02-25T07:53:40Z")

</div>

Let us consider the following optimization problem:

```julia
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?

---

<div class="post-metadata">

### Author: ![ianfiske](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@ianfiske](https://discourse.julialang.org/u/ianfiske)
#### Post date: [February 25, 2019, 2:05pm UTC](https://discourse.julialang.org/t/getting-the-optimal-solution/21167/2 "2019-02-25T14:05:05Z")

</div>

Does “dot” syntax work?

```julia
JuMP.value.(x)

```

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [February 25, 2019, 2:22pm UTC](https://discourse.julialang.org/t/getting-the-optimal-solution/21167/3 "2019-02-25T14:22:13Z")

</div>

See [Query Solutions · JuMP](http://www.juliaopt.org/JuMP.jl/v0.19/solutions/#Obtaining-solutions-1)
