Skip to content

Commit 64a4243

Browse files
committed
Now introduce Highs::getUserScaling
1 parent f166e24 commit 64a4243

File tree

5 files changed

+46
-29
lines changed

5 files changed

+46
-29
lines changed

highs/lp_data/HStruct.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ struct HighsUserScaleData {
196196
HighsInt num_infinite_row_bounds;
197197
HighsInt num_small_matrix_values;
198198
HighsInt num_large_matrix_values;
199+
HighsInt suggested_user_cost_scale;
200+
HighsInt suggested_user_bound_scale;
199201
void initialise(const HighsInt& user_cost_scale_,
200202
const HighsInt& user_bound_scale_,
201203
const double& infinite_cost_, const double& infinite_bound_,

highs/lp_data/Highs.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,8 +957,12 @@ HighsStatus Highs::run() {
957957
}
958958

959959
// Assess whether to warn the user about excessive bounds and costs
960-
assessExcessiveBoundCost(this->options_.log_options, this->model_,
961-
user_scale_data);
960+
assessCostBoundScaling(this->options_.log_options, this->model_,
961+
kExcessivelySmallCostValue,
962+
kExcessivelyLargeCostValue,
963+
kExcessivelySmallBoundValue,
964+
kExcessivelyLargeBoundValue,
965+
user_scale_data);
962966

963967
HighsStatus status;
964968
if (!this->multi_linear_objective_.size()) {

highs/lp_data/HighsLpUtils.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3684,6 +3684,8 @@ void HighsUserScaleData::initialise(const HighsInt& user_cost_scale_,
36843684
this->num_infinite_row_bounds = 0;
36853685
this->num_small_matrix_values = 0;
36863686
this->num_large_matrix_values = 0;
3687+
this->suggested_user_cost_scale = 0;
3688+
this->suggested_user_bound_scale = 0;
36873689
}
36883690

36893691
bool HighsUserScaleData::scaleError(std::string& message) const {

highs/lp_data/HighsSolve.cpp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,16 @@ HighsStatus solveUnconstrainedLp(const HighsOptions& options, const HighsLp& lp,
344344
}
345345

346346
// Assuming that any user scaling in user_scale_data has been applied,
347-
// determine the model coefficient ranges, assess it for excessive
348-
// values, and give scaling recommendations, when appropriate
349-
void assessExcessiveBoundCost(const HighsLogOptions log_options,
350-
const HighsModel& model,
351-
const HighsUserScaleData& user_scale_data) {
347+
// determine the model coefficient ranges, assess it for values
348+
// outside the [small, large] range, and give appropriate scaling
349+
// recommendations
350+
void assessCostBoundScaling(const HighsLogOptions log_options,
351+
const HighsModel& model,
352+
const double small_cost,
353+
const double large_cost,
354+
const double small_bound,
355+
const double large_bound,
356+
HighsUserScaleData& user_scale_data) {
352357
const bool user_cost_or_bound_scale = user_scale_data.user_cost_scale || user_scale_data.user_bound_scale;
353358
std::stringstream message;
354359
if (user_cost_or_bound_scale) {
@@ -469,24 +474,24 @@ void assessExcessiveBoundCost(const HighsLogOptions log_options,
469474

470475
const std::string problem = user_cost_or_bound_scale ? "User-scaled problem" : "Problem";
471476

472-
if (0 < min_col_cost && min_col_cost < kExcessivelySmallCostValue)
477+
if (0 < min_col_cost && min_col_cost < small_cost)
473478
highsLogUser(log_options, HighsLogType::kWarning,
474479
"%s has excessively small costs\n", problem.c_str());
475-
if (max_col_cost > kExcessivelyLargeCostValue)
480+
if (max_col_cost > large_cost)
476481
highsLogUser(log_options, HighsLogType::kWarning,
477482
"%s has excessively large costs\n", problem.c_str());
478483

479-
if (0 < min_col_bound && min_col_bound < kExcessivelySmallBoundValue)
484+
if (0 < min_col_bound && min_col_bound < small_bound)
480485
highsLogUser(log_options, HighsLogType::kWarning,
481486
"%s has excessively small column bounds\n", problem.c_str());
482-
if (max_col_bound > kExcessivelyLargeBoundValue)
487+
if (max_col_bound > large_bound)
483488
highsLogUser(log_options, HighsLogType::kWarning,
484489
"%s has excessively large column bounds\n", problem.c_str());
485490

486-
if (0 < min_row_bound && min_row_bound < kExcessivelySmallBoundValue)
491+
if (0 < min_row_bound && min_row_bound < small_bound)
487492
highsLogUser(log_options, HighsLogType::kWarning,
488493
"%s has excessively small row bounds\n", problem.c_str());
489-
if (max_row_bound > kExcessivelyLargeBoundValue)
494+
if (max_row_bound > large_bound)
490495
highsLogUser(log_options, HighsLogType::kWarning,
491496
"%s has excessively large row bounds\n", problem.c_str());
492497

@@ -541,11 +546,11 @@ void assessExcessiveBoundCost(const HighsLogOptions log_options,
541546

542547
double suggested_bound_scaling = suggestScaling(min_scalable_bound,
543548
max_scalable_bound,
544-
kExcessivelySmallBoundValue,
545-
kExcessivelyLargeBoundValue);
549+
small_bound,
550+
large_bound);
546551
// Determine the suggested (new) value for user_bound_scale,
547552
// allowing for the fact that the current value has been applied
548-
HighsInt suggested_user_bound_scale =
553+
user_scale_data.suggested_user_bound_scale =
549554
user_scale_data.user_bound_scale +
550555
std::ceil(std::log2(suggested_bound_scaling));
551556
// Determine the order of magnitude of the suggested bound scaling -
@@ -557,7 +562,7 @@ void assessExcessiveBoundCost(const HighsLogOptions log_options,
557562
//
558563
// Determine the corresponding extreme non-continuous costs and
559564
// update the extreme costs so that cost scalign can be suggested
560-
double suggested_user_bound_scale_value = pow(2.0, suggested_user_bound_scale);
565+
double suggested_user_bound_scale_value = pow(2.0, user_scale_data.suggested_user_bound_scale);
561566
min_noncontinuous_col_cost *= suggested_user_bound_scale_value;
562567
max_noncontinuous_col_cost *= suggested_user_bound_scale_value;
563568
min_col_cost =
@@ -569,11 +574,11 @@ void assessExcessiveBoundCost(const HighsLogOptions log_options,
569574

570575
double suggested_cost_scaling = suggestScaling(min_col_cost,
571576
max_col_cost,
572-
kExcessivelySmallCostValue,
573-
kExcessivelyLargeCostValue);
577+
small_cost,
578+
large_cost);
574579
// Determine the suggested (new) value for user_cost_scale,
575580
// allowing for the fact that the current value has been applied
576-
HighsInt suggested_user_cost_scale =
581+
user_scale_data.suggested_user_cost_scale =
577582
user_scale_data.user_cost_scale +
578583
std::ceil(std::log2(suggested_cost_scaling));
579584
// Determine the order of magnitude of the suggested cost scaling -
@@ -590,16 +595,16 @@ void assessExcessiveBoundCost(const HighsLogOptions log_options,
590595
if (order_of_magnitude_message)
591596
message << highsFormatToString(" Consider scaling the costs by 1e%+1d",
592597
int(suggested_cost_scale_order_of_magnitude));
593-
if (suggested_user_cost_scale) {
598+
if (user_scale_data.suggested_user_cost_scale) {
594599
if (!order_of_magnitude_message) {
595600
message << " Consider";
596601
} else {
597602
message << ", or";
598603
}
599604
message << highsFormatToString(" setting the user_cost_scale option to %d\n",
600-
int(suggested_user_cost_scale));
605+
int(user_scale_data.suggested_user_cost_scale));
601606
}
602-
if (order_of_magnitude_message || suggested_user_cost_scale)
607+
if (order_of_magnitude_message || user_scale_data.suggested_user_cost_scale)
603608
highsLogUser(log_options, HighsLogType::kWarning, "%s\n", message.str().c_str());
604609

605610
message.str(std::string());
@@ -610,16 +615,16 @@ void assessExcessiveBoundCost(const HighsLogOptions log_options,
610615
if (order_of_magnitude_message)
611616
message << highsFormatToString(" Consider scaling the bounds by 1e%+1d",
612617
int(suggested_bound_scale_order_of_magnitude));
613-
if (suggested_user_bound_scale) {
618+
if (user_scale_data.suggested_user_bound_scale) {
614619
if (!order_of_magnitude_message) {
615620
message << " Consider";
616621
} else {
617622
message << ", or";
618623
}
619624
message << highsFormatToString(" setting the user_bound_scale option to %d\n",
620-
int(suggested_user_bound_scale));
625+
int(user_scale_data.suggested_user_bound_scale));
621626
}
622-
if (order_of_magnitude_message || suggested_user_bound_scale)
627+
if (order_of_magnitude_message || user_scale_data.suggested_user_bound_scale)
623628
highsLogUser(log_options, HighsLogType::kWarning, "%s\n", message.str().c_str());
624629

625630
}

highs/lp_data/HighsSolve.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ HighsStatus solveUnconstrainedLp(const HighsOptions& options, const HighsLp& lp,
1818
HighsModelStatus& model_status,
1919
HighsInfo& highs_info, HighsSolution& solution,
2020
HighsBasis& basis);
21-
void assessExcessiveBoundCost(const HighsLogOptions log_options,
22-
const HighsModel& model,
23-
const HighsUserScaleData& user_scale_data);
21+
void assessCostBoundScaling(const HighsLogOptions log_options,
22+
const HighsModel& model,
23+
const double small_cost,
24+
const double large_cost,
25+
const double small_bound,
26+
const double large_bound,
27+
HighsUserScaleData& user_scale_data);
2428
#endif // LP_DATA_HIGHSSOLVE_H_

0 commit comments

Comments
 (0)