Skip to content

Commit bccb6e0

Browse files
committed
check/TestMipSolver.cpp: add tolerance to a few tests
We add tolerance to a few comparisons to fix a family of test failures that look like, .../check/TestMipSolver.cpp:1162: FAILED: REQUIRE( h.getInfo().objective_function_value == mip_optimal_objective ) with expansion: 1201500.0 == 1201499.9999999998 A double_equal_tolerance = 1e-5 was already defined in this file, so we have used that as the absolute tolerance.
1 parent f3cf9ff commit bccb6e0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

check/TestMipSolver.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,8 @@ TEST_CASE("get-fixed-lp", "[highs_test_mip_solver]") {
12111211
h.setOptionValue("presolve", kHighsOffString);
12121212
REQUIRE(h.run() == HighsStatus::kOk);
12131213

1214-
REQUIRE(h.getInfo().objective_function_value == mip_optimal_objective);
1214+
REQUIRE(std::abs(h.getInfo().objective_function_value - mip_optimal_objective)
1215+
< double_equal_tolerance);
12151216
// In calling changeColsBounds, the incumbent solution was always
12161217
// cleared, so there was no information from which to construct an
12171218
// advanced basis. Hence simplex starts from a logical basis and
@@ -1230,7 +1231,8 @@ TEST_CASE("get-fixed-lp", "[highs_test_mip_solver]") {
12301231
h.setSolution(solution);
12311232
REQUIRE(h.run() == HighsStatus::kOk);
12321233

1233-
REQUIRE(h.getInfo().objective_function_value == mip_optimal_objective);
1234+
REQUIRE(std::abs(h.getInfo().objective_function_value - mip_optimal_objective)
1235+
< double_equal_tolerance);
12341236
REQUIRE(h.getInfo().simplex_iteration_count == 0);
12351237

12361238
// Now re-load the MIP, re-solve, and get the fixed LP
@@ -1246,14 +1248,16 @@ TEST_CASE("get-fixed-lp", "[highs_test_mip_solver]") {
12461248
REQUIRE(h.passModel(fixed_lp) == HighsStatus::kOk);
12471249
REQUIRE(h.run() == HighsStatus::kOk);
12481250

1249-
REQUIRE(h.getInfo().objective_function_value == mip_optimal_objective);
1251+
REQUIRE(std::abs(h.getInfo().objective_function_value - mip_optimal_objective)
1252+
< double_equal_tolerance);
12501253

12511254
// Now run from saved solution (without presolve)
12521255
h.clearSolver();
12531256
h.setSolution(solution);
12541257
REQUIRE(h.run() == HighsStatus::kOk);
12551258

1256-
REQUIRE(h.getInfo().objective_function_value == mip_optimal_objective);
1259+
REQUIRE(std::abs(h.getInfo().objective_function_value - mip_optimal_objective)
1260+
< double_equal_tolerance);
12571261
REQUIRE(h.getInfo().simplex_iteration_count == 0);
12581262

12591263
REQUIRE(h.readModel(model_file) == HighsStatus::kOk);
@@ -1369,7 +1373,8 @@ TEST_CASE("row-fixed-lp", "[highs_test_mip_solver]") {
13691373
solution.row_value.data());
13701374
h.setOptionValue("presolve", kHighsOffString);
13711375
REQUIRE(h.run() == HighsStatus::kOk);
1372-
REQUIRE(h.getInfo().objective_function_value <= mip_optimal_objective);
1376+
REQUIRE(h.getInfo().objective_function_value
1377+
<= mip_optimal_objective + double_equal_tolerance);
13731378

13741379
h.resetGlobalScheduler(true);
13751380
}

0 commit comments

Comments
 (0)