1818#include < cuopt/linear_programming/mip/solver_settings.hpp>
1919#include < cuopt/linear_programming/optimization_problem.hpp>
2020#include < cuopt/linear_programming/solve.hpp>
21- #include < cuopt/logger.hpp>
2221#include < mps_parser/parser.hpp>
22+ #include < utilities/logger.hpp>
2323
2424#include < raft/core/handle.hpp>
2525
@@ -75,6 +75,18 @@ static char cuda_module_loading_env[] = "CUDA_MODULE_LOADING=EAGER";
7575 */
7676inline auto make_async () { return std::make_shared<rmm::mr::cuda_async_memory_resource>(); }
7777
78+ /* *
79+ * @brief Handle logger when error happens before logger is initialized
80+ * @param settings Solver settings
81+ * @return cuopt::init_logger_t
82+ */
83+ inline cuopt::init_logger_t dummy_logger (
84+ const cuopt::linear_programming::solver_settings_t <int , double >& settings)
85+ {
86+ return cuopt::init_logger_t (settings.get_parameter <std::string>(CUOPT_LOG_FILE),
87+ settings.get_parameter <bool >(CUOPT_LOG_TO_CONSOLE));
88+ }
89+
7890/* *
7991 * @brief Run a single file
8092 * @param file_path Path to the MPS format input file containing the optimization problem
@@ -94,6 +106,7 @@ int run_single_file(const std::string& file_path,
94106 settings.set_parameter_from_string (key, val);
95107 }
96108 } catch (const std::exception& e) {
109+ auto log = dummy_logger (settings);
97110 CUOPT_LOG_ERROR (" Error: %s" , e.what ());
98111 return -1 ;
99112 }
@@ -113,6 +126,7 @@ int run_single_file(const std::string& file_path,
113126 }
114127 }
115128 if (parsing_failed) {
129+ auto log = dummy_logger (settings);
116130 CUOPT_LOG_ERROR (" Parsing MPS failed. Exiting!" );
117131 return -1 ;
118132 }
@@ -122,7 +136,8 @@ int run_single_file(const std::string& file_path,
122136
123137 const bool is_mip =
124138 (op_problem.get_problem_category () == cuopt::linear_programming::problem_category_t ::MIP ||
125- op_problem.get_problem_category () == cuopt::linear_programming::problem_category_t ::IP);
139+ op_problem.get_problem_category () == cuopt::linear_programming::problem_category_t ::IP) &&
140+ !solve_relaxation;
126141
127142 try {
128143 auto initial_solution =
@@ -131,23 +146,36 @@ int run_single_file(const std::string& file_path,
131146 : cuopt::linear_programming::solution_reader_t::get_variable_values_from_sol_file (
132147 initial_solution_file, mps_data_model.get_variable_names ());
133148
134- if (is_mip && !solve_relaxation ) {
149+ if (is_mip) {
135150 auto & mip_settings = settings.get_mip_settings ();
136151 if (initial_solution.size () > 0 ) {
137152 mip_settings.add_initial_solution (initial_solution.data (), initial_solution.size ());
138153 }
139- auto solution = cuopt::linear_programming::solve_mip (op_problem, mip_settings);
140154 } else {
141155 auto & lp_settings = settings.get_pdlp_settings ();
142156 if (initial_solution.size () > 0 ) {
143157 lp_settings.set_initial_primal_solution (initial_solution.data (), initial_solution.size ());
144158 }
145- auto solution = cuopt::linear_programming::solve_lp (op_problem, lp_settings);
159+ }
160+ } catch (const std::exception& e) {
161+ auto log = dummy_logger (settings);
162+ CUOPT_LOG_ERROR (" Error: %s" , e.what ());
163+ return -1 ;
164+ }
165+
166+ try {
167+ if (is_mip) {
168+ auto & mip_settings = settings.get_mip_settings ();
169+ auto solution = cuopt::linear_programming::solve_mip (op_problem, mip_settings);
170+ } else {
171+ auto & lp_settings = settings.get_pdlp_settings ();
172+ auto solution = cuopt::linear_programming::solve_lp (op_problem, lp_settings);
146173 }
147174 } catch (const std::exception& e) {
148175 CUOPT_LOG_ERROR (" Error: %s" , e.what ());
149176 return -1 ;
150177 }
178+
151179 return 0 ;
152180}
153181
0 commit comments