Skip to content

Commit 0859510

Browse files
authored
Merge pull request #2509 from fwesselm/refactorPreDomChecks
Refactor HPresolve::dominatedColumns
2 parents f8b218d + dd69d7a commit 0859510

File tree

3 files changed

+280
-317
lines changed

3 files changed

+280
-317
lines changed

highs/mip/HighsPseudocost.h

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class HighsPostsolveStack;
2424

2525
class HighsPseudocost;
2626

27+
constexpr double minThreshold = 1e-6;
28+
2729
struct HighsPseudocostInitialization {
2830
std::vector<double> pseudocostup;
2931
std::vector<double> pseudocostdown;
@@ -47,6 +49,7 @@ struct HighsPseudocostInitialization {
4749
const HighsPseudocost& pscost, HighsInt maxCount,
4850
const presolve::HighsPostsolveStack& postsolveStack);
4951
};
52+
5053
class HighsPseudocost {
5154
friend struct HighsPseudocostInitialization;
5255
std::vector<double> pseudocostup;
@@ -77,9 +80,7 @@ class HighsPseudocost {
7780
HighsPseudocost(const HighsMipSolver& mipsolver);
7881

7982
void subtractBase(const HighsPseudocost& base) {
80-
HighsInt ncols = pseudocostup.size();
81-
82-
for (HighsInt i = 0; i != ncols; ++i) {
83+
for (size_t i = 0; i != pseudocostup.size(); ++i) {
8384
pseudocostup[i] -= base.pseudocostup[i];
8485
pseudocostdown[i] -= base.pseudocostdown[i];
8586
nsamplesup[i] -= base.nsamplesup[i];
@@ -95,8 +96,7 @@ class HighsPseudocost {
9596
conflict_weight = 1.0;
9697
conflict_avg_score *= scale;
9798

98-
HighsInt numCol = conflictscoreup.size();
99-
for (HighsInt i = 0; i < numCol; ++i) {
99+
for (size_t i = 0; i != conflictscoreup.size(); ++i) {
100100
conflictscoreup[i] *= scale;
101101
conflictscoredown[i] *= scale;
102102
}
@@ -248,11 +248,13 @@ class HighsPseudocost {
248248
}
249249

250250
double getScore(HighsInt col, double upcost, double downcost) const {
251-
double costScore = std::max(upcost, 1e-6) * std::max(downcost, 1e-6) /
252-
std::max(1e-6, cost_total * cost_total);
253-
double inferenceScore = std::max(inferencesup[col], 1e-6) *
254-
std::max(inferencesdown[col], 1e-6) /
255-
std::max(1e-6, inferences_total * inferences_total);
251+
double costScore = std::max(upcost, minThreshold) *
252+
std::max(downcost, minThreshold) /
253+
std::max(minThreshold, cost_total * cost_total);
254+
double inferenceScore =
255+
std::max(inferencesup[col], minThreshold) *
256+
std::max(inferencesdown[col], minThreshold) /
257+
std::max(minThreshold, inferences_total * inferences_total);
256258

257259
double cutOffScoreUp =
258260
ncutoffsup[col] /
@@ -266,18 +268,19 @@ class HighsPseudocost {
266268
std::max(1.0, static_cast<double>(ncutoffstotal) +
267269
static_cast<double>(nsamplestotal));
268270

269-
double cutoffScore = std::max(cutOffScoreUp, 1e-6) *
270-
std::max(cutOffScoreDown, 1e-6) /
271-
std::max(1e-6, avgCutoffs * avgCutoffs);
271+
double cutoffScore = std::max(cutOffScoreUp, minThreshold) *
272+
std::max(cutOffScoreDown, minThreshold) /
273+
std::max(minThreshold, avgCutoffs * avgCutoffs);
272274

273275
double conflictScoreUp = conflictscoreup[col] / conflict_weight;
274276
double conflictScoreDown = conflictscoredown[col] / conflict_weight;
275277
double conflictScoreAvg =
276278
conflict_avg_score /
277279
(conflict_weight * static_cast<double>(conflictscoreup.size()));
278-
double conflictScore = std::max(conflictScoreUp, 1e-6) *
279-
std::max(conflictScoreDown, 1e-6) /
280-
std::max(1e-6, conflictScoreAvg * conflictScoreAvg);
280+
double conflictScore =
281+
std::max(conflictScoreUp, minThreshold) *
282+
std::max(conflictScoreDown, minThreshold) /
283+
std::max(minThreshold, conflictScoreAvg * conflictScoreAvg);
281284

282285
auto mapScore = [](double score) { return 1.0 - 1.0 / (1.0 + score); };
283286
return mapScore(costScore) / degeneracyFactor +
@@ -294,9 +297,10 @@ class HighsPseudocost {
294297
}
295298

296299
double getScoreUp(HighsInt col, double frac) const {
297-
double costScore = getPseudocostUp(col, frac) / std::max(1e-6, cost_total);
300+
double costScore =
301+
getPseudocostUp(col, frac) / std::max(minThreshold, cost_total);
298302
double inferenceScore =
299-
inferencesup[col] / std::max(1e-6, inferences_total);
303+
inferencesup[col] / std::max(minThreshold, inferences_total);
300304

301305
double cutOffScoreUp =
302306
ncutoffsup[col] /
@@ -306,13 +310,14 @@ class HighsPseudocost {
306310
std::max(1.0, static_cast<double>(ncutoffstotal) +
307311
static_cast<double>(nsamplestotal));
308312

309-
double cutoffScore = cutOffScoreUp / std::max(1e-6, avgCutoffs);
313+
double cutoffScore = cutOffScoreUp / std::max(minThreshold, avgCutoffs);
310314

311315
double conflictScoreUp = conflictscoreup[col] / conflict_weight;
312316
double conflictScoreAvg =
313317
conflict_avg_score /
314318
(conflict_weight * static_cast<double>(conflictscoreup.size()));
315-
double conflictScore = conflictScoreUp / std::max(1e-6, conflictScoreAvg);
319+
double conflictScore =
320+
conflictScoreUp / std::max(minThreshold, conflictScoreAvg);
316321

317322
auto mapScore = [](double score) { return 1.0 - 1.0 / (1.0 + score); };
318323

@@ -323,9 +328,9 @@ class HighsPseudocost {
323328

324329
double getScoreDown(HighsInt col, double frac) const {
325330
double costScore =
326-
getPseudocostDown(col, frac) / std::max(1e-6, cost_total);
331+
getPseudocostDown(col, frac) / std::max(minThreshold, cost_total);
327332
double inferenceScore =
328-
inferencesdown[col] / std::max(1e-6, inferences_total);
333+
inferencesdown[col] / std::max(minThreshold, inferences_total);
329334

330335
double cutOffScoreDown =
331336
ncutoffsdown[col] /
@@ -335,13 +340,14 @@ class HighsPseudocost {
335340
std::max(1.0, static_cast<double>(ncutoffstotal) +
336341
static_cast<double>(nsamplestotal));
337342

338-
double cutoffScore = cutOffScoreDown / std::max(1e-6, avgCutoffs);
343+
double cutoffScore = cutOffScoreDown / std::max(minThreshold, avgCutoffs);
339344

340345
double conflictScoreDown = conflictscoredown[col] / conflict_weight;
341346
double conflictScoreAvg =
342347
conflict_avg_score /
343348
(conflict_weight * static_cast<double>(conflictscoredown.size()));
344-
double conflictScore = conflictScoreDown / std::max(1e-6, conflictScoreAvg);
349+
double conflictScore =
350+
conflictScoreDown / std::max(minThreshold, conflictScoreAvg);
345351

346352
auto mapScore = [](double score) { return 1.0 - 1.0 / (1.0 + score); };
347353

0 commit comments

Comments
 (0)