# Querying JuMP solutions - results out of order

**URL:** https://discourse.julialang.org/t/querying-jump-solutions-results-out-of-order/45301
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [August 21, 2020, 3:32am UTC](https://discourse.julialang.org/t/querying-jump-solutions-results-out-of-order/45301 "2020-08-21T03:32:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![fnbillimoria](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fnbillimoria/32/16518_2.png) [@fnbillimoria](https://discourse.julialang.org/u/fnbillimoria)
#### Post date: [August 21, 2020, 3:32am UTC](https://discourse.julialang.org/t/querying-jump-solutions-results-out-of-order/45301/1 "2020-08-21T03:32:01Z")

</div>

Hello,  
I have created a JuMP model, and wish to source and sort the results. The JuMP model is created via a call to a function with results stored as below. I wish to obtain results for a variable array called pg. However since the model creation is within a function, a direct call to the variable doesnt work (i.e. value(pg)) and hence i have extracted the variable values using the code below.

```julia
model = dc_dam_opf(pm_data)
set_optimizer(model,solver_mip)
result = optimize!(model)
vars_pg = model[:pg]
vals_pg = value.(vars_pg_t)

```

However, the variables are out of order i.e. 2,3,1 instead of 1,2,3 as you can see below. Is there any way to reorder these variables in the correct order so that when I reference them e.g. by calling vals\_pg[1,1] that I get the value of the correct variable (in this case vars\_pg[1,1] (currently I obtain the value for vars\_pg[2,1] because of the out-of-ordering). Thanks

```julia
julia> print(vars_pg)
2-dimensional DenseAxisArray{VariableRef,2,...} with index sets:
    Dimension 1, [2, 3, 1]
    Dimension 2, Base.OneTo(4)
And data, a 3×4 Array{VariableRef,2}:
 pg[2,1] pg[2,2] pg[2,3] pg[2,4]  
 pg[3,1] pg[3,2] pg[3,3] pg[3,4]  
 pg[1,1] pg[1,2] pg[1,3] pg[1,4]

```

---

<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: [August 21, 2020, 3:45am UTC](https://discourse.julialang.org/t/querying-jump-solutions-results-out-of-order/45301/2 "2020-08-21T03:45:49Z")

</div>

Please provide a reproducible example. How did you create `pg`?

For your example above, `vars_pg[1, 1]` will return the variable in the first column third row, not the first column first row.

---

<div class="post-metadata">

### Author: ![fnbillimoria](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fnbillimoria/32/16518_2.png) [@fnbillimoria](https://discourse.julialang.org/u/fnbillimoria)
#### Post date: [August 27, 2020, 7:06am UTC](https://discourse.julialang.org/t/querying-jump-solutions-results-out-of-order/45301/3 "2020-08-27T07:06:06Z")

</div>

For some reason it seems to work now. i think i was referencing the wrong row.
