WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
SolverExitCondition.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 <string_view>
8
10
11namespace sleipnir {
12
13/**
14 * Solver exit condition.
15 */
16enum class SolverExitCondition : int8_t {
17 /// Solved the problem to the desired tolerance.
18 kSuccess = 0,
19 /// Solved the problem to an acceptable tolerance, but not the desired one.
21 /// The solver returned its solution so far after the user requested a stop.
23 /// The solver determined the problem to be overconstrained and gave up.
24 kTooFewDOFs = -1,
25 /// The solver determined the problem to be locally infeasible and gave up.
27 /// The solver failed to reach the desired tolerance, and feasibility
28 /// restoration failed to converge.
30 /// The solver encountered nonfinite initial cost or constraints and gave up.
32 /// The solver encountered diverging primal iterates xₖ and/or sₖ and gave up.
34 /// The solver returned its solution so far after exceeding the maximum number
35 /// of iterations.
37 /// The solver returned its solution so far after exceeding the maximum
38 /// elapsed wall clock time.
39 kTimeout = -7
40};
41
42/**
43 * Returns user-readable message corresponding to the exit condition.
44 *
45 * @param exitCondition Solver exit condition.
46 */
47SLEIPNIR_DLLEXPORT constexpr std::string_view ToMessage(
48 const SolverExitCondition& exitCondition) {
49 using enum SolverExitCondition;
50
51 switch (exitCondition) {
52 case kSuccess:
53 return "solved to desired tolerance";
55 return "solved to acceptable tolerance";
57 return "callback requested stop";
58 case kTooFewDOFs:
59 return "problem has too few degrees of freedom";
61 return "problem is locally infeasible";
63 return "solver failed to reach the desired tolerance, and feasibility "
64 "restoration failed to converge";
66 return "solver encountered nonfinite initial cost or constraints and "
67 "gave up";
69 return "solver encountered diverging primal iterates xₖ and/or sₖ and "
70 "gave up";
72 return "solution returned after maximum iterations exceeded";
73 case kTimeout:
74 return "solution returned after maximum wall clock time exceeded";
75 default:
76 return "unknown";
77 }
78}
79
80} // namespace sleipnir
#define SLEIPNIR_DLLEXPORT
Definition SymbolExports.hpp:34
Definition Hessian.hpp:18
SLEIPNIR_DLLEXPORT constexpr std::string_view ToMessage(const SolverExitCondition &exitCondition)
Returns user-readable message corresponding to the exit condition.
Definition SolverExitCondition.hpp:47
SolverExitCondition
Solver exit condition.
Definition SolverExitCondition.hpp:16
@ kNonfiniteInitialCostOrConstraints
The solver encountered nonfinite initial cost or constraints and gave up.
@ kFeasibilityRestorationFailed
The solver failed to reach the desired tolerance, and feasibility restoration failed to converge.
@ kLocallyInfeasible
The solver determined the problem to be locally infeasible and gave up.
@ kTimeout
The solver returned its solution so far after exceeding the maximum elapsed wall clock time.
@ kSuccess
Solved the problem to the desired tolerance.
@ kSolvedToAcceptableTolerance
Solved the problem to an acceptable tolerance, but not the desired one.
@ kTooFewDOFs
The solver determined the problem to be overconstrained and gave up.
@ kMaxIterationsExceeded
The solver returned its solution so far after exceeding the maximum number of iterations.
@ kDivergingIterates
The solver encountered diverging primal iterates xₖ and/or sₖ and gave up.
@ kCallbackRequestedStop
The solver returned its solution so far after the user requested a stop.