I’m trying to be able to use values put in a Dictionary to weight the variables that are going to be minimized in a JuMP objective function.
The dictionnary is implemented as follow :
Dicopond = Dict(0=> 1, 1 => 2, 2 => 4, 3 => 8, 4 => 16, 5 => 32, 6 => 64, 7 => 128)
The variable :
@variable(model, absolute[y=1:10])
And the objective function :
@objective(model, Min, sum((absolute[y])*Dicopond[(absolute[y])] for y=1:10))
Absolute[y] will only take the values between 0 and 7.
However, I get the Error “LoadError: KeyError: key absolute[1] not found in expression starting at…”
Is there a way to make the dictionnary get the actual value that will be assigned to absolute[y] ?
I’ve tried different ways to be able to put a weight to the decision variable and this was the one that seemed to be the most likely to work.
Thank you for your help!
EDIT : Cross-posted on : https://discourse.julialang.org/t/use-dictionary-value-in-objective-function/59119