Modify/reasign objective function of a model in JuMP

I’m implementing a consensus ADMM model, and for that I wold like to iteratively solve two models, exchange information between them and solve them again with a modified objective function.

The problem I’m facing right now is that once the objective function is assigned, trying to re-assign it prompts an error, and as far as I know there is no method to delete the objective function as a workaround.

Any recomendations?

Just call @objective again.

model = Model()
@variable(model, x >= 1)
@objective(model, Min, 2x + 1)
optimize!(model)
@objective(model, Max, -x)
optimize!(model)

p.s. in future, read the first post of Please read: make it easier to help you - #8 and provide a minimal working example. It makes it much easier to provide help.

1 Like