"Getvalue" and "JuMP.value" -> collection JuMP decision variables

I have the following decision variables in JuMP:
@variable(model, x[j in positions, k in orders, i in machines], Bin)
@variable(model, D[i in machines, j in positions] >=0)

The functions “getvalue” or “JuMP.value” are not collecting the values of decision variables after the CPLEX finds the global optimal solution. If the variable is a scalar, “getvalue” or “JuMP.value” are returning the value correctly. Is there another function for multi-dimensional variables?

This should be possible with

x_vals = getvalue( model[:x] )

and you should be able to access the values by their coordintates x_vals[j,k,i].

Note that in JuMP 0.18 the function getvalue() returns type ::Any which slows your code down if you access the values often, e.g., in a callback.

EDIT: at least this works in JuMP 0.18, and I did not test it with newer versions

See the Info box in Query Solutions · JuMP.

Dear Mik, thank you very much for your attention. Unfortunately,
x_vals = getvalue( model[:x] ) returns LoadError: MethodError: no method matching in my Julia.

what are your julia and JuMP versions?

Dear Odow,
Thank you very much for your support.
In this version the new sintax is:
optimal_solution = value.(x)

Dear Joaquimg, the problems was solved (see chat with Odow). Thank you very much for your attention. Cheers

1 Like