Querying JuMP solutions - results out of order

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.

model = dc_dam_opf(pm_data)
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> 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]

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.

1 Like

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