Skip to content

Commit

Permalink
Options: added separate functions to determine default solvers based …
Browse files Browse the repository at this point in the history
…on available libraries. If used, they will be printed in the option list
  • Loading branch information
cvanaret committed Oct 23, 2024
1 parent ae46646 commit df18261
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions bindings/AMPL/uno_ampl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
10 changes: 7 additions & 3 deletions uno/options/DefaultOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace uno {
Options DefaultOptions::load() {
Options options(true);

/** termination **/
// (tight) tolerance
options["tolerance"] = "1e-8";
Expand Down Expand Up @@ -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 **/
Expand Down
1 change: 1 addition & 0 deletions uno/options/DefaultOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace uno {
class DefaultOptions {
public:
[[nodiscard]] static Options load();
[[nodiscard]] static Options determine_solvers();
};
} // namespace

Expand Down

0 comments on commit df18261

Please sign in to comment.