Skip to content

Commit

Permalink
strengthenInequalities can get too expensive to run without time limi…
Browse files Browse the repository at this point in the history
…t check
  • Loading branch information
jajhall committed Nov 1, 2024
1 parent 788d4ba commit f1e1676
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
49 changes: 31 additions & 18 deletions src/presolve/HPresolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4228,11 +4228,14 @@ 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, postsolve_stack));
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 +4310,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 +4363,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 +5132,8 @@ HPresolve::Result HPresolve::removeDoubletonEquations(
return Result::kOk;
}

HighsInt HPresolve::strengthenInequalities() {
HPresolve::Result HPresolve::strengthenInequalities(
HighsInt& num_strengthened, HighsPostsolveStack& postsolve_stack) {
std::vector<int8_t> complementation;
std::vector<double> reducedcost;
std::vector<double> upper;
Expand All @@ -5137,7 +5143,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 +5154,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 +5233,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 +5356,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
5 changes: 4 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,8 @@ class HPresolve {

Result removeDoubletonEquations(HighsPostsolveStack& postsolve_stack);

HighsInt strengthenInequalities();
Result strengthenInequalities(HighsInt& num_strenghtened,
HighsPostsolveStack& postsolve_stack);

HighsInt detectImpliedIntegers();

Expand Down

0 comments on commit f1e1676

Please sign in to comment.