Post Processing JuMP results - Transforming JuMP variables


#1

Hi guys!

I have finished my implementation of my unit commitment problem and I would like to know if there is any possibility of including this kind of plot in my final results:

Extracted from: https://yalmip.github.io/example/unitcommitment/

Basically right know I am accessing to my results as:

for j in 1:T
println("Dispatch Power in hour “,j,” = ", getvalue(p[:,j]))
println("Hour “, j, " Startup Cost =”,getvalue(s[:,j]))
end

But I would like to know if I there is any possibility of transforming the JuMP variable to a normal array o a dataframe in order to plot them.


#2

Have you looked at Gadfly.jl?


#3

getvalue should work on AbstractArray{JuMP.Variable} directly, so there is no need to iterate over the elements. getvalue will give you an AbstractArray{Float64}, and at this point you can do absolutely anything with the data that you want.


#4

Just check it, it works like charm thank you so much :smiley:


#5

Hello ExpandingMan,
Thanks for this tips, however, I tried “println(“solved model results”, getvalue(::AbstractArray{JuMP.Variable}))” but it did not work for me. I keep get the following error; “ERROR: LoadError: MethodError: no method matching getvalue(::Type{AbstractArray{JuMP.Variable,N} where N})”

I have tried searching for this error, but not finding any meaningful help. I shall appreciate your insight regarding this issue. Thank you.


#6

@ExpandingMan meant that instead of

for j in 1:T
    println("Dispatch Power in hour ",j," = ", getvalue(p[:,j]))
    println("Hour ", j, " Startup Cost =",getvalue(s[:,j]))
end

You can go

@show typeof(p)   # Array{JuMP.Variable, 2}
px = getvalue(p)
@show typeof(px)  # Array{Float64, 2}
sx = getvalue(s)
for j in 1:T
    println("Dispatch Power in hour ",j," = ", px[:,j])
    println("Hour ", j, " Startup Cost =", sx[:,j])
end

#7

Thank you clarifying this for me! Have a great week.