alpaqa 1.0.0a15
Nonconvex constrained optimization
Loading...
Searching...
No Matches
panoc-driver.cpp
Go to the documentation of this file.
7
8#include "alm-driver.hpp"
9#include "cancel.hpp"
10#include "extra-stats.hpp"
11#include "panoc-driver.hpp"
12#include "solver-driver.hpp"
13
14namespace {
15
16template <class T>
17struct tag_t {};
18
19template <template <class Direction> class Solver>
21 Options &opts) {
23 auto builder = []<class Direction>(tag_t<Direction>) {
24 return [](std::string_view, Options &opts) -> SharedSolverWrapper {
25 using collector_t = AlpaqaSolverStatsCollector<config_t>;
26 std::shared_ptr<collector_t> collector;
27 auto inner_solver = make_inner_solver<Solver<Direction>>(opts);
28 bool extra_stats = false;
29 set_params(extra_stats, "extra_stats", opts);
30 if (extra_stats) {
31 collector = std::make_shared<collector_t>();
32 inner_solver.set_progress_callback(
33 [collector](const auto &progress_info) {
34 collector->update_iter(progress_info);
35 });
36 }
37 auto solver = make_alm_solver(std::move(inner_solver), opts);
38 unsigned N_exp = 0;
39 set_params(N_exp, "num_exp", opts);
40 auto run = [solver{std::move(solver)},
41 N_exp](LoadedProblem &problem,
42 std::ostream &os) mutable -> SolverResults {
43 auto cancel = alpaqa::attach_cancellation(solver);
44 return run_alm_solver(problem, solver, os, N_exp);
45 };
46 return std::make_shared<AlpaqaSolverWrapperStats<config_t>>(
47 std::move(run), std::move(collector));
48 };
49 };
50 std::map<std::string_view, solver_builder_func> builders{
51 {"lbfgs", //
53 {"anderson", //
55 {"struclbfgs", //
57 };
58 if (direction.empty())
59 direction = "lbfgs";
60 auto builder_it = builders.find(direction);
61 if (builder_it != builders.end())
62 return builder_it->second(direction, opts);
63 else
64 throw std::invalid_argument(
65 "Unknown direction '" + std::string(direction) + "'\n" +
66 " Available directions: " +
67 alpaqa::util::join(std::views::keys(builders)));
68}
69
70} // namespace
71
72SharedSolverWrapper make_panoc_driver(std::string_view direction,
73 Options &opts) {
74 return make_panoc_like_driver<alpaqa::PANOCSolver>(direction, opts);
75}
76
77SharedSolverWrapper make_zerofpr_driver(std::string_view direction,
78 Options &opts) {
79 return make_panoc_like_driver<alpaqa::ZeroFPRSolver>(direction, opts);
80}
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
std::string join(std::ranges::input_range auto strings, join_opt opt={})
Join the list of strings into a single string, using the separator given by opt.
auto attach_cancellation(Solver &solver)
Attach SIGINT and SIGTERM handlers to stop the given solver.
Definition cancel.hpp:21
SharedSolverWrapper 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:86
SharedSolverWrapper make_zerofpr_driver(std::string_view direction, Options &opts)
SharedSolverWrapper make_panoc_driver(std::string_view direction, Options &opts)
std::shared_ptr< SolverWrapper > SharedSolverWrapper
Double-precision double configuration.
Definition config.hpp:135