From 0f478a9aa0afd7ef9f23b4fecf7e5e66d3fdf4e7 Mon Sep 17 00:00:00 2001 From: JAJHall Date: Sat, 26 Oct 2024 20:35:10 +0100 Subject: [PATCH] Added maximization test to dual objective value unit test --- check/TestLpSolvers.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/check/TestLpSolvers.cpp b/check/TestLpSolvers.cpp index 75dbf662f2..2355de6826 100644 --- a/check/TestLpSolvers.cpp +++ b/check/TestLpSolvers.cpp @@ -2,7 +2,7 @@ #include "Highs.h" #include "catch.hpp" -const bool dev_run = true; // false; +const bool dev_run = false; struct IterationCount { HighsInt simplex; @@ -491,6 +491,34 @@ TEST_CASE("blending-lp-ipm", "[highs_lp_solver]") { REQUIRE(highs.getModelStatus() == HighsModelStatus::kOptimal); } +TEST_CASE("dual-objective-max", "[highs_lp_solver]") { + Highs highs; + highs.setOptionValue("output_flag", dev_run); + HighsLp lp; + lp.num_col_ = 2; + lp.num_row_ = 2; + lp.sense_ = ObjSense::kMaximize; + lp.offset_ = 10; + lp.col_cost_ = {8, 10}; + lp.col_lower_ = {0, 0}; + lp.col_upper_ = {kHighsInf, kHighsInf}; + lp.row_lower_ = {-kHighsInf, -kHighsInf}; + lp.row_upper_ = {80, 120}; + lp.a_matrix_.start_ = {0, 2, 4}; + lp.a_matrix_.index_ = {0, 1, 0, 1}; + lp.a_matrix_.value_ = {1, 1, 2, 4}; + highs.passModel(lp); + highs.run(); + double dual_objective; + HighsStatus return_status = highs.getDualObjectiveValue(dual_objective); + REQUIRE(return_status == HighsStatus::kOk); + double primal_objective = highs.getInfo().objective_function_value; + double relative_primal_dual_gap = + std::fabs(primal_objective - dual_objective) / + std::max(1.0, std::fabs(primal_objective)); + REQUIRE(relative_primal_dual_gap < 1e-12); +} + TEST_CASE("dual-objective", "[highs_lp_solver]") { testDualObjective("avgas"); testDualObjective("adlittle");