Sleipnir C++ API
Loading...
Searching...
No Matches
exit_status.hpp
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#include <stdint.h>
6
7#include <format>
8#include <utility>
9
10namespace slp {
11
13enum class ExitStatus : int8_t {
15 SUCCESS = 0,
17 CALLBACK_REQUESTED_STOP = 1,
19 TOO_FEW_DOFS = -1,
21 LOCALLY_INFEASIBLE = -2,
24 GLOBALLY_INFEASIBLE = -3,
26 FACTORIZATION_FAILED = -4,
29 LINE_SEARCH_FAILED = -5,
32 NONFINITE_INITIAL_GUESS = -6,
34 DIVERGING_ITERATES = -7,
37 MAX_ITERATIONS_EXCEEDED = -8,
40 TIMEOUT = -9,
41};
42
43} // namespace slp
44
46template <>
47struct std::formatter<slp::ExitStatus> {
52 constexpr auto parse(std::format_parse_context& ctx) {
53 return m_underlying.parse(ctx);
54 }
55
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_GUESS:
82 return m_underlying.format(
83 "nonfinite initial cost, constraints, or derivatives", 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:
91 std::unreachable();
92 }
93 }
94
95 private:
96 std::formatter<const char*> m_underlying;
97};
auto format(const slp::ExitStatus &exit_status, FmtContext &ctx) const
Definition exit_status.hpp:63
constexpr auto parse(std::format_parse_context &ctx)
Definition exit_status.hpp:52