alpaqa develop
Nonconvex constrained optimization
Loading...
Searching...
No Matches
pantr-driver.cpp
Go to the documentation of this file.
4
5#include "alm-driver.hpp"
6#include "cancel.hpp"
7#include "extra-stats.hpp"
8#include "pantr-driver.hpp"
9#include "solver-driver.hpp"
10
11namespace {
12
13template <class T>
14struct tag_t {};
15
16template <template <class Direction> class Solver>
18 [[maybe_unused]] Options &opts) {
20 auto builder = []<class Direction>(tag_t<Direction>) {
21 return [](std::string_view, Options &opts) -> SharedSolverWrapper {
22 using collector_t = AlpaqaSolverStatsCollector<config_t>;
23 std::shared_ptr<collector_t> collector;
24 auto inner_solver = make_inner_solver<Solver<Direction>>(opts);
25 bool extra_stats = false;
26 set_params(extra_stats, "extra_stats", opts);
27 if (extra_stats) {
28 collector = std::make_shared<collector_t>();
29 inner_solver.set_progress_callback(
30 [collector](const auto &progress_info) {
31 collector->update_iter(progress_info);
32 });
33 }
34 auto solver = make_alm_solver(std::move(inner_solver), opts);
35 unsigned N_exp = 0;
36 set_params(N_exp, "num_exp", opts);
37 auto run = [solver{std::move(solver)},
38 N_exp](LoadedProblem &problem,
39 std::ostream &os) mutable -> SolverResults {
40 auto cancel = alpaqa::attach_cancellation(solver);
41 return run_alm_solver(problem, solver, os, N_exp);
42 };
43 return std::make_shared<AlpaqaSolverWrapperStats<config_t>>(
44 std::move(run), std::move(collector));
45 };
46 };
47 std::map<std::string_view, solver_builder_func> builders{
48 {"newtontr", //
50 };
51 if (direction.empty())
52 direction = "newtontr";
53 auto builder_it = builders.find(direction);
54 if (builder_it != builders.end())
55 return builder_it->second(direction, opts);
56 else
57 throw std::invalid_argument(
58 "Unknown direction '" + std::string(direction) + "'\n" +
59 " Available directions: " +
60 alpaqa::util::join(std::views::keys(builders)));
61}
62
63} // namespace
64
65SharedSolverWrapper make_pantr_driver(std::string_view direction,
66 Options &opts) {
67 return make_pantr_like_solver<alpaqa::PANTRSolver>(direction, opts);
68}
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_pantr_like_solver(std::string_view direction, Options &opts)
void set_params(T &t, std::string_view prefix, Options &opts)
Definition options.hpp:126
SharedSolverWrapper make_pantr_driver(std::string_view direction, Options &opts)
std::shared_ptr< SolverWrapper > SharedSolverWrapper
Double-precision double configuration.
Definition config.hpp:176