Closed dannyopts closed 3 months ago
Found the answer that this is the expected way to do this: https://discourse.julialang.org/t/using-anonymous-and-or-symbols-to-create-dynamic-varible-names/83095/3 https://discourse.julialang.org/t/how-to-let-the-user-specify-the-variable-name/114467
closing since this is clearly the intended way
Hi,
I have written some functions to create variables and ran into a few issues which make me think I must be doing something wrong.
These functions are called multiple times for a single subproblem and I have found that I cant use the "standard" JuMP syntax for defining variables
because the symbol my_var_name will be used to name the variable on the model (not the runtime value of my_var_name). I will then get name collisions on the second call of this function.
Instead I have used an anonymous variable like so:
This is fine until I try to the access the variables in SDDP.simulate.
which results in CompressedH2Store_p being given the value NaN, even though CompressedH2Store_p is a variable that was added to the model (via
@JuMP.variable(sp, [i=mode.sns], base_name="CompressedH2Store_p")
)I dug around a bit and it seems that the variables are added to the model CompressedH2Store_p_1, CompressedH2Store_p_2 etc but are not inserted into the object_dictionary.
As a temporary work around I am adding variables to the object_dictionary after they are created, although this seems like I'm fighting with the tools rather than using them as intended.
Is there a better way to add variables to a model with a runtime defined names?