Post Processing JuMP results - Transforming JuMP variables

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: Unit commitment - YALMIP

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.

Have you looked at Gadfly.jl?

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.

2 Likes

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

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.

@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
2 Likes

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

1 Like