Skip to content

Commit e079ec3

Browse files
committed
Large bounds test OK for LP/MIP/QP
1 parent 42b9d8d commit e079ec3

File tree

3 files changed

+73
-24
lines changed

3 files changed

+73
-24
lines changed

check/TestUserScale.cpp

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "Highs.h"
55
#include "catch.hpp"
66

7-
const bool dev_run = false;
7+
const bool dev_run = true;//false;
88
const double inf = kHighsInf;
99

1010
bool doubleEqual0(const double v0, const double v1) {
@@ -283,41 +283,57 @@ TEST_CASE("ill-scaled-model", "[highs_user_scale]") {
283283
h.run();
284284
}
285285

286-
const bool all_test = true;
287-
const bool lp_test = all_test || false;
288-
const bool mip_test = all_test || true;
286+
const bool all_test = true;//false;//
287+
const bool lp_test = all_test || true;
288+
const bool mip_test = all_test || false;
289289
const bool qp_test = all_test || false;
290290

291+
const bool ok_test = all_test || false;
291292
const double ok_cost = 1.0;
292293
const double ok_hessian = 1.0;
293294
const double ok_col_lower = 0.0;
294295
const double ok_bound = 1.0;
295296

296297
// If the costs are too small, it becomes a feasibility problem,
297298
// so don't get the same objective value in testUserScale
298-
const bool small_cost_test = true;
299+
const bool small_cost_test = all_test || false;
299300
const double small_cost = 0.5e-4;
300301
const double small_hessian = 1e-4;
301302
const double small_col_lower = 1e-8;
303+
const double large_cost = 1e8;
304+
const double large_hessian = 1e4;
305+
const double large_bound = 1e8;
302306
if (lp_test) {
303-
if (dev_run)
304-
printf(
305-
"\n================\nill-scaled-model: LP test\n================\n");
306-
testLp(h, ok_cost, ok_col_lower, ok_bound);
307+
if (ok_test) {
308+
if (dev_run)
309+
printf(
310+
"\n================\nill-scaled-model: LP test\n================\n");
311+
testLp(h, ok_cost, ok_col_lower, ok_bound);
312+
}
307313
if (small_cost_test) {
308314
if (dev_run)
309315
printf(
310316
"\n================\nill-scaled-model: LP test - small costs and "
311317
"column LB\n================\n");
312318
testLp(h, small_cost, small_col_lower, ok_bound);
313319
}
320+
if (dev_run)
321+
printf(
322+
"\n================\nill-scaled-model: LP test - large costs\n================\n");
323+
testLp(h, large_cost, small_col_lower, ok_bound);
324+
if (dev_run)
325+
printf(
326+
"\n================\nill-scaled-model: LP test - large bounds\n================\n");
327+
testLp(h, ok_cost, small_col_lower, large_bound);
314328
}
315329

316330
if (mip_test) {
317-
if (dev_run)
318-
printf(
319-
"\n================\nill-scaled-model: MIP test\n================\n");
320-
testMip(h, ok_cost, ok_col_lower, ok_bound);
331+
if (ok_test) {
332+
if (dev_run)
333+
printf(
334+
"\n================\nill-scaled-model: MIP test\n================\n");
335+
testMip(h, ok_cost, ok_col_lower, ok_bound);
336+
}
321337

322338
if (small_cost_test) {
323339
if (dev_run)
@@ -326,14 +342,32 @@ TEST_CASE("ill-scaled-model", "[highs_user_scale]") {
326342
"column LB\n================\n");
327343
testMip(h, small_cost, small_col_lower, ok_bound);
328344
}
345+
if (dev_run)
346+
printf(
347+
"\n================\nill-scaled-model: MIP test - large costs\n================\n");
348+
testMip(h, large_cost, small_col_lower, ok_bound);
349+
if (dev_run)
350+
printf(
351+
"\n================\nill-scaled-model: MIP test - large bounds\n================\n");
352+
testMip(h, ok_cost, small_col_lower, large_bound);
329353
}
330354

331355
if (qp_test) {
332-
if (dev_run)
333-
printf(
334-
"\n================\nill-scaled-model: QP test\n================\n");
335-
testQp(h, ok_cost, ok_hessian, ok_col_lower, ok_bound);
356+
if (ok_test) {
357+
if (dev_run)
358+
printf(
359+
"\n================\nill-scaled-model: QP test\n================\n");
360+
testQp(h, ok_cost, ok_hessian, ok_col_lower, ok_bound);
361+
}
336362
// QP solver can't handle small costs and Hessian
363+
if (dev_run)
364+
printf(
365+
"\n================\nill-scaled-model: QP test - large costs\n================\n");
366+
testQp(h, large_cost, ok_hessian, ok_col_lower, ok_bound);
367+
if (dev_run)
368+
printf(
369+
"\n================\nill-scaled-model: QP test - large bounds\n================\n");
370+
testQp(h, ok_cost, ok_hessian, small_col_lower, large_bound);
337371
}
338372

339373
h.resetGlobalScheduler(true);

highs/lp_data/Highs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ HighsStatus Highs::run() {
963963
// and user_bound_scale
964964
assessExcessiveObjectiveBoundScaling(this->options_.log_options, this->model_,
965965
user_scale_data);
966-
// this->writeModel("");
966+
this->writeModel("");
967967
HighsStatus status;
968968
if (!this->multi_linear_objective_.size()) {
969969
status = this->optimizeModel();

highs/lp_data/HighsSolve.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ void assessExcessiveObjectiveBoundScaling(const HighsLogOptions log_options,
526526
highsLogUser(log_options, HighsLogType::kWarning,
527527
"%s has some excessively large row bounds\n", problem.c_str());
528528

529-
// Determine recommended user scaling values
529+
// Lambda to determine recommended user scaling values
530530
auto suggestScaling = [&](double min_value, double max_value,
531531
double small_value, double large_value) {
532532
double ratio = 1;
@@ -543,17 +543,33 @@ void assessExcessiveObjectiveBoundScaling(const HighsLogOptions log_options,
543543
return ratio;
544544
};
545545

546+
// Lambda to for outward rounding of log
547+
auto outerRoundedLog = [&](const double value, const HighsInt base) {
548+
assert(value > 0);
549+
assert(base == 2 || base == 10);
550+
HighsInt rounded_log = 0;
551+
if (base == 2) {
552+
rounded_log = value < 1 ?
553+
std::floor(std::log2(value)) :
554+
std::ceil(std::log2(value));
555+
} else {
556+
rounded_log = value < 1 ?
557+
std::floor(std::log10(value)) :
558+
std::ceil(std::log10(value));
559+
}
560+
return rounded_log;
561+
};
546562
double suggested_bound_scaling = suggestScaling(
547563
min_scalable_bound, max_scalable_bound, small_bound, large_bound);
548564
// Determine the suggested (new) value for user_bound_scale,
549565
// allowing for the fact that the current value has been applied
550-
HighsInt dl_user_bound_scale = std::ceil(std::log2(suggested_bound_scaling));
566+
HighsInt dl_user_bound_scale = outerRoundedLog(suggested_bound_scaling, 2);
551567
user_scale_data.suggested_user_bound_scale =
552568
user_scale_data.user_bound_scale + dl_user_bound_scale;
553569
// Determine the order of magnitude of the suggested bound scaling -
554570
// just for logging
555571
HighsInt suggested_bound_scale_order_of_magnitude =
556-
std::ceil(std::log10(suggested_bound_scaling));
572+
outerRoundedLog(suggested_bound_scaling, 10);
557573
// Applying the suggested bound scaling requires the costs and
558574
// matrix columns of non-continuous variables to be scaled, and any
559575
// Hessian entries are also scaled
@@ -582,14 +598,13 @@ void assessExcessiveObjectiveBoundScaling(const HighsLogOptions log_options,
582598
small_objective_coefficient, large_objective_coefficient);
583599
// Determine the suggested (new) value for user_objective_scale,
584600
// allowing for the fact that the current value has been applied
585-
HighsInt dl_user_objective_scale =
586-
std::ceil(std::log2(suggested_objective_scaling));
601+
HighsInt dl_user_objective_scale = outerRoundedLog(suggested_objective_scaling, 2);
587602
user_scale_data.suggested_user_objective_scale =
588603
user_scale_data.user_objective_scale + dl_user_objective_scale;
589604
// Determine the order of magnitude of the suggested objective scaling -
590605
// just for logging
591606
HighsInt suggested_objective_scale_order_of_magnitude =
592-
std::ceil(std::log10(suggested_objective_scaling));
607+
outerRoundedLog(suggested_objective_scaling, 10);
593608

594609
// Only report the order of magnitude scaling if there is no user
595610
// scaling

0 commit comments

Comments
 (0)