WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
exit_status.hpp
Go to the documentation of this file.
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#include <stdint.h>
6
7#include <fmt/base.h>
8
10
11namespace slp {
12
13/// Solver exit status. Negative values indicate failure.
14enum class ExitStatus : int8_t {
15 /// Solved the problem to the desired tolerance.
17 /// The solver returned its solution so far after the user requested a stop.
19 /// The solver determined the problem to be overconstrained and gave up.
21 /// The solver determined the problem to be locally infeasible and gave up.
23 /// The problem setup frontend determined the problem to have an empty
24 /// feasible region.
26 /// The linear system factorization failed.
28 /// The backtracking line search failed, and the problem isn't locally
29 /// infeasible.
31 /// The solver failed to reach the desired tolerance, and feasibility
32 /// restoration failed to converge.
34 /// The solver encountered nonfinite initial cost, constraints, or derivatives
35 /// and gave up.
37 /// The solver encountered diverging primal iterates xₖ and/or sₖ and gave up.
39 /// The solver returned its solution so far after exceeding the maximum number
40 /// of iterations.
42 /// The solver returned its solution so far after exceeding the maximum
43 /// elapsed wall clock time.
44 TIMEOUT = -10,
45};
46
47} // namespace slp
48
49// @cond Suppress Doxygen
50
51/// Formatter for ExitStatus.
52template <>
53struct fmt::formatter<slp::ExitStatus> {
54 /// Parses format string.
55 ///
56 /// @param ctx Format parse context.
57 /// @return Format parse context iterator.
58 constexpr auto parse(fmt::format_parse_context& ctx) {
59 return m_underlying.parse(ctx);
60 }
61
62 /// Formats ExitStatus.
63 ///
64 /// @tparam FmtContext Format context type.
65 /// @param exit_status Exit status.
66 /// @param ctx Format context.
67 /// @return Format context iterator.
68 template <typename FmtContext>
69 constexpr auto format(const slp::ExitStatus& exit_status,
70 FmtContext& ctx) const {
71 using enum slp::ExitStatus;
72
73 switch (exit_status) {
74 case SUCCESS:
75 return m_underlying.format("success", ctx);
77 return m_underlying.format("callback requested stop", ctx);
78 case TOO_FEW_DOFS:
79 return m_underlying.format("too few degrees of freedom", ctx);
81 return m_underlying.format("locally infeasible", ctx);
83 return m_underlying.format("globally infeasible", ctx);
85 return m_underlying.format("factorization failed", ctx);
87 return m_underlying.format("line search failed", ctx);
89 return m_underlying.format("feasibility restoration failed", ctx);
91 return m_underlying.format("nonfinite initial guess", ctx);
93 return m_underlying.format("diverging iterates", ctx);
95 return m_underlying.format("max iterations exceeded", ctx);
96 case TIMEOUT:
97 return m_underlying.format("timeout", ctx);
98 default:
100 }
101 }
102
103 private:
104 fmt::formatter<const char*> m_underlying;
105};
106
107// @endcond
FMT_INLINE auto format(locale_ref loc, format_string< T... > fmt, T &&... args) -> std::string
Definition format.h:4305
Definition to_underlying.hpp:7
ExitStatus
Solver exit status. Negative values indicate failure.
Definition exit_status.hpp:14
@ TIMEOUT
The solver returned its solution so far after exceeding the maximum elapsed wall clock time.
Definition exit_status.hpp:44
@ CALLBACK_REQUESTED_STOP
The solver returned its solution so far after the user requested a stop.
Definition exit_status.hpp:18
@ GLOBALLY_INFEASIBLE
The problem setup frontend determined the problem to have an empty feasible region.
Definition exit_status.hpp:25
@ DIVERGING_ITERATES
The solver encountered diverging primal iterates xₖ and/or sₖ and gave up.
Definition exit_status.hpp:38
@ FACTORIZATION_FAILED
The linear system factorization failed.
Definition exit_status.hpp:27
@ LINE_SEARCH_FAILED
The backtracking line search failed, and the problem isn't locally infeasible.
Definition exit_status.hpp:30
@ MAX_ITERATIONS_EXCEEDED
The solver returned its solution so far after exceeding the maximum number of iterations.
Definition exit_status.hpp:41
@ NONFINITE_INITIAL_GUESS
The solver encountered nonfinite initial cost, constraints, or derivatives and gave up.
Definition exit_status.hpp:36
@ SUCCESS
Solved the problem to the desired tolerance.
Definition exit_status.hpp:16
@ FEASIBILITY_RESTORATION_FAILED
The solver failed to reach the desired tolerance, and feasibility restoration failed to converge.
Definition exit_status.hpp:33
@ LOCALLY_INFEASIBLE
The solver determined the problem to be locally infeasible and gave up.
Definition exit_status.hpp:22
@ TOO_FEW_DOFS
The solver determined the problem to be overconstrained and gave up.
Definition exit_status.hpp:20
void unreachable()
Definition unreachable.hpp:8