Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass model name #1951

Merged
merged 5 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions check/TestNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,16 @@ TEST_CASE("highs-names", "[highs_names]") {

std::remove(solution_file.c_str());
}

TEST_CASE("highs-model-name", "[model_names]") {

Highs highs;
const HighsLp& lp = highs.getLp();

std::string name = lp.model_name_;
REQUIRE(name == "");

highs.passModelName("new_name");
name = lp.model_name_;
REQUIRE(name == "new_name");
}
5 changes: 5 additions & 0 deletions src/Highs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/highs_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 10 additions & 0 deletions src/interfaces/highs_c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
10 changes: 10 additions & 0 deletions src/lp_data/Highs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading