I wrote a method to get all the variable values in a JuMP Model:
function get_results_dict(m::JuMP.Model)
av = JuMP.all_variables(m);
d = Dict()
for v in av
# special handling of time series, sub-indices, etc.
# e.g. a variable could have three sub-indices in a JuMP.Containers
v = string(v) # e.g. "x[a,2,3]"
k = Symbol(v[1:prevind(v, findfirst('[', v))[1]]) # :x
vm = value.(m[k])
d[k] = vm.data
# e.g. typeof(vm) is JuMP.Containers.SparseAxisArray{Float64, 3, Tuple{SubString{String}, Int64, Int64}}
end
return d
end
However, this is extremely slow because
julia> length(av)
1349040
Is there more efficient way to get all the variable values? Other than only getting some variable values? And if the latter is the only solution, what is the most efficient way to get a group of variable values with different indexing structures in JuMP.Containers
? (Say if I had a vector of variable names that is a subset of JuMP.all_variables
).