alpaqa 1.0.0a8
Nonconvex constrained optimization
Loading...
Searching...
No Matches
panoc-driver.cpp
Go to the documentation of this file.
6
7#include "alm-driver.hpp"
8#include "cancel.hpp"
9#include "panoc-driver.hpp"
10#include "solver-driver.hpp"
11#include "util.hpp"
12
13namespace {
14
15template <class T>
16struct tag_t {};
17
18template <template <class Direction> class Solver>
19solver_func_t make_panoc_like_driver(std::string_view direction,
20 [[maybe_unused]] Options &opts) {
22 auto builder = []<class Direction>(tag_t<Direction>) {
23 return [](std::string_view, Options &opts) -> solver_func_t {
24 auto inner_solver = make_inner_solver<Solver<Direction>>(opts);
25 auto solver = make_alm_solver(std::move(inner_solver), opts);
26 unsigned N_exp = 0;
27 set_params(N_exp, "num_exp", opts);
28 return [solver{std::move(solver)},
29 N_exp](LoadedProblem &problem,
30 std::ostream &os) mutable -> SolverResults {
31 static std::atomic<decltype(solver) *> solver_to_stop;
32 auto cancel = attach_cancellation<solver_to_stop>(solver);
33 return run_alm_solver(problem, solver, os, N_exp);
34 };
35 };
36 };
37 std::map<std::string_view, solver_builder_func_t> builders{
38 {"lbfgs", //
39 builder(tag_t<alpaqa::LBFGSDirection<config_t>>())},
40 {"anderson", //
41 builder(tag_t<alpaqa::AndersonDirection<config_t>>())},
42 {"struclbfgs", //
44 };
45 if (direction.empty())
46 direction = "lbfgs";
47 auto builder_it = builders.find(direction);
48 if (builder_it != builders.end())
49 return builder_it->second(direction, opts);
50 else
51 throw std::invalid_argument(
52 "Unknown direction '" + std::string(direction) + "'\n" +
53 " Available directions: " +
54 format_string_list(builders,
55 [](const auto &x) { return x.first; }));
56}
57
58} // namespace
59
60solver_func_t make_panoc_driver(std::string_view direction, Options &opts) {
61 return make_panoc_like_driver<alpaqa::PANOCSolver>(direction, opts);
62}
63
64solver_func_t make_zerofpr_driver(std::string_view direction, Options &opts) {
65 return make_panoc_like_driver<alpaqa::ZeroFPRSolver>(direction, opts);
66}
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_panoc_driver(std::string_view direction, Options &opts)
solver_func_t make_zerofpr_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