# "Getvalue" and "JuMP.value" -\> collection JuMP decision variables

**URL:** <https://discourse.julialang.org/t/getvalue-and-jump-value-collection-jump-decision-variables/30510>\
**Category:** General Usage\
**Tags:** jump\
**Created:** [October 30, 2019, 6:23pm UTC](https://discourse.julialang.org/t/getvalue-and-jump-value-collection-jump-decision-variables/30510 "2019-10-30T18:23:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![baprata](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baprata/32/204269_2.png) [@baprata](https://discourse.julialang.org/u/baprata)\
**Post date:** [October 30, 2019, 6:23pm UTC](https://discourse.julialang.org/t/getvalue-and-jump-value-collection-jump-decision-variables/30510/1 "2019-10-30T18:23:37Z")

</div>

I have the following decision variables in JuMP:  
@variable(model, x[j in positions, k in orders, i in machines], Bin)  
@variable(model, D[i in machines, j in positions] \>=0)

The functions “getvalue” or “JuMP.value” are not collecting the values of decision variables after the CPLEX finds the global optimal solution. If the variable is a scalar, “getvalue” or “JuMP.value” are returning the value correctly. Is there another function for multi-dimensional variables?

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [October 30, 2019, 7:07pm UTC](https://discourse.julialang.org/t/getvalue-and-jump-value-collection-jump-decision-variables/30510/2 "2019-10-30T19:07:19Z")

</div>

This should be possible with

```julia
x_vals = getvalue( model[:x] )

```

and you should be able to access the values by their coordintates `x_vals[j,k,i]`.

Note that in JuMP 0.18 the function `getvalue()` returns type `::Any` which slows your code down if you access the values often, e.g., in a callback.

EDIT: at least this works in JuMP 0.18, and I did not test it with newer versions

---

<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:** [October 30, 2019, 7:55pm UTC](https://discourse.julialang.org/t/getvalue-and-jump-value-collection-jump-decision-variables/30510/3 "2019-10-30T19:55:01Z")

</div>

See the `Info` box in [Query Solutions · JuMP](https://www.juliaopt.org/JuMP.jl/v0.20.0/solutions/#Obtaining-solutions-1).

---

<div class="post-metadata">

**Author:** ![baprata](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baprata/32/204269_2.png) [@baprata](https://discourse.julialang.org/u/baprata)\
**Post date:** [October 31, 2019, 1:26pm UTC](https://discourse.julialang.org/t/getvalue-and-jump-value-collection-jump-decision-variables/30510/4 "2019-10-31T13:26:40Z")

</div>

> [@mike\_k](#):
>
> x\_vals = getvalue( model[:x] )

Dear Mik, thank you very much for your attention. Unfortunately,  
x\_vals = getvalue( model[:x] ) returns LoadError: MethodError: no method matching in my Julia.

---

<div class="post-metadata">

**Author:** ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)\
**Post date:** [October 31, 2019, 1:38pm UTC](https://discourse.julialang.org/t/getvalue-and-jump-value-collection-jump-decision-variables/30510/5 "2019-10-31T13:38:23Z")

</div>

Hey,  
what are your julia and JuMP versions?

---

<div class="post-metadata">

**Author:** ![baprata](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baprata/32/204269_2.png) [@baprata](https://discourse.julialang.org/u/baprata)\
**Post date:** [October 31, 2019, 1:40pm UTC](https://discourse.julialang.org/t/getvalue-and-jump-value-collection-jump-decision-variables/30510/6 "2019-10-31T13:40:31Z")

</div>

> [@baprata](#):
>
> @variable(model, x[j in positions, k in orders, i in machines], Bin)  
> @variable(model, D[i in machines, j in positions] \>=0)

Dear Odow,  
Thank you very much for your support.  
In this version the new sintax is:  
optimal\_solution = value.(x)  
println(optimal\_solution)

---

<div class="post-metadata">

**Author:** ![baprata](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baprata/32/204269_2.png) [@baprata](https://discourse.julialang.org/u/baprata)\
**Post date:** [October 31, 2019, 1:41pm UTC](https://discourse.julialang.org/t/getvalue-and-jump-value-collection-jump-decision-variables/30510/7 "2019-10-31T13:41:40Z")

</div>

> [@baprata](#):
>
> Dear Odow,  
> Thank you very much for your support.  
> In this version the new sintax is:  
> optimal\_solution = value.(x)  
> println(optimal\_solution)

Dear Joaquimg, the problems was solved (see chat with Odow). Thank you very much for your attention. Cheers
