alpaqa pantr
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 static std::atomic<decltype(solver) *> solver_to_stop;
29 auto cancel = attach_cancellation<solver_to_stop>(solver);
30 return run_alm_solver(problem, solver, os, N_exp);
31 };
32 };
33 };
34 std::map<std::string_view, solver_builder_func_t> builders{
35 {"newtontr", //
36 builder(tag_t<alpaqa::NewtonTRDirection<config_t>>())},
37 };
38 if (direction.empty())
39 direction = "newtontr";
40 auto builder_it = builders.find(direction);
41 if (builder_it != builders.end())
42 return builder_it->second(direction, opts);
43 else
44 throw std::invalid_argument(
45 "Unknown direction '" + std::string(direction) + "'\n" +
46 " Available directions: " +
47 format_string_list(builders,
48 [](const auto &x) { return x.first; }));
49}
50
51} // namespace
52
53solver_func_t make_pantr_driver(std::string_view direction, Options &opts) {
54 return make_pantr_like_solver<alpaqa::PANTRSolver>(direction, opts);
55}
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:42
decltype(auto) set_params(T &t, std::string_view prefix, Options &opts)
Definition: options.hpp:29
solver_func_t make_pantr_driver(std::string_view direction, Options &opts)
std::function< solver_free_func_t > solver_func_t
std::string format_string_list(const auto &container, const auto &proj=[](const auto &x) -> decltype(auto) { return x;})
Definition: util.hpp:7