Skip to content

Add .delete_constraints method because repeated constraint deletion is slow #108

Description

@staadecker

Hi Yue,

I hope you're doing well!

I've received reports that repeatedly deleting linear constraints in Gurobi (via the .delete_constraint method) is so slow that often it is faster to simply re-create the model from scratch. This is particularly an issue for iterative optimization problems where users may want to modify and/or delete constraints on each iteration without recreating the model from scratch.

Looking at PyOptInterface's code, it does seem that each repeated call to .delete_constraint triggers both:

  1. An expensive re-indexing (via GurobiModel::delete_constraint -> GurobiModel::_constraint_index -> ChunkedBitVector::get_index -> ChunkedBitVector::update_to)
  2. A Gurobi update (via GurobiModel::delete_constraint -> GurobiModel::_constraint_index -> GurobiModel::_update_for_constraint_index -> GurobiModel::update -> gurobi::GRBupdatemodel)

Would you be open to adding a delete_constraints method similar to delete_variables? I expect such a method could be much much more efficient given that Gurobi supports deleting multiple constraints at once and your ChunkedBitVector can delete multiple indexes lazily (very neat btw!).

Cheers,
Martin

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions