WPILibC++ 2027.0.0-alpha-4
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 encountered nonfinite initial cost or constraints and gave up.
33 /// The solver encountered diverging primal iterates xₖ and/or sₖ and gave up.
35 /// The solver returned its solution so far after exceeding the maximum number
36 /// of iterations.
38 /// The solver returned its solution so far after exceeding the maximum
39 /// elapsed wall clock time.
40 TIMEOUT = -9,
41};
42
43} // namespace slp
44
45/// Formatter for ExitStatus.
46template <>
47struct fmt::formatter<slp::ExitStatus> {
48 /// Parse format string.
49 ///
50 /// @param ctx Format parse context.
51 /// @return Format parse context iterator.
52 constexpr auto parse(fmt::format_parse_context& ctx) {
53 return m_underlying.parse(ctx);
54 }
55
56 /// Format ExitStatus.
57 ///
58 /// @tparam FmtContext Format context type.
59 /// @param exit_status Exit status.
60 /// @param ctx Format context.
61 /// @return Format context iterator.
62 template <typename FmtContext>
63 auto format(const slp::ExitStatus& exit_status, FmtContext& ctx) const {
64 using enum slp::ExitStatus;
65
66 switch (exit_status) {
67 case SUCCESS:
68 return m_underlying.format("success", ctx);
69 case CALLBACK_REQUESTED_STOP:
70 return m_underlying.format("callback requested stop", ctx);
71 case TOO_FEW_DOFS:
72 return m_underlying.format("too few degrees of freedom", ctx);
73 case LOCALLY_INFEASIBLE:
74 return m_underlying.format("locally infeasible", ctx);
75 case GLOBALLY_INFEASIBLE:
76 return m_underlying.format("globally infeasible", ctx);
77 case FACTORIZATION_FAILED:
78 return m_underlying.format("factorization failed", ctx);
79 case LINE_SEARCH_FAILED:
80 return m_underlying.format("line search failed", ctx);
81 case NONFINITE_INITIAL_COST_OR_CONSTRAINTS:
82 return m_underlying.format("nonfinite initial cost or constraints",
83 ctx);
84 case DIVERGING_ITERATES:
85 return m_underlying.format("diverging iterates", ctx);
86 case MAX_ITERATIONS_EXCEEDED:
87 return m_underlying.format("max iterations exceeded", ctx);
88 case TIMEOUT:
89 return m_underlying.format("timeout", ctx);
90 default:
92 }
93 }
94
95 private:
96 fmt::formatter<const char*> m_underlying;
97};
Definition expression_graph.hpp:11
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:40
@ 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:34
@ 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:37
@ SUCCESS
Solved the problem to the desired tolerance.
Definition exit_status.hpp:16
@ 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
@ NONFINITE_INITIAL_COST_OR_CONSTRAINTS
The solver encountered nonfinite initial cost or constraints and gave up.
Definition exit_status.hpp:32
void unreachable()
Definition unreachable.hpp:8
auto format(const slp::ExitStatus &exit_status, FmtContext &ctx) const
Format ExitStatus.
Definition exit_status.hpp:63
constexpr auto parse(fmt::format_parse_context &ctx)
Parse format string.
Definition exit_status.hpp:52