-
-
Notifications
You must be signed in to change notification settings - Fork 411
Closed
Labels
Description
I run an MILP several times with different parameter values. Instead of recreating the model every time, I would like to be able to just change the relevant constraints. From the documentation, I figured that I'd be able to do this by deleting the constraint and then reformulating it.
Here's a toy example:
using JuMP
model = Model(with_optimizer(Gurobi.Optimizer))
@variable(model, x[i=1:2,j=1:2])
@constraint(model, con[i=1:2,j=1:2], x[i,j] >= 1)
for i=1:2
for j=1:2
delete(model, con[i,j])
end
end
@constraint(model, con[i=1:2,j=1:2], x[i,j] >= 2)This produces the error:
ERROR: LoadError: An object of name con is already attached to this model. If this is intended, consider using the anonymous construction syntax, e.g., x = @variable(model, [1:N], ...) where the name of the object does not appear inside the macro.
One workaround I can see is to delete the name con in model, but I don't know how / cannot do this. Ideally I would like a simpler way of modifying constraints, for example as:
model = Model(with_optimizer(Gurobi.Optimizer))
@variable(model, x[i=1:2,j=1:2])
@constraint(model, con[i=1:2,j=1:2], x[i,j] >= 1)
@constraint(model, con[i=1:2,j=1:2], x[i,j] >= 2)However it would appear that this is quite difficult judging from this issue: #1241