Skip to content

Commit ff30e2b

Browse files
committed
Add general scale function in HighsCutGeneration
1 parent 89ee10f commit ff30e2b

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

highs/mip/HighsCutGeneration.cpp

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,25 @@ bool HighsCutGeneration::cmirCutGenerationHeuristic(double minEfficacy,
717717
return true;
718718
}
719719

720+
double HighsCutGeneration::scale(double val) {
721+
int expshift = 0;
722+
std::frexp(val, &expshift);
723+
expshift = -expshift;
724+
725+
// Don't scale the coefficients by more than +1024 (violations can increase)
726+
expshift = std::min(10, expshift);
727+
728+
// Scale rhs
729+
rhs = std::ldexp(static_cast<double>(rhs), expshift);
730+
731+
// Scale row
732+
for (HighsInt i = 0; i != rowlen; ++i)
733+
vals[i] = std::ldexp(vals[i], expshift);
734+
735+
// Return scaling factor
736+
return std::ldexp(1.0, expshift);
737+
}
738+
720739
bool HighsCutGeneration::postprocessCut() {
721740
// right hand sides slightly below zero are likely due to numerical errors and
722741
// can cause numerical troubles with scaling, so set them to zero
@@ -848,27 +867,12 @@ bool HighsCutGeneration::postprocessCut() {
848867
for (HighsInt i = 0; i != rowlen; ++i)
849868
minAbsValue = std::min(std::abs(vals[i]), minAbsValue);
850869

851-
int expshift;
852-
std::frexp(minAbsValue - epsilon, &expshift);
853-
expshift = -expshift;
854-
855-
rhs = std::ldexp((double)rhs, expshift);
856-
857-
for (HighsInt i = 0; i != rowlen; ++i)
858-
vals[i] = std::ldexp(vals[i], expshift);
870+
scale(minAbsValue - epsilon);
859871
}
860872
} else {
861873
// the support is not integral, scale cut to have the largest coefficient
862874
// around 1.0
863-
int expshift;
864-
std::frexp(maxAbsValue - epsilon, &expshift);
865-
expshift = -expshift;
866-
// Don't scale the coefficients by more than +1024 (violations can increase)
867-
expshift = std::min(10, expshift);
868-
rhs = std::ldexp((double)rhs, expshift);
869-
870-
for (HighsInt i = 0; i != rowlen; ++i)
871-
vals[i] = std::ldexp(vals[i], expshift);
875+
scale(maxAbsValue - epsilon);
872876
}
873877

874878
return true;
@@ -896,14 +900,7 @@ bool HighsCutGeneration::preprocessBaseInequality(bool& hasUnboundedInts,
896900
for (HighsInt i = 0; i < rowlen; ++i)
897901
maxAbsVal = std::max(std::abs(vals[i]), maxAbsVal);
898902

899-
int expshift = 0;
900-
std::frexp(maxAbsVal, &expshift);
901-
expshift = -expshift;
902-
// Don't scale the coefficients by more than +1024 (violations can increase)
903-
expshift = std::min(10, expshift);
904-
initialScale = std::ldexp(1.0, expshift);
905-
rhs *= initialScale;
906-
for (HighsInt i = 0; i < rowlen; ++i) vals[i] = std::ldexp(vals[i], expshift);
903+
scale(maxAbsVal);
907904

908905
isintegral.resize(rowlen);
909906
for (HighsInt i = 0; i != rowlen; ++i) {

highs/mip/HighsCutGeneration.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class HighsCutGeneration {
6565
bool cmirCutGenerationHeuristic(double minEfficacy,
6666
bool onlyInitialCMIRScale = false);
6767

68+
double scale(double val);
69+
6870
bool postprocessCut();
6971

7072
bool preprocessBaseInequality(bool& hasUnboundedInts, bool& hasGeneralInts,

0 commit comments

Comments
 (0)