alpaqa 1.0.0a13
Nonconvex constrained optimization
Loading...
Searching...
No Matches
pantr-driver.cpp
Go to the documentation of this file.
3
4#include "alm-driver.hpp"
5#include "cancel.hpp"
6#include "extra-stats.hpp"
7#include "pantr-driver.hpp"
8#include "solver-driver.hpp"
9#include "util.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 format_string_list(builders,
61 [](const auto &x) { return x.first; }));
62}
63
64} // namespace
65
66SharedSolverWrapper make_pantr_driver(std::string_view direction,
67 Options &opts) {
68 return make_pantr_like_solver<alpaqa::PANTRSolver>(direction, opts);
69}
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
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)
decltype(auto) set_params(T &t, std::string_view prefix, Options &opts)
Definition options.hpp:27
SharedSolverWrapper make_pantr_driver(std::string_view direction, Options &opts)
std::shared_ptr< SolverWrapper > SharedSolverWrapper
Double-precision double configuration.
Definition config.hpp:135
std::string format_string_list(const auto &container, const auto &proj=[](const auto &x) -> decltype(auto) { return x;})
Definition util.hpp:7