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:
- An expensive re-indexing (via
GurobiModel::delete_constraint -> GurobiModel::_constraint_index -> ChunkedBitVector::get_index -> ChunkedBitVector::update_to)
- 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
Hi Yue,
I hope you're doing well!
I've received reports that repeatedly deleting linear constraints in Gurobi (via the
.delete_constraintmethod) 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_constrainttriggers both:GurobiModel::delete_constraint -> GurobiModel::_constraint_index -> ChunkedBitVector::get_index -> ChunkedBitVector::update_to)GurobiModel::delete_constraint -> GurobiModel::_constraint_index -> GurobiModel::_update_for_constraint_index -> GurobiModel::update -> gurobi::GRBupdatemodel)Would you be open to adding a
delete_constraintsmethod similar todelete_variables? I expect such a method could be much much more efficient given that Gurobi supports deleting multiple constraints at once and yourChunkedBitVectorcan delete multiple indexes lazily (very neat btw!).Cheers,
Martin