Skip to content

Commit

Permalink
Merge pull request #2022 from ERGO-Code/fix-2021
Browse files Browse the repository at this point in the history
Added time limit check to HPresolve::strengthenInequalities
  • Loading branch information
jajhall authored Nov 1, 2024
2 parents 0268034 + c31b397 commit 588b8a9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
48 changes: 30 additions & 18 deletions src/presolve/HPresolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4228,11 +4228,13 @@ HPresolve::Result HPresolve::presolve(HighsPostsolveStack& postsolve_stack) {
HPRESOLVE_CHECKED_CALL(fastPresolveLoop(postsolve_stack));

if (mipsolver != nullptr) {
HighsInt numStrenghtened = strengthenInequalities();
if (numStrenghtened > 0)
HighsInt num_strengthened = -1;
HPRESOLVE_CHECKED_CALL(strengthenInequalities(num_strengthened));
assert(num_strengthened >= 0);
if (num_strengthened > 0)
highsLogDev(options->log_options, HighsLogType::kInfo,
"Strengthened %" HIGHSINT_FORMAT " coefficients\n",
numStrenghtened);
num_strengthened);
}

HPRESOLVE_CHECKED_CALL(fastPresolveLoop(postsolve_stack));
Expand Down Expand Up @@ -4307,6 +4309,15 @@ HPresolve::Result HPresolve::presolve(HighsPostsolveStack& postsolve_stack) {
return Result::kOk;
}

HPresolve::Result HPresolve::checkTimeLimit() {
assert(timer);
assert(run_clock >= 0);
if (options->time_limit < kHighsInf &&
timer->read(run_clock) >= options->time_limit)
return Result::kStopped;
return Result::kOk;
}

HPresolve::Result HPresolve::checkLimits(HighsPostsolveStack& postsolve_stack) {
size_t numreductions = postsolve_stack.numReductions();

Expand Down Expand Up @@ -4351,14 +4362,7 @@ HPresolve::Result HPresolve::checkLimits(HighsPostsolveStack& postsolve_stack) {
postsolve_stack.debug_prev_numreductions = numreductions;
}

if ((numreductions & 1023u) == 0) {
assert(timer);
assert(run_clock >= 0);
if (options->time_limit < kHighsInf &&
timer->read(run_clock) >= options->time_limit) {
return Result::kStopped;
}
}
if ((numreductions & 1023u) == 0) HPRESOLVE_CHECKED_CALL(checkTimeLimit());
return numreductions >= reductionLimit ? Result::kStopped : Result::kOk;
}

Expand Down Expand Up @@ -5127,7 +5131,8 @@ HPresolve::Result HPresolve::removeDoubletonEquations(
return Result::kOk;
}

HighsInt HPresolve::strengthenInequalities() {
HPresolve::Result HPresolve::strengthenInequalities(
HighsInt& num_strengthened) {
std::vector<int8_t> complementation;
std::vector<double> reducedcost;
std::vector<double> upper;
Expand All @@ -5137,7 +5142,9 @@ HighsInt HPresolve::strengthenInequalities() {
std::vector<double> coefs;
std::vector<HighsInt> cover;

HighsInt numstrenghtened = 0;
num_strengthened = 0;
// Check for timeout according to this frequency
const HighsInt check_time_frequency = 100;

for (HighsInt row = 0; row != model->num_row_; ++row) {
if (rowsize[row] <= 1) continue;
Expand All @@ -5146,9 +5153,9 @@ HighsInt HPresolve::strengthenInequalities() {
continue;

// do not run on very dense rows as this could get expensive
if (rowsize[row] >
std::max(HighsInt{1000}, (model->num_col_ - numDeletedCols) / 20))
continue;
HighsInt rowsize_limit =
std::max(HighsInt{1000}, (model->num_col_ - numDeletedCols) / 20);
if (rowsize[row] > rowsize_limit) continue;

// printf("strengthening knapsack of %" HIGHSINT_FORMAT " vars\n",
// rowsize[row]);
Expand Down Expand Up @@ -5225,6 +5232,11 @@ HighsInt HPresolve::strengthenInequalities() {
upper.push_back(ub);
}

// Check for timeout according to frequency, unless a particularly
// dense row has just been analysed
if ((row & check_time_frequency) == 0 || 10 * rowsize[row] > rowsize_limit)
HPRESOLVE_CHECKED_CALL(checkTimeLimit());

if (skiprow) {
stack.clear();
continue;
Expand Down Expand Up @@ -5343,10 +5355,10 @@ HighsInt HPresolve::strengthenInequalities() {
model->row_upper_[row] = double(rhs);
}

numstrenghtened += indices.size();
num_strengthened += indices.size();
}

return numstrenghtened;
return Result::kOk;
}

HighsInt HPresolve::detectImpliedIntegers() {
Expand Down
4 changes: 3 additions & 1 deletion src/presolve/HPresolve.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ class HPresolve {

Result presolve(HighsPostsolveStack& postsolve_stack);

Result checkTimeLimit();

Result checkLimits(HighsPostsolveStack& postsolve_stack);

void storeCurrentProblemSize();
Expand Down Expand Up @@ -343,7 +345,7 @@ class HPresolve {

Result removeDoubletonEquations(HighsPostsolveStack& postsolve_stack);

HighsInt strengthenInequalities();
Result strengthenInequalities(HighsInt& num_strenghtened);

HighsInt detectImpliedIntegers();

Expand Down

0 comments on commit 588b8a9

Please sign in to comment.