Hello, I would like to declare in JuMP a variable
s whose bounds depends form its index, with some indexes fixed.
The problems is that if I declare it twice I get an error that the variable already attached to the model, e.g.:
idxSet1 = [1,3,5] idxSet0 = [2,4] m = Model(Ipopt.Optimizer) @variable(m, 0 <= s[idx in idxSet1] <= 1) @variable(m, s[idx in idxSet0 ] == 0) # ERROR , s already exists
Of course a workaround is to make the fixation a constrain:
idxSet1 = [1,3,5] idxSet0 = [2,4] m = Model(Ipopt.Optimizer) @variable(m, 0 <= s[idx in union(idxSet1,idxSet0)] <= 1) @constraint(m,sfix[idx in idxSet0 ], s[idx] == 0)
However I am worry that I have more variables than needed here, unless JuMP and the solver engine are smart enough to remove them before the actual optimisation…