Hi,
After solving my JuMP model, I would like to use getvalue() on all variables in my model in an automated way. Say I have the following example problem:
using JuMP
using Clp
m=Model(solver=ClpSolver())
@variable(m,x[1:3]>=0)
@variable(m,y[1:3]>=0)
@constraint(m,[i=1:3],x[i]<=3)
@constraint(m,[i=1:3],y[i]<=4)
@objective(m,Max,sum(x[i] + 2*y[i] for i=1:3))
status=solve(m)
I could then do the following in order to obtain the optimal values of the variables:
x_res = getvalue(x)
y_res = getvalue(y)
How could I do this in an automated fashion, looping through all variables that the JuMP model contains and saving them similarly to the example above?
Is there a list/dictionary associated with a JuMP model that contains all the variables, that I could then loop through?
Thank you already in advance
using MathOptInterface
const MOI = MathOptInterface
vars = JuMP.Variable(m, MOI.get(m.moibackend, MOI.ListOfVariableIndices()))
JuMP.resultvalue.(vars)
but we might have a nicer syntax on JuMP v0.19 like MOI.get(m, MOI.ListOfVariableIndices()) to get the list of variables.