Skip to content

Commit 5a670fa

Browse files
committed
Introduced HSimplexNla::hasMatrixScale() to replace test scale_ == nullptr now that scale_ is not null when there is cost scaling, but no matrix scaling
1 parent 0347451 commit 5a670fa

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

highs/simplex/HSimplexNla.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ void HSimplexNla::update(HVector* aq, HVector* ep, HighsInt* iRow,
133133

134134
double HSimplexNla::rowEp2NormInScaledSpace(const HighsInt iRow,
135135
const HVector& row_ep) const {
136-
if (scale_ == NULL) {
137-
return row_ep.norm2();
138-
}
136+
if (!hasMatrixScale()) return row_ep.norm2();
139137
const vector<double>& row_scale = scale_->row;
140138
// Get the 2-norm of row_ep in the scaled space otherwise for
141139
// checking
@@ -186,7 +184,7 @@ double HSimplexNla::rowEp2NormInScaledSpace(const HighsInt iRow,
186184
void HSimplexNla::transformForUpdate(HVector* aq, HVector* ep,
187185
const HighsInt variable_in,
188186
const HighsInt row_out) {
189-
if (scale_ == NULL) return;
187+
if (!hasMatrixScale()) return;
190188
// For (\hat)aq, UPDATE needs packValue and array[row_out] to
191189
// correspond to \bar{B}^{-1}(R.aq.cq), but CB.\bar{B}^{-1}(R.aq)
192190
// has been computed.
@@ -221,13 +219,13 @@ void HSimplexNla::transformForUpdate(HVector* aq, HVector* ep,
221219
}
222220

223221
double HSimplexNla::variableScaleFactor(const HighsInt iVar) const {
224-
if (scale_ == NULL) return 1.0;
222+
if (!hasMatrixScale()) return 1.0;
225223
return iVar < lp_->num_col_ ? scale_->col[iVar]
226224
: 1.0 / scale_->row[iVar - lp_->num_col_];
227225
}
228226

229227
double HSimplexNla::basicColScaleFactor(const HighsInt iCol) const {
230-
if (scale_ == NULL) return 1.0;
228+
if (!hasMatrixScale()) return 1.0;
231229
return variableScaleFactor(basic_index_[iCol]);
232230
}
233231

@@ -243,7 +241,7 @@ void HSimplexNla::setPivotThreshold(const double new_pivot_threshold) {
243241
}
244242

245243
void HSimplexNla::applyBasisMatrixRowScale(HVector& rhs) const {
246-
if (scale_ == NULL) return;
244+
if (!hasMatrixScale()) return;
247245
const vector<double>& row_scale = scale_->row;
248246
HighsInt to_entry;
249247
const bool use_row_indices =
@@ -255,7 +253,7 @@ void HSimplexNla::applyBasisMatrixRowScale(HVector& rhs) const {
255253
}
256254

257255
void HSimplexNla::applyBasisMatrixColScale(HVector& rhs) const {
258-
if (scale_ == NULL) return;
256+
if (!hasMatrixScale()) return;
259257
const vector<double>& col_scale = scale_->col;
260258
const vector<double>& row_scale = scale_->row;
261259
HighsInt to_entry;
@@ -273,7 +271,7 @@ void HSimplexNla::applyBasisMatrixColScale(HVector& rhs) const {
273271
}
274272

275273
void HSimplexNla::unapplyBasisMatrixRowScale(HVector& rhs) const {
276-
if (scale_ == NULL) return;
274+
if (!hasMatrixScale()) return;
277275
const vector<double>& row_scale = scale_->row;
278276
HighsInt to_entry;
279277
const bool use_row_indices =
@@ -421,9 +419,15 @@ void HSimplexNla::reportPackValue(const std::string message,
421419
printf("\n");
422420
}
423421

422+
bool HSimplexNla::hasMatrixScale() const {
423+
if (scale_ == nullptr) return false;
424+
if (scale_->col.size() && scale_->row.size()) return true;
425+
return false;
426+
}
427+
424428
HighsDebugStatus HSimplexNla::debugCheckData(const std::string message) const {
425429
std::string scale_status;
426-
if (scale_ == NULL) {
430+
if (!hasMatrixScale()) {
427431
scale_status = "NULL";
428432
} else {
429433
scale_status = "non-NULL";
@@ -439,7 +443,7 @@ HighsDebugStatus HSimplexNla::debugCheckData(const std::string message) const {
439443
const HighsInt* factor_Aindex = factor_.getAindex();
440444
const double* factor_Avalue = factor_.getAvalue();
441445

442-
if (scale_ == NULL) {
446+
if (!hasMatrixScale()) {
443447
if (factor_Astart != lp_->a_matrix_.start_.data()) error0_found = true;
444448
if (factor_Aindex != lp_->a_matrix_.index_.data()) error1_found = true;
445449
if (factor_Avalue != lp_->a_matrix_.value_.data()) error2_found = true;

highs/simplex/HSimplexNla.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class HSimplexNla {
111111
const HVector* vector, const bool force = false) const;
112112
void reportPackValue(const std::string message, const HVector* vector,
113113
const bool force = false) const;
114+
bool hasMatrixScale() const;
114115
// Debug methods
115116
HighsDebugStatus debugCheckData(const std::string message = "") const;
116117
HighsDebugStatus debugCheckInvert(const std::string message,

0 commit comments

Comments
 (0)