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

Fix 2095 #2096

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/presolve/HPresolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6133,15 +6133,30 @@ HPresolve::Result HPresolve::equalityRowAddition(
HighsPostsolveStack& postsolve_stack, HighsInt stayrow, HighsInt removerow,
double scale, const HighsMatrixSlice<RowStorageFormat>& vector) {
postsolve_stack.equalityRowAddition(removerow, stayrow, scale, vector);
// As exposed by #2095, adding to the matrix in the loop can corrupt
// vector, so possiblt accumulate the addiitons and perform then
// when vector is no longer needed
std::vector<std::pair<HighsInt, double>> add_index_value;
const bool add_to_matrix_after = true;
for (const auto& rowNz : vector) {
assert(rowNz.index() >= 0);
HighsInt pos = findNonzero(removerow, rowNz.index());
if (pos != -1)
if (pos != -1) {
unlink(pos); // all common nonzeros are cancelled, as the rows are
// parallel
else // might introduce a singleton
addToMatrix(removerow, rowNz.index(), scale * rowNz.value());
} else { // might introduce a singleton
if (add_to_matrix_after) {
add_index_value.push_back(std::make_pair(rowNz.index(), rowNz.value()));
} else {
addToMatrix(removerow, rowNz.index(), scale * rowNz.value());
}
}
}
if (add_to_matrix_after) {
for (HighsInt iX = 0; iX < HighsInt(add_index_value.size()); iX++)
addToMatrix(removerow, add_index_value[iX].first,
scale * add_index_value[iX].second);
}

if (model->row_upper_[removerow] != kHighsInf)
model->row_upper_[removerow] =
double(model->row_upper_[removerow] +
Expand Down
Loading