Allow multiple calls of XpressInterface::SetCoefficient, also XpressInterface::ClearConstraint

This commit is contained in:
Florian OMNES
2025-06-04 18:54:04 +02:00
parent c8da371ab3
commit f03887aa89

View File

@@ -427,7 +427,7 @@ class XpressInterface : public MPSolverInterface {
// Looping on MPConstraint::coefficients_ yields non-reproducible results
// since is uses pointer addresses as keys, the value of which is
// non-deterministic, especially their order.
std::map<int, std::vector<std::pair<int, double> > >
std::map<int, std::map<int, double> >
fixedOrderCoefficientsPerConstraint;
// Incremental extraction.
@@ -1094,8 +1094,7 @@ void XpressInterface::SetCoefficient(MPConstraint* const constraint,
double new_value, double) {
InvalidateSolutionSynchronization();
fixedOrderCoefficientsPerConstraint[constraint->index()].emplace_back(
variable->index(), new_value);
fixedOrderCoefficientsPerConstraint[constraint->index()][variable->index()] = new_value;
// Changing a single coefficient in the matrix is potentially pretty
// slow since that coefficient has to be found in the sparse matrix
@@ -1129,6 +1128,8 @@ void XpressInterface::ClearConstraint(MPConstraint* const constraint) {
// There is nothing to do if the constraint was not even extracted.
return;
fixedOrderCoefficientsPerConstraint.erase(constraint->index());
// Clearing a constraint means setting all coefficients in the corresponding
// row to 0 (we cannot just delete the row since that would renumber all
// the constraints/rows after it).