Nonconvex constrained optimization
Loading...
Searching...
No Matches
pantr-driver.cpp
Go to the documentation of this file.
4#include <guanaqo/string-util.hpp>
5
9#include "extra-stats.hpp"
10#include "pantr-driver.hpp"
11
12namespace alpaqa::driver {
13namespace {
14
15template <class T>
16struct tag_t {};
17
18template <template <class Direction> class Solver>
20make_pantr_like_solver(std::string_view direction,
21 [[maybe_unused]] alpaqa::Options &opts) {
23 auto builder = []<class Direction>(tag_t<Direction>) {
24 return
25 [](std::string_view, alpaqa::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](alpaqa::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 {"newtontr", //
54 };
55 if (direction.empty())
56 direction = "newtontr";
57 auto builder_it = builders.find(direction);
58 if (builder_it != builders.end())
59 return builder_it->second(direction, opts);
60 else
61 throw std::invalid_argument("Unknown direction '" +
62 std::string(direction) + "'\n" +
63 " Available directions: " +
64 guanaqo::join(std::views::keys(builders)));
65}
66
67} // namespace
68
69SharedSolverWrapper make_pantr_driver(std::string_view direction,
70 alpaqa::Options &opts) {
71 return make_pantr_like_solver<alpaqa::PANTRSolver>(direction, opts);
72}
73
74} // namespace alpaqa::driver
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:77
SharedSolverWrapper make_pantr_like_solver(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_pantr_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