Skip to content

Commit 58a744b

Browse files
committed
Round to powers of 2
1 parent 92d105e commit 58a744b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

highs/ipm/hipo/ipm/Model.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,10 @@ void Model::CRscaling() {
458458
}
459459

460460
void Model::applyScaling() {
461+
// make sure that scaling is a power of 2
462+
for (Int i = 0; i < n_; ++i) colscale_[i] = roundToPowerOf2(colscale_[i]);
463+
for (Int i = 0; i < m_; ++i) rowscale_[i] = roundToPowerOf2(rowscale_[i]);
464+
461465
// Column has been scaled up by colscale_[col], so cost is scaled up and
462466
// bounds are scaled down
463467
for (Int col = 0; col < n_; ++col) {
@@ -497,8 +501,7 @@ void Model::onePassNormScaling() {
497501
}
498502

499503
// apply row scaling
500-
for (Int i = 0; i < m_; ++i)
501-
rowscale_[i] *= roundToPowerOf2(1.0 / std::sqrt(norm_rows[i]));
504+
for (Int i = 0; i < m_; ++i) rowscale_[i] *= 1.0 / std::sqrt(norm_rows[i]);
502505

503506
// infinity norm of columns
504507
std::vector<double> norm_cols(n_);
@@ -513,8 +516,7 @@ void Model::onePassNormScaling() {
513516
}
514517

515518
// apply col scaling
516-
for (Int i = 0; i < n_; ++i)
517-
colscale_[i] *= roundToPowerOf2(1.0 / std::sqrt(norm_cols[i]));
519+
for (Int i = 0; i < n_; ++i) colscale_[i] *= 1.0 / std::sqrt(norm_cols[i]);
518520
}
519521

520522
void Model::boundScaling() {
@@ -528,9 +530,9 @@ void Model::boundScaling() {
528530
const double diff = std::abs(u - l);
529531

530532
if (diff < kSmallBoundDiff)
531-
colscale_[i] *= roundToPowerOf2(diff / kSmallBoundDiff);
533+
colscale_[i] *= diff / kSmallBoundDiff;
532534
else if (diff > kLargeBoundDiff) {
533-
colscale_[i] *= roundToPowerOf2(diff / kLargeBoundDiff);
535+
colscale_[i] *= diff / kLargeBoundDiff;
534536
}
535537
}
536538
}

0 commit comments

Comments
 (0)