The best way to visualize optimization results in juMP

I have been working for some months in the optimization domain. I have a huge problem that can easily reach >500k variables. These variables represent many different things over a time-slice. After getting the solution, it’s necessary to make the results readable for people and the best way is plotting. I know there are many packages to help us to plot but once I’m dealing with variables that have a multi indexation( for example, [ year, region, type_product, division of year, day, hour] ) it’s not been easy to me to group all of them to plot( I started by StatPlots.jl) it’s been actually a very tedious task. As I’m beginner in this domain, I’d like to know if usually people export the results to Excel and then treat them there, or if it’s really possible to create good presentations of my optimization results only using the plot packages in Julia? Thanks in advance.

You certainly can generate any analysis you need in Julia. The easiest way is to drop the results of your variables into a DataFrame. For a multi-index variable you can do something like:

using DataFrames

df = DataFrame(year=[],region=[],type_product=[],division=[],day=[],hour=[])
for k in keys(x)
  val = getvalue(x[k...])
  if val > 0
    push!(df,vcat(k...,val))
  end
end

For example this code creates an empty data frame, and then fill it line by line if the variable is > 0. Once your have the DataFrame, you can do many things… including exporting a CSV if you wish.

The easiest plotting package (imho) is Gadfly. The documentation is very clear, and you can create plots from DataFrames.

Another cool thing you can do is create expressions inside your JuMP code, so you can query the values afterwards. Expressions are not variables, so they won’t increase the size of your constraint matrix, but they can also be indexed. Check JuMP @expression.

5 Likes

I was not used with … operator. It will help me a lot later!! Thanks a lot!!

Check out VegaLite.jl.