From a904b210fb4858cf7e5897e0d3f494442e844b94 Mon Sep 17 00:00:00 2001 From: Ivet Galabova Date: Tue, 24 Sep 2024 12:15:23 +0300 Subject: [PATCH 1/3] passModelName added to C++ and C api --- check/TestNames.cpp | 13 +++++++++++++ src/Highs.h | 5 +++++ src/interfaces/highs_c_api.cpp | 4 ++++ src/interfaces/highs_c_api.h | 10 ++++++++++ src/lp_data/Highs.cpp | 10 ++++++++++ 5 files changed, 42 insertions(+) diff --git a/check/TestNames.cpp b/check/TestNames.cpp index bddecfdc4f..b2ceba6cdd 100644 --- a/check/TestNames.cpp +++ b/check/TestNames.cpp @@ -118,3 +118,16 @@ TEST_CASE("highs-names", "[highs_names]") { std::remove(solution_file.c_str()); } + +TEST_CASE("highs-names", "[model_names]") { + + Highs highs; + const HighsLp& lp = highs.getLp(); + + std::string name = lp.model_name_; + REQUIRE(name == ""); + + highs.passModelName("new_name"); + std::string name = lp.model_name_; + REQUIRE(name == "new_name"); +} diff --git a/src/Highs.h b/src/Highs.h index c9c42f3a8c..1ce37977d7 100644 --- a/src/Highs.h +++ b/src/Highs.h @@ -160,6 +160,11 @@ class Highs { */ HighsStatus passRowName(const HighsInt row, const std::string& name); + /** + * @brief Pass a model name to the incumbent model + */ + HighsStatus passModelName(const std::string& name); + /** * @brief Read in a model */ diff --git a/src/interfaces/highs_c_api.cpp b/src/interfaces/highs_c_api.cpp index bbdd3f5e59..5dd76f62b4 100644 --- a/src/interfaces/highs_c_api.cpp +++ b/src/interfaces/highs_c_api.cpp @@ -301,6 +301,10 @@ HighsInt Highs_passColName(const void* highs, const HighsInt col, return (HighsInt)((Highs*)highs)->passColName(col, std::string(name)); } +HighsInt Highs_passModelName(const void* highs, const char* name) { + return (HighsInt)((Highs*)highs)->passModelName(std::string(name)); +} + HighsInt Highs_readOptions(const void* highs, const char* filename) { return (HighsInt)((Highs*)highs)->readOptions(filename); } diff --git a/src/interfaces/highs_c_api.h b/src/interfaces/highs_c_api.h index 43833a9c75..6237dbac49 100644 --- a/src/interfaces/highs_c_api.h +++ b/src/interfaces/highs_c_api.h @@ -581,6 +581,16 @@ HighsInt Highs_passRowName(const void* highs, const HighsInt row, HighsInt Highs_passColName(const void* highs, const HighsInt col, const char* name); +/** + * Pass the name of the model. + * + * @param highs A pointer to the Highs instance. + * @param name The name of the model. + * + * @returns A `kHighsStatus` constant indicating whether the call succeeded. + */ +HighsInt Highs_passModelName(const void* highs, const char* name); + /** * Read the option values from file. * diff --git a/src/lp_data/Highs.cpp b/src/lp_data/Highs.cpp index 43cd3094c6..b20f4b2c3a 100644 --- a/src/lp_data/Highs.cpp +++ b/src/lp_data/Highs.cpp @@ -618,6 +618,16 @@ HighsStatus Highs::passRowName(const HighsInt row, const std::string& name) { return HighsStatus::kOk; } +HighsStatus Highs::passModelName(const std::string& name) { + if (int(name.length()) <= 0) { + highsLogUser(options_.log_options, HighsLogType::kError, + "Cannot define empty model names\n"); + return HighsStatus::kError; + } + this->model_.lp_.model_name_ = name; + return HighsStatus::kOk; +} + HighsStatus Highs::readModel(const std::string& filename) { this->logHeader(); HighsStatus return_status = HighsStatus::kOk; From 167fc08e929735b762c19f0b742cd05186ef7fba Mon Sep 17 00:00:00 2001 From: Ivet Galabova Date: Thu, 26 Sep 2024 18:12:05 +0300 Subject: [PATCH 2/3] fix test --- check/TestNames.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check/TestNames.cpp b/check/TestNames.cpp index b2ceba6cdd..738e53785b 100644 --- a/check/TestNames.cpp +++ b/check/TestNames.cpp @@ -128,6 +128,6 @@ TEST_CASE("highs-names", "[model_names]") { REQUIRE(name == ""); highs.passModelName("new_name"); - std::string name = lp.model_name_; + name = lp.model_name_; REQUIRE(name == "new_name"); } From 6ab45a825b80c9b0a0675608ce2e2f6692651a38 Mon Sep 17 00:00:00 2001 From: Ivet Galabova Date: Thu, 26 Sep 2024 18:13:21 +0300 Subject: [PATCH 3/3] test name --- check/TestNames.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check/TestNames.cpp b/check/TestNames.cpp index 738e53785b..f0d11fc4a8 100644 --- a/check/TestNames.cpp +++ b/check/TestNames.cpp @@ -119,7 +119,7 @@ TEST_CASE("highs-names", "[highs_names]") { std::remove(solution_file.c_str()); } -TEST_CASE("highs-names", "[model_names]") { +TEST_CASE("highs-model-name", "[model_names]") { Highs highs; const HighsLp& lp = highs.getLp();