alpaqa sparse
Nonconvex constrained optimization
Loading...
Searching...
No Matches
panoc-driver.cpp
Go to the documentation of this file.
6
7#include "alm-driver.hpp"
8#include "cancel.hpp"
9#include "panoc-driver.hpp"
10#include "solver-driver.hpp"
11#include "util.hpp"
12
13namespace {
14
15template <class T>
16struct tag_t {};
17
18template <template <class Direction> class Solver>
19solver_func_t make_panoc_like_driver(std::string_view direction,
20 [[maybe_unused]] Options &opts) {
22 auto builder = []<class Direction>(tag_t<Direction>) {
23 return [](std::string_view, Options &opts) -> solver_func_t {
24 auto inner_solver = make_inner_solver<Solver<Direction>>(opts);
25 auto solver = make_alm_solver(std::move(inner_solver), opts);
26 unsigned N_exp = 0;
27 set_params(N_exp, "num_exp", opts);
28 return [solver{std::move(solver)},
29 N_exp](LoadedProblem &problem,
30 std::ostream &os) mutable -> SolverResults {
31 auto cancel = alpaqa::attach_cancellation(solver);
32 return run_alm_solver(problem, solver, os, N_exp);
33 };
34 };
35 };
36 std::map<std::string_view, solver_builder_func_t> builders{
37 {"lbfgs", //
39 {"anderson", //
41 {"struclbfgs", //
43 };
44 if (direction.empty())
45 direction = "lbfgs";
46 auto builder_it = builders.find(direction);
47 if (builder_it != builders.end())
48 return builder_it->second(direction, opts);
49 else
50 throw std::invalid_argument(
51 "Unknown direction '" + std::string(direction) + "'\n" +
52 " Available directions: " +
53 format_string_list(builders,
54 [](const auto &x) { return x.first; }));
55}
56
57} // namespace
58
59solver_func_t make_panoc_driver(std::string_view direction, Options &opts) {
60 return make_panoc_like_driver<alpaqa::PANOCSolver>(direction, opts);
61}
62
63solver_func_t make_zerofpr_driver(std::string_view direction, Options &opts) {
64 return make_panoc_like_driver<alpaqa::ZeroFPRSolver>(direction, opts);
65}
SolverResults run_alm_solver(LoadedProblem &problem, Solver &solver, std::ostream &os, unsigned N_exp)
auto make_alm_solver(InnerSolver &&inner_solver, Options &opts)
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:56
auto attach_cancellation(Solver &solver)
Attach SIGINT and SIGTERM handlers to stop the given solver.
Definition cancel.hpp:21
solver_func_t make_panoc_like_driver(std::string_view direction, Options &opts)
decltype(auto) set_params(T &t, std::string_view prefix, Options &opts)
Definition options.hpp:27
solver_func_t make_panoc_driver(std::string_view direction, Options &opts)
solver_func_t make_zerofpr_driver(std::string_view direction, Options &opts)
std::function< solver_free_func_t > solver_func_t
Double-precision double configuration.
Definition config.hpp:135
std::string format_string_list(const auto &container, const auto &proj=[](const auto &x) -> decltype(auto) { return x;})
Definition util.hpp:7