alpaqa 1.0.0a11
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 "pantr-driver.hpp"
7#include "solver-driver.hpp"
8#include "util.hpp"
9
10namespace {
11
12template <class T>
13struct tag_t {};
14
15template <template <class Direction> class Solver>
16solver_func_t make_pantr_like_solver(std::string_view direction,
17 [[maybe_unused]] Options &opts) {
19 auto builder = []<class Direction>(tag_t<Direction>) {
20 return [](std::string_view, Options &opts) -> solver_func_t {
21 auto inner_solver = make_inner_solver<Solver<Direction>>(opts);
22 auto solver = make_alm_solver(std::move(inner_solver), opts);
23 unsigned N_exp = 0;
24 set_params(N_exp, "num_exp", opts);
25 return [solver{std::move(solver)},
26 N_exp](LoadedProblem &problem,
27 std::ostream &os) mutable -> SolverResults {
28 auto cancel = alpaqa::attach_cancellation(solver);
29 return run_alm_solver(problem, solver, os, N_exp);
30 };
31 };
32 };
33 std::map<std::string_view, solver_builder_func_t> builders{
34 {"newtontr", //
35 builder(tag_t<alpaqa::NewtonTRDirection<config_t>>())},
36 };
37 if (direction.empty())
38 direction = "newtontr";
39 auto builder_it = builders.find(direction);
40 if (builder_it != builders.end())
41 return builder_it->second(direction, opts);
42 else
43 throw std::invalid_argument(
44 "Unknown direction '" + std::string(direction) + "'\n" +
45 " Available directions: " +
46 format_string_list(builders,
47 [](const auto &x) { return x.first; }));
48}
49
50} // namespace
51
52solver_func_t make_pantr_driver(std::string_view direction, Options &opts) {
53 return make_pantr_like_solver<alpaqa::PANTRSolver>(direction, opts);
54}
SolverResults run_alm_solver(LoadedProblem &problem, Solver &solver, std::ostream &os, unsigned N_exp)
Definition: alm-driver.hpp:56
auto make_alm_solver(InnerSolver &&inner_solver, Options &opts)
Definition: alm-driver.hpp:12
#define USING_ALPAQA_CONFIG(Conf)
Definition: config.hpp:54
std::decay_t< decltype(Tag)> tag_t
Definition: tag-invoke.hpp:74
auto attach_cancellation(Solver &solver)
Attach SIGINT and SIGTERM handlers to stop the given solver.
Definition: cancel.hpp:21
decltype(auto) set_params(T &t, std::string_view prefix, Options &opts)
Definition: options.hpp:27
solver_func_t make_pantr_driver(std::string_view direction, Options &opts)
std::function< solver_free_func_t > solver_func_t
Double-precision double configuration.
Definition: config.hpp:127
std::string format_string_list(const auto &container, const auto &proj=[](const auto &x) -> decltype(auto) { return x;})
Definition: util.hpp:7