alpaqa 1.0.0a17
Nonconvex constrained optimization
Loading...
Searching...
No Matches
panoc-driver.cpp
Go to the documentation of this file.
8
9#include "alm-driver.hpp"
10#include "cancel.hpp"
11#include "extra-stats.hpp"
12#include "panoc-driver.hpp"
13#include "solver-driver.hpp"
14
15namespace {
16
17template <class T>
18struct tag_t {};
19
20template <template <class Direction> class Solver>
22 Options &opts) {
24 auto builder = []<class Direction>(tag_t<Direction>) {
25 return [](std::string_view, Options &opts) -> SharedSolverWrapper {
26 using collector_t = AlpaqaSolverStatsCollector<config_t>;
27 std::shared_ptr<collector_t> collector;
28 auto inner_solver = make_inner_solver<Solver<Direction>>(opts);
29 bool extra_stats = false;
30 set_params(extra_stats, "extra_stats", opts);
31 if (extra_stats) {
32 collector = std::make_shared<collector_t>();
33 inner_solver.set_progress_callback(
34 [collector](const auto &progress_info) {
35 collector->update_iter(progress_info);
36 });
37 }
38 auto solver = make_alm_solver(std::move(inner_solver), opts);
39 unsigned N_exp = 0;
40 set_params(N_exp, "num_exp", opts);
41 auto run = [solver{std::move(solver)},
42 N_exp](LoadedProblem &problem,
43 std::ostream &os) mutable -> SolverResults {
44 auto cancel = alpaqa::attach_cancellation(solver);
45 return run_alm_solver(problem, solver, os, N_exp);
46 };
47 return std::make_shared<AlpaqaSolverWrapperStats<config_t>>(
48 std::move(run), std::move(collector));
49 };
50 };
51 std::map<std::string_view, solver_builder_func> builders{
52 {"lbfgs", //
54 {"anderson", //
56 {"struclbfgs", //
58 {"convex-newton", //
60 };
61 if (direction.empty())
62 direction = "lbfgs";
63 auto builder_it = builders.find(direction);
64 if (builder_it != builders.end())
65 return builder_it->second(direction, opts);
66 else
67 throw std::invalid_argument(
68 "Unknown direction '" + std::string(direction) + "'\n" +
69 " Available directions: " +
70 alpaqa::util::join(std::views::keys(builders)));
71}
72
73} // namespace
74
75SharedSolverWrapper make_panoc_driver(std::string_view direction,
76 Options &opts) {
77 return make_panoc_like_driver<alpaqa::PANOCSolver>(direction, opts);
78}
79
80SharedSolverWrapper make_zerofpr_driver(std::string_view direction,
81 Options &opts) {
82 return make_panoc_like_driver<alpaqa::ZeroFPRSolver>(direction, opts);
83}
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:77
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)
void set_params(T &t, std::string_view prefix, Options &opts)
Definition options.hpp:128
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:174