WPILibC++ 2025.1.1
|
Namespaces | |
namespace | detail |
namespace | slicing |
Classes | |
struct | EqualityConstraints |
A vector of equality constraints of the form cₑ(x) = 0. More... | |
class | function_ref |
An implementation of std::function_ref, a lightweight non-owning reference to a callable. More... | |
class | function_ref< R(Args...)> |
class | Gradient |
This class calculates the gradient of a a variable with respect to a vector of variables. More... | |
class | Hessian |
This class calculates the Hessian of a variable with respect to a vector of variables. More... | |
struct | InequalityConstraints |
A vector of inequality constraints of the form cᵢ(x) ≥ 0. More... | |
class | IntrusiveSharedPtr |
A custom intrusive shared pointer implementation without thread synchronization overhead. More... | |
class | Jacobian |
This class calculates the Jacobian of a vector of variables with respect to a vector of variables. More... | |
struct | MultistartResult |
The result of a multistart solve. More... | |
class | OCPSolver |
This class allows the user to pose and solve a constrained optimal control problem (OCP) in a variety of ways. More... | |
class | OptimizationProblem |
This class allows the user to pose a constrained nonlinear optimization problem in natural mathematical notation and solve it. More... | |
class | PoolAllocator |
This class is an allocator for the pool resource. More... | |
class | PoolResource |
This class implements a pool memory resource. More... | |
class | Profiler |
Records the number of profiler measurements (start/stop pairs) and the average duration between each start and stop call. More... | |
class | Slice |
struct | SolverConfig |
Solver configuration. More... | |
struct | SolverIterationInfo |
Solver iteration information exposed to a user callback. More... | |
struct | SolverStatus |
Return value of OptimizationProblem::Solve() containing the cost function and constraint types and solver's exit condition. More... | |
class | Variable |
An autodiff variable pointing to an expression node. More... | |
class | VariableBlock |
A submatrix of autodiff variables with reference semantics. More... | |
class | VariableMatrix |
A matrix of autodiff variables. More... | |
Concepts | |
concept | ScalarLike |
concept | SleipnirMatrixLike |
concept | EigenMatrixLike |
concept | MatrixLike |
concept | EigenSolver |
Enumerations | |
enum class | TranscriptionMethod : uint8_t { kDirectTranscription , kDirectCollocation , kSingleShooting } |
Enum describing an OCP transcription method. More... | |
enum class | DynamicsType : uint8_t { kExplicitODE , kDiscrete } |
Enum describing a type of system dynamics constraints. More... | |
enum class | TimestepMethod : uint8_t { kFixed , kVariable , kVariableSingle } |
Enum describing the type of system timestep. More... | |
enum class | ExpressionType : uint8_t { kNone , kConstant , kLinear , kQuadratic , kNonlinear } |
Expression type. More... | |
enum class | SolverExitCondition : int8_t { kSuccess = 0 , kSolvedToAcceptableTolerance = 1 , kCallbackRequestedStop = 2 , kTooFewDOFs = -1 , kLocallyInfeasible = -2 , kFeasibilityRestorationFailed = -3 , kNonfiniteInitialCostOrConstraints = -4 , kDivergingIterates = -5 , kMaxIterationsExceeded = -6 , kTimeout = -7 } |
Solver exit condition. More... | |
Functions | |
SLEIPNIR_DLLEXPORT VariableMatrix | CwiseReduce (const VariableMatrix &lhs, const VariableMatrix &rhs, function_ref< Variable(const Variable &x, const Variable &y)> binaryOp) |
Applies a coefficient-wise reduce operation to two matrices. | |
SLEIPNIR_DLLEXPORT VariableMatrix | Block (std::initializer_list< std::initializer_list< VariableMatrix > > list) |
Assemble a VariableMatrix from a nested list of blocks. | |
SLEIPNIR_DLLEXPORT VariableMatrix | Block (const std::vector< std::vector< VariableMatrix > > &list) |
Assemble a VariableMatrix from a nested list of blocks. | |
SLEIPNIR_DLLEXPORT VariableMatrix | Solve (const VariableMatrix &A, const VariableMatrix &B) |
Solves the VariableMatrix equation AX = B for X. | |
template<typename F , typename State , typename Input , typename Time > | |
State | RK4 (F &&f, State x, Input u, Time t0, Time dt) |
Performs 4th order Runge-Kutta integration of dx/dt = f(t, x, u) for dt. | |
template<typename R , typename... Args> | |
constexpr void | swap (function_ref< R(Args...)> &lhs, function_ref< R(Args...)> &rhs) noexcept |
Swaps the referred callables of lhs and rhs . | |
template<typename R , typename... Args> | |
function_ref (R(*)(Args...)) -> function_ref< R(Args...)> | |
SLEIPNIR_DLLEXPORT constexpr std::string_view | ToMessage (const SolverExitCondition &exitCondition) |
Returns user-readable message corresponding to the exit condition. | |
SLEIPNIR_DLLEXPORT void | SQP (std::span< Variable > decisionVariables, std::span< Variable > equalityConstraints, Variable &f, function_ref< bool(const SolverIterationInfo &info)> callback, const SolverConfig &config, Eigen::VectorXd &x, SolverStatus *status) |
Finds the optimal solution to a nonlinear program using Sequential Quadratic Programming (SQP). | |
SLEIPNIR_DLLEXPORT PoolResource & | GlobalPoolResource () |
Returns a global pool memory resource. | |
template<typename T > | |
PoolAllocator< T > | GlobalPoolAllocator () |
Returns an allocator for a global pool memory resource. | |
SLEIPNIR_DLLEXPORT Variable | abs (const Variable &x) |
std::abs() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | acos (const Variable &x) |
std::acos() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | asin (const Variable &x) |
std::asin() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | atan (const Variable &x) |
std::atan() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | atan2 (const Variable &y, const Variable &x) |
std::atan2() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | cos (const Variable &x) |
std::cos() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | cosh (const Variable &x) |
std::cosh() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | erf (const Variable &x) |
std::erf() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | exp (const Variable &x) |
std::exp() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | hypot (const Variable &x, const Variable &y) |
std::hypot() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | pow (const Variable &base, const Variable &power) |
std::pow() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | log (const Variable &x) |
std::log() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | log10 (const Variable &x) |
std::log10() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | sign (const Variable &x) |
sign() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | sin (const Variable &x) |
std::sin() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | sinh (const Variable &x) |
std::sinh() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | sqrt (const Variable &x) |
std::sqrt() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | tan (const Variable &x) |
std::tan() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | tanh (const Variable &x) |
std::tanh() for Variables. | |
SLEIPNIR_DLLEXPORT Variable | hypot (const Variable &x, const Variable &y, const Variable &z) |
std::hypot() for Variables. | |
template<typename LHS , typename RHS > requires (ScalarLike<std::decay_t<LHS>> || MatrixLike<std::decay_t<LHS>>) && (ScalarLike<std::decay_t<RHS>> || MatrixLike<std::decay_t<RHS>>) && (!std::same_as<std::decay_t<LHS>, double> || !std::same_as<std::decay_t<RHS>, double>) | |
wpi::SmallVector< Variable > | MakeConstraints (LHS &&lhs, RHS &&rhs) |
Make a list of constraints. | |
template<typename LHS , typename RHS > requires (ScalarLike<std::decay_t<LHS>> || MatrixLike<std::decay_t<LHS>>) && (ScalarLike<std::decay_t<RHS>> || MatrixLike<std::decay_t<RHS>>) && (!std::same_as<std::decay_t<LHS>, double> || !std::same_as<std::decay_t<RHS>, double>) | |
EqualityConstraints | operator== (LHS &&lhs, RHS &&rhs) |
Equality operator that returns an equality constraint for two Variables. | |
template<typename LHS , typename RHS > requires (ScalarLike<std::decay_t<LHS>> || MatrixLike<std::decay_t<LHS>>) && (ScalarLike<std::decay_t<RHS>> || MatrixLike<std::decay_t<RHS>>) && (!std::same_as<std::decay_t<LHS>, double> || !std::same_as<std::decay_t<RHS>, double>) | |
InequalityConstraints | operator< (LHS &&lhs, RHS &&rhs) |
Less-than comparison operator that returns an inequality constraint for two Variables. | |
template<typename LHS , typename RHS > requires (ScalarLike<std::decay_t<LHS>> || MatrixLike<std::decay_t<LHS>>) && (ScalarLike<std::decay_t<RHS>> || MatrixLike<std::decay_t<RHS>>) && (!std::same_as<std::decay_t<LHS>, double> || !std::same_as<std::decay_t<RHS>, double>) | |
InequalityConstraints | operator<= (LHS &&lhs, RHS &&rhs) |
Less-than-or-equal-to comparison operator that returns an inequality constraint for two Variables. | |
template<typename LHS , typename RHS > requires (ScalarLike<std::decay_t<LHS>> || MatrixLike<std::decay_t<LHS>>) && (ScalarLike<std::decay_t<RHS>> || MatrixLike<std::decay_t<RHS>>) && (!std::same_as<std::decay_t<LHS>, double> || !std::same_as<std::decay_t<RHS>, double>) | |
InequalityConstraints | operator> (LHS &&lhs, RHS &&rhs) |
Greater-than comparison operator that returns an inequality constraint for two Variables. | |
template<typename LHS , typename RHS > requires (ScalarLike<std::decay_t<LHS>> || MatrixLike<std::decay_t<LHS>>) && (ScalarLike<std::decay_t<RHS>> || MatrixLike<std::decay_t<RHS>>) && (!std::same_as<std::decay_t<LHS>, double> || !std::same_as<std::decay_t<RHS>, double>) | |
InequalityConstraints | operator>= (LHS &&lhs, RHS &&rhs) |
Greater-than-or-equal-to comparison operator that returns an inequality constraint for two Variables. | |
template<typename T , typename... Args> | |
IntrusiveSharedPtr< T > | MakeIntrusiveShared (Args &&... args) |
Constructs an object of type T and wraps it in an intrusive shared pointer using args as the parameter list for the constructor of T. | |
template<typename T , typename Alloc , typename... Args> | |
IntrusiveSharedPtr< T > | AllocateIntrusiveShared (Alloc alloc, Args &&... args) |
Constructs an object of type T and wraps it in an intrusive shared pointer using alloc as the storage allocator of T and args as the parameter list for the constructor of T. | |
SLEIPNIR_DLLEXPORT void | InteriorPoint (std::span< Variable > decisionVariables, std::span< Variable > equalityConstraints, std::span< Variable > inequalityConstraints, Variable &f, function_ref< bool(const SolverIterationInfo &info)> callback, const SolverConfig &config, bool feasibilityRestoration, Eigen::VectorXd &x, Eigen::VectorXd &s, SolverStatus *status) |
Finds the optimal solution to a nonlinear program using the interior-point method. | |
template<typename DecisionVariables > | |
MultistartResult< DecisionVariables > | Multistart (function_ref< MultistartResult< DecisionVariables >(const DecisionVariables &initialGuess)> solve, std::span< const DecisionVariables > initialGuesses) |
Solves an optimization problem from different starting points in parallel, then returns the solution with the lowest cost. | |
SLEIPNIR_DLLEXPORT void | Spy (std::ostream &file, const Eigen::SparseMatrix< double > &mat) |
Write the sparsity pattern of a sparse matrix to a file. | |
SLEIPNIR_DLLEXPORT void | Spy (std::string_view filename, const Eigen::SparseMatrix< double > &mat) |
Write the sparsity pattern of a sparse matrix to a file. | |
template<typename... T> | |
void | print (fmt::format_string< T... > fmt, T &&... args) |
Wrapper around fmt::print() that squelches write failure exceptions. | |
template<typename... T> | |
void | print (std::FILE *f, fmt::format_string< T... > fmt, T &&... args) |
Wrapper around fmt::print() that squelches write failure exceptions. | |
template<typename... T> | |
void | println (fmt::format_string< T... > fmt, T &&... args) |
Wrapper around fmt::println() that squelches write failure exceptions. | |
template<typename... T> | |
void | println (std::FILE *f, fmt::format_string< T... > fmt, T &&... args) |
Wrapper around fmt::println() that squelches write failure exceptions. | |
Variables | |
class SLEIPNIR_DLLEXPORT | Hessian |
class SLEIPNIR_DLLEXPORT | Jacobian |
|
strong |
|
strong |
Expression type.
Used for autodiff caching.
|
strong |
Solver exit condition.
|
strong |
|
strong |
Enum describing an OCP transcription method.
|
inline |
std::abs() for Variables.
x | The argument. |
|
inline |
std::acos() for Variables.
x | The argument. |
IntrusiveSharedPtr< T > sleipnir::AllocateIntrusiveShared | ( | Alloc | alloc, |
Args &&... | args ) |
Constructs an object of type T and wraps it in an intrusive shared pointer using alloc as the storage allocator of T and args as the parameter list for the constructor of T.
T | Type of object for intrusive shared pointer. |
Alloc | Type of allocator for T. |
Args | Types of constructor arguments. |
alloc | The allocator for T. |
args | Constructor arguments for T. |
|
inline |
std::asin() for Variables.
x | The argument. |
|
inline |
std::atan() for Variables.
x | The argument. |
|
inline |
std::atan2() for Variables.
y | The y argument. |
x | The x argument. |
|
inline |
Assemble a VariableMatrix from a nested list of blocks.
Each row's blocks must have the same height, and the assembled block rows must have the same width. For example, for the block matrix [[A, B], [C]] to be constructible, the number of rows in A and B must match, and the number of columns in [A, B] and [C] must match.
This overload is for Python bindings only.
list | The nested list of blocks. |
|
inline |
Assemble a VariableMatrix from a nested list of blocks.
Each row's blocks must have the same height, and the assembled block rows must have the same width. For example, for the block matrix [[A, B], [C]] to be constructible, the number of rows in A and B must match, and the number of columns in [A, B] and [C] must match.
list | The nested list of blocks. |
|
inline |
std::cos() for Variables.
x | The argument. |
|
inline |
std::cosh() for Variables.
x | The argument. |
|
inline |
Applies a coefficient-wise reduce operation to two matrices.
lhs | The left-hand side of the binary operator. |
rhs | The right-hand side of the binary operator. |
binaryOp | The binary operator to use for the reduce operation. |
|
inline |
std::erf() for Variables.
x | The argument. |
|
inline |
std::exp() for Variables.
x | The argument. |
sleipnir::function_ref | ( | R(* | )(Args...) | ) | -> function_ref< R(Args...)> |
PoolAllocator< T > sleipnir::GlobalPoolAllocator | ( | ) |
Returns an allocator for a global pool memory resource.
T | The type of object in the pool. |
SLEIPNIR_DLLEXPORT PoolResource & sleipnir::GlobalPoolResource | ( | ) |
Returns a global pool memory resource.
|
inline |
std::hypot() for Variables.
x | The x argument. |
y | The y argument. |
|
inline |
std::hypot() for Variables.
x | The x argument. |
y | The y argument. |
z | The z argument. |
SLEIPNIR_DLLEXPORT void sleipnir::InteriorPoint | ( | std::span< Variable > | decisionVariables, |
std::span< Variable > | equalityConstraints, | ||
std::span< Variable > | inequalityConstraints, | ||
Variable & | f, | ||
function_ref< bool(const SolverIterationInfo &info)> | callback, | ||
const SolverConfig & | config, | ||
bool | feasibilityRestoration, | ||
Eigen::VectorXd & | x, | ||
Eigen::VectorXd & | s, | ||
SolverStatus * | status ) |
Finds the optimal solution to a nonlinear program using the interior-point method.
A nonlinear program has the form:
min_x f(x) subject to cₑ(x) = 0 cᵢ(x) ≥ 0
where f(x) is the cost function, cₑ(x) are the equality constraints, and cᵢ(x) are the inequality constraints.
[in] | decisionVariables | The list of decision variables. |
[in] | equalityConstraints | The list of equality constraints. |
[in] | inequalityConstraints | The list of inequality constraints. |
[in] | f | The cost function. |
[in] | callback | The user callback. |
[in] | config | Configuration options for the solver. |
[in] | feasibilityRestoration | Whether to use feasibility restoration instead of the normal algorithm. |
[in,out] | x | The initial guess and output location for the decision variables. |
[in,out] | s | The initial guess and output location for the inequality constraint slack variables. |
[out] | status | The solver status. |
|
inline |
std::log() for Variables.
x | The argument. |
|
inline |
std::log10() for Variables.
x | The argument. |
wpi::SmallVector< Variable > sleipnir::MakeConstraints | ( | LHS && | lhs, |
RHS && | rhs ) |
Make a list of constraints.
The standard form for equality constraints is c(x) = 0, and the standard form for inequality constraints is c(x) ≥ 0. This function takes constraints of the form lhs = rhs or lhs ≥ rhs and converts them to lhs - rhs = 0 or lhs - rhs ≥ 0.
lhs | Left-hand side. |
rhs | Right-hand side. |
IntrusiveSharedPtr< T > sleipnir::MakeIntrusiveShared | ( | Args &&... | args | ) |
Constructs an object of type T and wraps it in an intrusive shared pointer using args as the parameter list for the constructor of T.
T | Type of object for intrusive shared pointer. |
Args | Types of constructor arguments. |
args | Constructor arguments for T. |
MultistartResult< DecisionVariables > sleipnir::Multistart | ( | function_ref< MultistartResult< DecisionVariables >(const DecisionVariables &initialGuess)> | solve, |
std::span< const DecisionVariables > | initialGuesses ) |
Solves an optimization problem from different starting points in parallel, then returns the solution with the lowest cost.
Each solve is performed on a separate thread. Solutions from successful solves are always preferred over solutions from unsuccessful solves, and cost (lower is better) is the tiebreaker between successful solves.
DecisionVariables | The type containing the decision variable initial guess. |
solve | A user-provided function that takes a decision variable initial guess and returns a MultistartResult. |
initialGuesses | A list of decision variable initial guesses to try. |
InequalityConstraints sleipnir::operator< | ( | LHS && | lhs, |
RHS && | rhs ) |
Less-than comparison operator that returns an inequality constraint for two Variables.
lhs | Left-hand side. |
rhs | Left-hand side. |
InequalityConstraints sleipnir::operator<= | ( | LHS && | lhs, |
RHS && | rhs ) |
Less-than-or-equal-to comparison operator that returns an inequality constraint for two Variables.
lhs | Left-hand side. |
rhs | Left-hand side. |
EqualityConstraints sleipnir::operator== | ( | LHS && | lhs, |
RHS && | rhs ) |
Equality operator that returns an equality constraint for two Variables.
lhs | Left-hand side. |
rhs | Left-hand side. |
InequalityConstraints sleipnir::operator> | ( | LHS && | lhs, |
RHS && | rhs ) |
Greater-than comparison operator that returns an inequality constraint for two Variables.
lhs | Left-hand side. |
rhs | Left-hand side. |
InequalityConstraints sleipnir::operator>= | ( | LHS && | lhs, |
RHS && | rhs ) |
Greater-than-or-equal-to comparison operator that returns an inequality constraint for two Variables.
lhs | Left-hand side. |
rhs | Left-hand side. |
|
inline |
std::pow() for Variables.
base | The base. |
power | The power. |
|
inline |
Wrapper around fmt::print() that squelches write failure exceptions.
|
inline |
Wrapper around fmt::print() that squelches write failure exceptions.
|
inline |
Wrapper around fmt::println() that squelches write failure exceptions.
|
inline |
Wrapper around fmt::println() that squelches write failure exceptions.
State sleipnir::RK4 | ( | F && | f, |
State | x, | ||
Input | u, | ||
Time | t0, | ||
Time | dt ) |
Performs 4th order Runge-Kutta integration of dx/dt = f(t, x, u) for dt.
f | The function to integrate. It must take two arguments x and u. |
x | The initial value of x. |
u | The value u held constant over the integration period. |
t0 | The initial time. |
dt | The time over which to integrate. |
|
inline |
sign() for Variables.
x | The argument. |
|
inline |
std::sin() for Variables.
x | The argument. |
|
inline |
std::sinh() for Variables.
x | The argument. |
SLEIPNIR_DLLEXPORT VariableMatrix sleipnir::Solve | ( | const VariableMatrix & | A, |
const VariableMatrix & | B ) |
Solves the VariableMatrix equation AX = B for X.
A | The left-hand side. |
B | The right-hand side. |
|
inline |
Write the sparsity pattern of a sparse matrix to a file.
Each character represents an element with '.' representing zero, '+' representing positive, and '-' representing negative. Here's an example for a 3x3 identity matrix.
"+.." ".+." "..+"
[out] | file | A file stream. |
[in] | mat | The sparse matrix. |
|
inline |
Write the sparsity pattern of a sparse matrix to a file.
Each character represents an element with "." representing zero, "+" representing positive, and "-" representing negative. Here's an example for a 3x3 identity matrix.
"+.." ".+." "..+"
[in] | filename | The filename. |
[in] | mat | The sparse matrix. |
SLEIPNIR_DLLEXPORT void sleipnir::SQP | ( | std::span< Variable > | decisionVariables, |
std::span< Variable > | equalityConstraints, | ||
Variable & | f, | ||
function_ref< bool(const SolverIterationInfo &info)> | callback, | ||
const SolverConfig & | config, | ||
Eigen::VectorXd & | x, | ||
SolverStatus * | status ) |
Finds the optimal solution to a nonlinear program using Sequential Quadratic Programming (SQP).
A nonlinear program has the form:
min_x f(x) subject to cₑ(x) = 0
where f(x) is the cost function and cₑ(x) are the equality constraints.
[in] | decisionVariables | The list of decision variables. |
[in] | equalityConstraints | The list of equality constraints. |
[in] | f | The cost function. |
[in] | callback | The user callback. |
[in] | config | Configuration options for the solver. |
[in,out] | x | The initial guess and output location for the decision variables. |
[out] | status | The solver status. |
|
inline |
std::sqrt() for Variables.
x | The argument. |
|
constexprnoexcept |
Swaps the referred callables of lhs
and rhs
.
|
inline |
std::tan() for Variables.
x | The argument. |
|
inline |
std::tanh() for Variables.
x | The argument. |
|
constexpr |
Returns user-readable message corresponding to the exit condition.
exitCondition | Solver exit condition. |
class SLEIPNIR_DLLEXPORT sleipnir::Hessian |
class SLEIPNIR_DLLEXPORT sleipnir::Jacobian |