From df18261f32991cd74a2d6f49b975145591ce38d3 Mon Sep 17 00:00:00 2001 From: Charlie Vanaret Date: Thu, 24 Oct 2024 00:01:59 +0200 Subject: [PATCH] Options: added separate functions to determine default solvers based on available libraries. If used, they will be printed in the option list --- bindings/AMPL/uno_ampl.cpp | 8 ++++++-- uno/options/DefaultOptions.cpp | 10 +++++++--- uno/options/DefaultOptions.hpp | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bindings/AMPL/uno_ampl.cpp b/bindings/AMPL/uno_ampl.cpp index cf5e203e..2d54e19f 100644 --- a/bindings/AMPL/uno_ampl.cpp +++ b/bindings/AMPL/uno_ampl.cpp @@ -100,9 +100,13 @@ int main(int argc, char* argv[]) { throw std::runtime_error("The second command line argument should be -AMPL"); } + // determine the default solvers based on the available libraries + Options solvers_options = DefaultOptions::determine_solvers(); + options.overwrite_with(solvers_options); + // overwrite the default options with the command line arguments - Options overwriting_options = Options::get_command_line_options(argc, argv); - options.overwrite_with(overwriting_options); + Options command_line_options = Options::get_command_line_options(argc, argv); + options.overwrite_with(command_line_options); // solve the model Logger::set_logger(options.get_string("logger")); diff --git a/uno/options/DefaultOptions.cpp b/uno/options/DefaultOptions.cpp index 7d5d1e19..a8068a0a 100644 --- a/uno/options/DefaultOptions.cpp +++ b/uno/options/DefaultOptions.cpp @@ -9,6 +9,7 @@ namespace uno { Options DefaultOptions::load() { Options options(true); + /** termination **/ // (tight) tolerance options["tolerance"] = "1e-8"; @@ -185,24 +186,27 @@ namespace uno { /** AMPL options **/ options["AMPL_write_solution_to_file"] = "yes"; + return options; + } + + Options DefaultOptions::determine_solvers() { + Options options(false); + /** solvers: check the available solvers **/ // QP solver const auto QP_solvers = QPSolverFactory::available_solvers(); if (not QP_solvers.empty()) { options["QP_solver"] = QP_solvers[0]; - //options.is_default["QP_solver"] = false; } // LP solver const auto LP_solvers = LPSolverFactory::available_solvers(); if (not LP_solvers.empty()) { options["LP_solver"] = LP_solvers[0]; - //options.is_default["LP_solver"] = false; } // linear solver const auto linear_solvers = SymmetricIndefiniteLinearSolverFactory::available_solvers(); if (not linear_solvers.empty()) { options["linear_solver"] = linear_solvers[0]; - //options.is_default["linear_solver"] = false; } /** ingredients **/ diff --git a/uno/options/DefaultOptions.hpp b/uno/options/DefaultOptions.hpp index c88fa6a7..f1d47ebc 100644 --- a/uno/options/DefaultOptions.hpp +++ b/uno/options/DefaultOptions.hpp @@ -10,6 +10,7 @@ namespace uno { class DefaultOptions { public: [[nodiscard]] static Options load(); + [[nodiscard]] static Options determine_solvers(); }; } // namespace