I want to add serval named expressions in a JuMP model that are conditional on the indices p (set P) and t (set T). X and I are the decision variable and set P consists of two subsets, P_1, P_2. I want the expressions to be named to be able to use them later on. After adding the expression “ex” for the first subset P_1, I am not able to add the expression for the second subset because I receive the following error:
ERROR: An object of name ex is already attached to this model.
How can I avoid this error and add the expression conditional on index value? Here is a MWE:
using JuMP, HiGHs
P_1 = ["a", "b", "c"]
P_2 = ["d", "e"]
P = vcat(P_1, P_2)
T = 1:10
model = JuMP.Model(HiGHs.Optimizer)
@variables model begin
X[P,T], Bin
I[P,T] >= 0
end
@expression(model, ex[p=P_1, t=T], I[p,t] * 5)
@expression(model, ex[p=P_2, t=T], I[p,t] * 7)