Skip to content

Commit 5d45136

Browse files
authored
Merge pull request #2505 from fwesselm/removeDuplicateLogic
Small cleanup
2 parents 3d36291 + 7e6e14b commit 5d45136

File tree

4 files changed

+44
-47
lines changed

4 files changed

+44
-47
lines changed

highs/mip/HighsCliqueTable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ void HighsCliqueTable::extractCliques(
861861
for (HighsInt i = 0; i != nbin; ++i) {
862862
HighsInt bincol = inds[perm[i]];
863863
HighsCDouble impliedub = HighsCDouble(rhs) - vals[perm[i]];
864-
if (implics.getNumVarBounds() >= implics.getMaxVarBounds()) break;
864+
if (implics.tooManyVarBounds()) break;
865865
for (HighsInt j = nbin; j != ntotal; ++j) {
866866
HighsInt col = inds[perm[j]];
867867
if (globaldom.isFixed(col)) continue;

highs/mip/HighsImplications.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ void HighsImplications::addVUB(HighsInt col, HighsInt vubcol, double vubcoef,
395395
// assume that VUBs do not have infinite coefficients and infinite constant
396396
// terms since such VUBs effectively evaluate to NaN.
397397
assert(std::abs(vubcoef) != kHighsInf || std::abs(vubconstant) != kHighsInf);
398-
if (numVarBounds >= maxVarBounds) return;
398+
if (tooManyVarBounds()) return;
399399

400400
VarBound vub{vubcoef, vubconstant};
401401

@@ -424,7 +424,7 @@ void HighsImplications::addVLB(HighsInt col, HighsInt vlbcol, double vlbcoef,
424424
// assume that VLBs do not have infinite coefficients and infinite constant
425425
// terms since such VLBs effectively evaluate to NaN.
426426
assert(std::abs(vlbcoef) != kHighsInf || std::abs(vlbconstant) != kHighsInf);
427-
if (numVarBounds >= maxVarBounds) return;
427+
if (tooManyVarBounds()) return;
428428

429429
VarBound vlb{vlbcoef, vlbconstant};
430430

@@ -732,13 +732,9 @@ void HighsImplications::cleanupVarbounds(HighsInt col) {
732732
if (infeasible) return;
733733
});
734734

735-
if (!delVbds.empty()) {
736-
for (HighsInt vubCol : delVbds) {
737-
vubs[col].erase(vubCol);
738-
numVarBounds--;
739-
}
740-
delVbds.clear();
741-
}
735+
for (HighsInt vubCol : delVbds) vubs[col].erase(vubCol);
736+
numVarBounds -= delVbds.size();
737+
delVbds.clear();
742738

743739
vlbs[col].for_each([&](HighsInt vlbCol, VarBound& vlb) {
744740
bool redundant = false;
@@ -748,10 +744,8 @@ void HighsImplications::cleanupVarbounds(HighsInt col) {
748744
if (infeasible) return;
749745
});
750746

751-
for (HighsInt vlbCol : delVbds) {
752-
vlbs[col].erase(vlbCol);
753-
numVarBounds--;
754-
}
747+
for (HighsInt vlbCol : delVbds) vlbs[col].erase(vlbCol);
748+
numVarBounds -= delVbds.size();
755749
}
756750

757751
void HighsImplications::cleanupVlb(HighsInt col, HighsInt vlbCol,

highs/mip/HighsImplications.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class HighsImplications {
6666
nextCleanupCall = mipsolver.numNonzero();
6767
numImplications = 0;
6868
numVarBounds = 0;
69-
maxVarBounds = 5000000 + 10 * numcol;
69+
maxVarBounds = calcMaxVarBounds(numcol);
7070
}
7171

7272
std::function<void(HighsInt, HighsInt, HighsInt, double)>
@@ -89,12 +89,18 @@ class HighsImplications {
8989
vlbs.shrink_to_fit();
9090
vlbs.resize(numcol);
9191
numVarBounds = 0;
92-
maxVarBounds = 5000000 + 10 * numcol;
92+
maxVarBounds = calcMaxVarBounds(numcol);
9393

9494
nextCleanupCall = mipsolver.numNonzero();
9595
}
9696

97-
HighsInt getNumImplications() const { return numImplications; }
97+
constexpr static int64_t calcMaxVarBounds(HighsInt numcol) {
98+
return int64_t{5000000} + 10 * static_cast<int64_t>(numcol);
99+
};
100+
101+
HighsInt getNumImplications() const {
102+
return static_cast<HighsInt>(numImplications);
103+
}
98104

99105
const std::vector<HighsDomainChange>& getImplications(HighsInt col, bool val,
100106
bool& infeasible) {
@@ -114,9 +120,7 @@ class HighsImplications {
114120
return implications[loc].computed;
115121
}
116122

117-
HighsInt getNumVarBounds() const { return numVarBounds; }
118-
119-
HighsInt getMaxVarBounds() const { return maxVarBounds; }
123+
bool tooManyVarBounds() const { return numVarBounds >= maxVarBounds; }
120124

121125
void addVUB(HighsInt col, HighsInt vubcol, double vubcoef,
122126
double vubconstant);

highs/mip/HighsPrimalHeuristics.cpp

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,25 @@ void HighsPrimalHeuristics::rootReducedCost() {
319319
localdom.col_lower_, localdom.col_upper_,
320320
500, // std::max(50, int(0.05 *
321321
// (mipsolver.mipdata_->num_leaves))),
322-
200 + mipsolver.mipdata_->num_nodes / 20, 12);
322+
200 + static_cast<HighsInt>(mipsolver.mipdata_->num_nodes / 20),
323+
12);
324+
}
325+
326+
static double calcFixVal(double rootchange, double fracval, double cost) {
327+
// reinforce direction of this solution away from root
328+
// solution if the change is at least 0.4
329+
// otherwise take the direction where the objective gets worse
330+
// if objective is zero round to nearest integer
331+
if (rootchange >= 0.4)
332+
return std::ceil(fracval);
333+
else if (rootchange <= -0.4)
334+
return std::floor(fracval);
335+
else if (cost > 0.0)
336+
return std::ceil(fracval);
337+
else if (cost < 0.0)
338+
return std::floor(fracval);
339+
else
340+
return std::floor(fracval + 0.5);
323341
}
324342

325343
void HighsPrimalHeuristics::RENS(const std::vector<double>& tmp) {
@@ -434,25 +452,15 @@ void HighsPrimalHeuristics::RENS(const std::vector<double>& tmp) {
434452

435453
if (numBranched == 0) {
436454
auto getFixVal = [&](HighsInt col, double fracval) {
437-
double fixval;
438-
439455
// reinforce direction of this solution away from root
440456
// solution if the change is at least 0.4
441457
// otherwise take the direction where the objective gets worse
442458
// if objective is zero round to nearest integer
443-
double rootchange = mipsolver.mipdata_->rootlpsol.empty()
444-
? 0.0
445-
: fracval - mipsolver.mipdata_->rootlpsol[col];
446-
if (rootchange >= 0.4)
447-
fixval = std::ceil(fracval);
448-
else if (rootchange <= -0.4)
449-
fixval = std::floor(fracval);
450-
else if (mipsolver.model_->col_cost_[col] > 0.0)
451-
fixval = std::ceil(fracval);
452-
else if (mipsolver.model_->col_cost_[col] < 0.0)
453-
fixval = std::floor(fracval);
454-
else
455-
fixval = std::floor(fracval + 0.5);
459+
double fixval =
460+
calcFixVal(mipsolver.mipdata_->rootlpsol.empty()
461+
? 0.0
462+
: fracval - mipsolver.mipdata_->rootlpsol[col],
463+
fracval, mipsolver.model_->col_cost_[col]);
456464
// make sure we do not set an infeasible domain
457465
fixval = std::min(localdom.col_upper_[col], fixval);
458466
fixval = std::max(localdom.col_lower_[col], fixval);
@@ -671,17 +679,8 @@ void HighsPrimalHeuristics::RINS(const std::vector<double>& relaxationsol) {
671679
// solution if the change is at least 0.4
672680
// otherwise take the direction where the objective gets worse
673681
// if objective is zero round to nearest integer
674-
double rootchange = fracval - mipsolver.mipdata_->rootlpsol[col];
675-
if (rootchange >= 0.4)
676-
fixval = std::ceil(fracval);
677-
else if (rootchange <= -0.4)
678-
fixval = std::floor(fracval);
679-
else if (mipsolver.model_->col_cost_[col] > 0.0)
680-
fixval = std::ceil(fracval);
681-
else if (mipsolver.model_->col_cost_[col] < 0.0)
682-
fixval = std::floor(fracval);
683-
else
684-
fixval = std::floor(fracval + 0.5);
682+
fixval = calcFixVal(fracval - mipsolver.mipdata_->rootlpsol[col],
683+
fracval, mipsolver.model_->col_cost_[col]);
685684
}
686685
// make sure we do not set an infeasible domain
687686
fixval = std::min(localdom.col_upper_[col], fixval);

0 commit comments

Comments
 (0)