You should always keep in mind that JuMP variables and constraints are just regular Julia objects.
That means you can use them with any other data structure in Julia. Iād write your model as:
cons = []
for time in 1:nTime
c = @constraint(model, a[time] + b[time] == c[time], base_name = "cons")
push!(cons, c)
end
shadow_price.(cons)
or perhaps
cons = map(1:nTime) do time
# Stuff here
return @constraint(model, a[time] + b[time] == c[time], base_name = "cons")
end
shadow_price.(cons)
Your constraint_by_name approach also works, but it involves a couple of lookups and relies on base_name being unique. So having an explicit vector of constraints might be better.