Skip to content

Commit

Permalink
Added options write_presolved_model_to_file and write_presolved_model…
Browse files Browse the repository at this point in the history
…_file, and writes out OK unless file name is empty
  • Loading branch information
jajhall committed Jul 26, 2024
1 parent d04eae8 commit 76a7e76
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/RunHighs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ int main(int argc, char** argv) {
return (int)read_solution_status;
}
}
if (options.write_presolved_model_to_file) {
// Run presolve and write the presolved model to a file
HighsStatus status = highs.presolve();
if (status == HighsStatus::kError) return int(status);
HighsPresolveStatus model_presolve_status = highs.getModelPresolveStatus();
const bool ok_to_write =
model_presolve_status == HighsPresolveStatus::kNotReduced ||
model_presolve_status == HighsPresolveStatus::kReduced ||
model_presolve_status == HighsPresolveStatus::kReducedToEmpty ||
model_presolve_status == HighsPresolveStatus::kTimeout;
if (!ok_to_write) {
highsLogUser(log_options, HighsLogType::kInfo,
"No presolved model to write to file\n");
return int(status);
}
status = highs.writePresolvedModel(options.write_presolved_model_file);
return int(status);
}
// Solve the model
HighsStatus run_status = highs.run();
if (run_status == HighsStatus::kError) return int(run_status);
Expand Down
15 changes: 15 additions & 0 deletions src/lp_data/HighsOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ const string kSolutionFileString = "solution_file";
const string kRangingString = "ranging";
const string kVersionString = "version";
const string kWriteModelFileString = "write_model_file";
const string kWritePresolvedModelFileString = "write_presolved_model_file";
const string kReadSolutionFileString = "read_solution_file";

// String for HiGHS log file option
Expand Down Expand Up @@ -320,9 +321,11 @@ struct HighsOptionsStruct {

std::string log_file;
bool write_model_to_file;
bool write_presolved_model_to_file;
bool write_solution_to_file;
HighsInt write_solution_style;
HighsInt glpsol_cost_row_location;
std::string write_presolved_model_file;

// Control of HiGHS log
bool output_flag;
Expand Down Expand Up @@ -434,6 +437,7 @@ struct HighsOptionsStruct {
time_limit(0.0),
solution_file(""),
write_model_file(""),
write_presolved_model_file(""),
random_seed(0),
ranging(""),
infinite_cost(0.0),
Expand Down Expand Up @@ -461,6 +465,7 @@ struct HighsOptionsStruct {
simplex_max_concurrency(0),
log_file(""),
write_model_to_file(false),
write_presolved_model_to_file(false),
write_solution_to_file(false),
write_solution_style(0),
glpsol_cost_row_location(0),
Expand Down Expand Up @@ -898,6 +903,16 @@ class HighsOptions : public HighsOptionsStruct {
advanced, &write_model_to_file, false);
records.push_back(record_bool);

record_string = new OptionRecordString(
kWritePresolvedModelFileString, "Write presolved model file", advanced,
&write_presolved_model_file, kHighsFilenameDefault);
records.push_back(record_string);

record_bool = new OptionRecordBool(
"write_presolved_model_to_file", "Write the presolved model to a file",
advanced, &write_presolved_model_to_file, false);
records.push_back(record_bool);

record_bool = new OptionRecordBool(
"mip_detect_symmetry", "Whether MIP symmetry should be detected",
advanced, &mip_detect_symmetry, true);
Expand Down

0 comments on commit 76a7e76

Please sign in to comment.