Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing/Updating Constraints #219

Open
JP-Barbosa opened this issue Jul 23, 2024 · 1 comment
Open

Replacing/Updating Constraints #219

JP-Barbosa opened this issue Jul 23, 2024 · 1 comment

Comments

@JP-Barbosa
Copy link

Hi,

Is there a way to update or replace constraints after the model is instantiated?

Long version

I am currently solving an EPEC via diagonalization. This requires me to solve the bilevel problem several times by updating a set of constraints. Since creating a new model instance is a bit of a waste of time (models are very large), being able to update constraints would be very useful.

I have already done something similar using directly JuMP Models...

function update!(model:: JuMP.Model, new_values::Vector[Number], index_set)
   # Remove and unregister existing fixing constraints
   for i in eachindex(model[:MyConstraintName])
      delete(model, model[:MyConstraintName][i])
   end
   unregister(model, :MyConstraintName)
   
   # Add new Constraint
   @constraint(model, :MyConstraintName[i in index_set], model[::MyVariableName][i] .== new_values[i])
   return model
end

However I failled to do the same with the BilevelJump since

delete(Upper(model), model[:MyConstraintName][i])

calls this function:

#jump_constraints.jl ln 45

function JuMP.delete(m::AbstractBilevelModel, cref::BilevelConstraintRef)
    error("can't delete")

Thanks!

@joaquimg
Copy link
Owner

Hi and welcome!

The main point is: it is usually much slower to solve than to build.

Moreover, related to the solve part,
a new solve will rebuild the internal MPEC anyway, so again building should not be a great bottleneck.

Have to tried profiling your code with PProf.jl?

If you have a MWE for which building is a bottleneck I would be happy to consider adding this functionality.

At the same time, a PR would be welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants