How to output the value of my decision variable in workspace?
I tried to use value at the end of the program, but it didn’t work. At present, the effective way is to write value() one by one in repl.
If each variable is a single value (not an array of values), I think the best way is (maybe):
for variable in all_variables(model)
println("$(name(variable)) = $(value(variable))")
end
Also, maybe you wanna put it inside an if
too, to avoid printing the zero-valued variables.
1 Like
What if the variables in matrix form need to be output?
My first reply will work if some variables are, in fact, vectors or matrices of variables. But, then, maybe you wanna do something special to improve the visualization, I mean. Using that loop you will get:
scalar_name = its_value
matrix[1, 1] = its_value
matrix[1, 2] = its_value
...
scalar_name = its_value
The order will be by creation time (unless you start to fiddle with the JuMP containers yourself).
Assign the value to some variable PGD_EX_opt = value(PGD_EX)
In that case don’t forget to use the .
broadcast in value
M_opt = value.(M)
2 Likes
If your decision variable is a vector use value.(variable)
2 Likes
that’s right! thankyou!