Skip to content

Commit f80d6cf

Browse files
authored
Dump presolved problem to file (#459)
This PR adds a new option to write the presolved model if presolved is applied. Authors: - Hugo Linsenmaier (https://github.com/hlinsen) Approvers: - Chris Maes (https://github.com/chris-maes) URL: #459
1 parent 7dc755e commit f80d6cf

6 files changed

Lines changed: 15 additions & 1 deletion

File tree

cpp/include/cuopt/linear_programming/constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#define CUOPT_NUM_CPU_THREADS "num_cpu_threads"
7575
#define CUOPT_NUM_GPUS "num_gpus"
7676
#define CUOPT_USER_PROBLEM_FILE "user_problem_file"
77+
#define CUOPT_PRESOLVE_FILE "presolve_file"
7778
#define CUOPT_RANDOM_SEED "random_seed"
7879
#define CUOPT_PDLP_PRECISION "pdlp_precision"
7980

cpp/include/cuopt/linear_programming/mip/solver_settings.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class mip_solver_settings_t {
105105
std::string log_file;
106106
std::string sol_file;
107107
std::string user_problem_file;
108+
std::string presolve_file;
108109

109110
/** Initial primal solutions */
110111
std::vector<std::shared_ptr<rmm::device_uvector<f_t>>> initial_solutions;

cpp/include/cuopt/linear_programming/pdlp/solver_settings.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ class pdlp_solver_settings_t {
245245
std::string log_file{""};
246246
std::string sol_file{""};
247247
std::string user_problem_file{""};
248+
std::string presolve_file{""};
248249
bool per_constraint_residual{false};
249250
bool crossover{false};
250251
bool cudss_deterministic{false};

cpp/src/math_optimization/solver_settings.cu

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ solver_settings_t<i_t, f_t>::solver_settings_t() : pdlp_settings(), mip_settings
131131
{CUOPT_SOLUTION_FILE, &mip_settings.sol_file, ""},
132132
{CUOPT_SOLUTION_FILE, &pdlp_settings.sol_file, ""},
133133
{CUOPT_USER_PROBLEM_FILE, &mip_settings.user_problem_file, ""},
134-
{CUOPT_USER_PROBLEM_FILE, &pdlp_settings.user_problem_file, ""}
134+
{CUOPT_USER_PROBLEM_FILE, &pdlp_settings.user_problem_file, ""},
135+
{CUOPT_PRESOLVE_FILE, &mip_settings.presolve_file, ""},
136+
{CUOPT_PRESOLVE_FILE, &pdlp_settings.presolve_file, ""}
135137
};
136138
// clang-format on
137139
}

cpp/src/mip_heuristics/solve.cu

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ mip_solution_t<i_t, f_t> solve_mip(optimization_problem_t<i_t, f_t>& op_problem,
283283
settings.tolerances.relative_tolerance,
284284
presolve_time_limit,
285285
settings.num_cpu_threads);
286+
286287
if (!result.has_value()) {
287288
return mip_solution_t<i_t, f_t>(mip_termination_status_t::Infeasible,
288289
solver_stats_t<i_t, f_t>{},
@@ -306,6 +307,10 @@ mip_solution_t<i_t, f_t> solve_mip(optimization_problem_t<i_t, f_t>& op_problem,
306307
CUOPT_LOG_INFO("Writing user problem to file: %s", settings.user_problem_file.c_str());
307308
op_problem.write_to_mps(settings.user_problem_file);
308309
}
310+
if (run_presolve && settings.presolve_file != "") {
311+
CUOPT_LOG_INFO("Writing presolved problem to file: %s", settings.presolve_file.c_str());
312+
presolve_result->reduced_problem.write_to_mps(settings.presolve_file);
313+
}
309314

310315
auto sol = run_mip(problem, settings, timer);
311316

cpp/src/pdlp/solve.cu

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,10 @@ optimization_problem_solution_t<i_t, f_t> solve_lp(
14531453
CUOPT_LOG_INFO("Writing user problem to file: %s", settings.user_problem_file.c_str());
14541454
op_problem.write_to_mps(settings.user_problem_file);
14551455
}
1456+
if (run_presolve && settings.presolve_file != "") {
1457+
CUOPT_LOG_INFO("Writing presolved problem to file: %s", settings.presolve_file.c_str());
1458+
result->reduced_problem.write_to_mps(settings.presolve_file);
1459+
}
14561460

14571461
// Set the hyper-parameters based on the solver_settings
14581462
if (use_pdlp_solver_mode) { set_pdlp_solver_mode(settings); }

0 commit comments

Comments
 (0)