From 5c5868e1e970dea429796b29fb2b877655ae8ae3 Mon Sep 17 00:00:00 2001 From: Henri Lefebvre Date: Thu, 2 Nov 2023 18:53:43 +0100 Subject: [PATCH] handle return status of HiGHS --- .../wrappers/HiGHS/Optimizers_HiGHS.h | 2 +- .../wrappers/HiGHS/Optimizers_HiGHS.cpp | 23 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/include/idol/optimizers/wrappers/HiGHS/Optimizers_HiGHS.h b/lib/include/idol/optimizers/wrappers/HiGHS/Optimizers_HiGHS.h index 0825c58f..991d9f33 100644 --- a/lib/include/idol/optimizers/wrappers/HiGHS/Optimizers_HiGHS.h +++ b/lib/include/idol/optimizers/wrappers/HiGHS/Optimizers_HiGHS.h @@ -76,7 +76,7 @@ class idol::Optimizers::HiGHS : public OptimizerWithLazyUpdates { [[nodiscard]] unsigned int get_solution_index() const override; void set_solution_index(unsigned int t_index) override; - void analyze_status(); + void analyze_status(HighsStatus t_status); public: explicit HiGHS(const Model& t_model, bool t_continuous_relaxation); diff --git a/lib/src/optimizers/wrappers/HiGHS/Optimizers_HiGHS.cpp b/lib/src/optimizers/wrappers/HiGHS/Optimizers_HiGHS.cpp index 7cd3dc38..c28ab128 100644 --- a/lib/src/optimizers/wrappers/HiGHS/Optimizers_HiGHS.cpp +++ b/lib/src/optimizers/wrappers/HiGHS/Optimizers_HiGHS.cpp @@ -278,14 +278,14 @@ void idol::Optimizers::HiGHS::hook_optimize() { delete[] m_farkas_certificate; m_farkas_certificate = nullptr; - m_model.run(); + auto result = m_model.run(); - analyze_status(); + analyze_status(result); if (m_solution_status == Fail) { m_model.clearSolver(); - m_model.run(); - analyze_status(); + result = m_model.run(); + analyze_status(result); } if (get_param_infeasible_or_unbounded_info() && m_solution_status == Unbounded) { @@ -322,7 +322,13 @@ void idol::Optimizers::HiGHS::hook_optimize() { } -void idol::Optimizers::HiGHS::analyze_status() { +void idol::Optimizers::HiGHS::analyze_status(HighsStatus t_status) { + + if (t_status != HighsStatus::kOk) { + m_solution_status = Fail; + m_solution_reason = NotSpecified; + return; + } const auto status = m_model.getModelStatus(); @@ -378,8 +384,13 @@ void idol::Optimizers::HiGHS::run_without_presolve() { return; } m_model.setOptionValue("presolve", "off"); - m_model.run(); + auto result = m_model.run(); m_model.setOptionValue("presolve", old_presolve_setting); + + if (result != HighsStatus::kOk) { + m_solution_status = Fail; + m_solution_reason = NotSpecified; + } } void idol::Optimizers::HiGHS::set_param_time_limit(double t_time_limit) {