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,
31 NONFINITE_INITIAL_COST_OR_CONSTRAINTS = -6,
33 DIVERGING_ITERATES = -7,
36 MAX_ITERATIONS_EXCEEDED = -8,
39 TIMEOUT = -9,
40};
41
42} // namespace slp
43
45template <>
46struct std::formatter<slp::ExitStatus> {
51 constexpr auto parse(std::format_parse_context& ctx) {
52 return m_underlying.parse(ctx);
53 }
54
61 template <typename FmtContext>
62 auto format(const slp::ExitStatus& exit_status, FmtContext& ctx) const {
63 using enum slp::ExitStatus;
64
65 switch (exit_status) {
66 case SUCCESS:
67 return m_underlying.format("success", ctx);
68 case CALLBACK_REQUESTED_STOP:
69 return m_underlying.format("callback requested stop", ctx);
70 case TOO_FEW_DOFS:
71 return m_underlying.format("too few degrees of freedom", ctx);
72 case LOCALLY_INFEASIBLE:
73 return m_underlying.format("locally infeasible", ctx);
74 case GLOBALLY_INFEASIBLE:
75 return m_underlying.format("globally infeasible", ctx);
76 case FACTORIZATION_FAILED:
77 return m_underlying.format("factorization failed", ctx);
78 case LINE_SEARCH_FAILED:
79 return m_underlying.format("line search failed", ctx);
80 case NONFINITE_INITIAL_COST_OR_CONSTRAINTS:
81 return m_underlying.format("nonfinite initial cost or constraints",
82 ctx);
83 case DIVERGING_ITERATES:
84 return m_underlying.format("diverging iterates", ctx);
85 case MAX_ITERATIONS_EXCEEDED:
86 return m_underlying.format("max iterations exceeded", ctx);
87 case TIMEOUT:
88 return m_underlying.format("timeout", ctx);
89 default:
90 std::unreachable();
91 }
92 }
93
94 private:
95 std::formatter<const char*> m_underlying;
96};
auto format(const slp::ExitStatus &exit_status, FmtContext &ctx) const
Definition exit_status.hpp:62
constexpr auto parse(std::format_parse_context &ctx)
Definition exit_status.hpp:51