Skip to content

Commit a1402df

Browse files
committed
Clean up
1 parent 3259b93 commit a1402df

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

highs/presolve/HPresolve.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3926,7 +3926,6 @@ HPresolve::Result HPresolve::rowPresolve(HighsPostsolveStack& postsolve_stack,
39263926
if (val < 0.0 && model->col_upper_[col] != kHighsInf) {
39273927
// complement
39283928
rhs -= val * static_cast<HighsCDouble>(model->col_upper_[col]);
3929-
rowCoefs[i] = -rowCoefs[i];
39303929
} else if (val > 0.0 && model->col_lower_[col] != -kHighsInf) {
39313930
// shift
39323931
rhs -= val * static_cast<HighsCDouble>(model->col_lower_[col]);
@@ -3966,23 +3965,25 @@ HPresolve::Result HPresolve::rowPresolve(HighsPostsolveStack& postsolve_stack,
39663965
HighsCDouble& roundedRhs) {
39673966
bool accept = false;
39683967
// round rhs (using feasibility tolerance)
3969-
roundedRhs = floor(rhs * s + primal_feastol);
3968+
roundedRhs = ceil(rhs * s - primal_feastol);
3969+
assert(roundedRhs != 0.0);
3970+
HighsCDouble rhsRatio = rhs / roundedRhs;
39703971
for (size_t i = 0; i < rowCoefs.size(); ++i) {
3972+
// coefficient sign has not been flipped for complemented
3973+
// variables; take absolute value of coefficient.
3974+
double absCoef = std::abs(rowCoefs[i]);
39713975
// round coefficient
3972-
roundedRowCoefs[i] = std::floor(rowCoefs[i] * s + kHighsTiny);
3973-
// compute "normalised" coefficients, i.e. coefficient divided by
3974-
// rhs
3975-
double normalisedCoef =
3976-
static_cast<double>(rowCoefs[i] * roundedRhs);
3977-
double normalisedRoundedCoef =
3978-
static_cast<double>(roundedRowCoefs[i] * rhs);
3976+
roundedRowCoefs[i] = std::ceil(absCoef * s - kHighsTiny);
3977+
// compare "normalised" coefficients, i.e. coefficients divided by
3978+
// corresponding rhs.
3979+
double threshold =
3980+
static_cast<double>(roundedRowCoefs[i] * rhsRatio);
39793981
// return if coefficient is weaker
3980-
if (normalisedRoundedCoef <
3981-
normalisedCoef - options->small_matrix_value)
3982+
if (absCoef < threshold - options->small_matrix_value)
39823983
return false;
39833984
// accept rounding if at least one coefficient is improved
3984-
accept = accept || (normalisedRoundedCoef >
3985-
normalisedCoef + options->small_matrix_value);
3985+
accept =
3986+
accept || (absCoef > threshold + options->small_matrix_value);
39863987
}
39873988
return accept;
39883989
};
@@ -4010,7 +4011,7 @@ HPresolve::Result HPresolve::rowPresolve(HighsPostsolveStack& postsolve_stack,
40104011
// replace the model row by the rounded one
40114012
auto updateRow = [&](HighsInt row, HighsInt direction,
40124013
HighsCDouble roundedRhs) {
4013-
if (direction > 0)
4014+
if (direction < 0)
40144015
model->row_upper_[row] = static_cast<double>(roundedRhs);
40154016
else
40164017
model->row_lower_[row] = static_cast<double>(roundedRhs);
@@ -4024,10 +4025,10 @@ HPresolve::Result HPresolve::rowPresolve(HighsPostsolveStack& postsolve_stack,
40244025

40254026
// direction = 1: <= constraint, direction = -1: >= constraint
40264027
HighsInt direction =
4027-
model->row_upper_[row] != kHighsInf ? HighsInt{1} : HighsInt{-1};
4028+
model->row_upper_[row] != kHighsInf ? HighsInt{-1} : HighsInt{1};
40284029
// get rhs
40294030
HighsCDouble rhs =
4030-
direction > 0 ? model->row_upper_[row] : -model->row_lower_[row];
4031+
direction < 0 ? -model->row_upper_[row] : model->row_lower_[row];
40314032

40324033
// initialise
40334034
HighsCDouble roundedRhs = 0.0;

0 commit comments

Comments
 (0)