@@ -6648,22 +6648,25 @@ HPresolve::Result HPresolve::sparsify(HighsPostsolveStack& postsolve_stack) {
66486648
66496649 storeRow (eqrow);
66506650
6651- HighsInt secondSparsestColumn = -1 ;
6652- HighsInt sparsestCol = Acol[rowpositions[ 0 ]] ;
6651+ HighsInt sparsestCol = -1 ;
6652+ HighsInt secondSparsestCol = - 1 ;
66536653 HighsInt sparsestColLen = kHighsIInf ;
6654- for (size_t i = 1 ; i < rowpositions.size (); ++i) {
6655- HighsInt col = Acol[rowpositions[i]];
6654+ HighsInt secondSparsestColLen = kHighsIInf ;
6655+ for (HighsInt nzPos : rowpositions) {
6656+ HighsInt col = Acol[nzPos];
66566657 if (colsize[col] < sparsestColLen) {
6657- sparsestColLen = colsize[col] ;
6658- secondSparsestColumn = sparsestCol ;
6658+ secondSparsestCol = sparsestCol ;
6659+ secondSparsestColLen = sparsestColLen ;
66596660 sparsestCol = col;
6661+ sparsestColLen = colsize[col];
6662+ } else if (colsize[col] < secondSparsestColLen) {
6663+ secondSparsestCol = col;
6664+ secondSparsestColLen = colsize[col];
66606665 }
66616666 }
66626667
6663- if (colsize[secondSparsestColumn] < colsize[sparsestCol])
6664- std::swap (sparsestCol, secondSparsestColumn);
6665-
6666- assert (sparsestCol != -1 && secondSparsestColumn != -1 );
6668+ assert (sparsestCol != -1 && secondSparsestCol != -1 );
6669+ assert (colsize[sparsestCol] <= colsize[secondSparsestCol]);
66676670
66686671 std::map<double , HighsInt> possibleScales;
66696672 sparsifyRows.clear ();
@@ -6711,7 +6714,7 @@ HPresolve::Result HPresolve::sparsify(HighsPostsolveStack& postsolve_stack) {
67116714 auto it = possibleScales.lower_bound (scale - scaleTolerance);
67126715 if (it != possibleScales.end () &&
67136716 std::abs (it->first - scale) <= scaleTolerance) {
6714- // there already is a scale that is very close and could produces
6717+ // there already is a scale that is very close and could produce
67156718 // a matrix value for this nonzero that is below the allowed
67166719 // threshold. Therefore we check if the matrix value is small enough
67176720 // for this nonzero to be deleted, in which case the number of
@@ -6759,7 +6762,7 @@ HPresolve::Result HPresolve::sparsify(HighsPostsolveStack& postsolve_stack) {
67596762 // now check for rows which do not contain the sparsest column but all
67606763 // other columns by scanning the second sparsest column
67616764 for (const HighsSliceNonzero& colNz :
6762- getColumnVector (secondSparsestColumn )) {
6765+ getColumnVector (secondSparsestCol )) {
67636766 HighsInt candRow = colNz.index ();
67646767 if (candRow == eqrow) continue ;
67656768
@@ -6776,7 +6779,7 @@ HPresolve::Result HPresolve::sparsify(HighsPostsolveStack& postsolve_stack) {
67766779 bool skip = false ;
67776780 for (const HighsSliceNonzero& nonzero : getStoredRow ()) {
67786781 double candRowVal;
6779- if (nonzero.index () == secondSparsestColumn ) {
6782+ if (nonzero.index () == secondSparsestCol ) {
67806783 candRowVal = colNz.value ();
67816784 } else {
67826785 HighsInt nzPos = findNonzero (candRow, nonzero.index ());
@@ -6795,7 +6798,7 @@ HPresolve::Result HPresolve::sparsify(HighsPostsolveStack& postsolve_stack) {
67956798 auto it = possibleScales.lower_bound (scale - scaleTolerance);
67966799 if (it != possibleScales.end () &&
67976800 std::abs (it->first - scale) <= scaleTolerance) {
6798- // there already is a scale that is very close and could produces
6801+ // there already is a scale that is very close and could produce
67996802 // a matrix value for this nonzero that is below the allowed
68006803 // threshold. Therefore we check if the matrix value is small enough
68016804 // for this nonzero to be deleted, in which case the number of
0 commit comments