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 <string_view>
8
9#include "sleipnir/util/symbol_exports.hpp"
10
11namespace slp {
12
16enum class ExitStatus : int8_t {
18 SUCCESS = 0,
20 SOLVED_TO_ACCEPTABLE_TOLERANCE = 1,
22 CALLBACK_REQUESTED_STOP = 2,
24 TOO_FEW_DOFS = -1,
26 LOCALLY_INFEASIBLE = -2,
28 FACTORIZATION_FAILED = -3,
31 LINE_SEARCH_FAILED = -4,
33 NONFINITE_INITIAL_COST_OR_CONSTRAINTS = -5,
35 DIVERGING_ITERATES = -6,
38 MAX_ITERATIONS_EXCEEDED = -7,
41 TIMEOUT = -8
42};
43
49SLEIPNIR_DLLEXPORT constexpr std::string_view ToMessage(
50 const ExitStatus& exit_status) {
51 using enum ExitStatus;
52
53 switch (exit_status) {
54 case SUCCESS:
55 return "solved to desired tolerance";
56 case SOLVED_TO_ACCEPTABLE_TOLERANCE:
57 return "solved to acceptable tolerance";
58 case CALLBACK_REQUESTED_STOP:
59 return "callback requested stop";
60 case TOO_FEW_DOFS:
61 return "problem has too few degrees of freedom";
62 case LOCALLY_INFEASIBLE:
63 return "problem is locally infeasible";
64 case FACTORIZATION_FAILED:
65 return "linear system factorization failed";
66 case LINE_SEARCH_FAILED:
67 return "backtracking line search failed, and the problem isn't locally "
68 "infeasible";
69 case NONFINITE_INITIAL_COST_OR_CONSTRAINTS:
70 return "solver encountered nonfinite initial cost or constraints and "
71 "gave up";
72 case DIVERGING_ITERATES:
73 return "solver encountered diverging primal iterates xₖ and/or sₖ and "
74 "gave up";
75 case MAX_ITERATIONS_EXCEEDED:
76 return "solution returned after maximum iterations exceeded";
77 case TIMEOUT:
78 return "solution returned after maximum wall clock time exceeded";
79 default:
80 return "unknown";
81 }
82}
83
84} // namespace slp