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