WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
sqp.hpp
Go to the documentation of this file.
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#include <functional>
6#include <span>
7
8#include <Eigen/Core>
9#include <Eigen/SparseCore>
10
15
16namespace slp {
17
18/**
19 * Matrix callbacks for the Sequential Quadratic Programming (SQP) solver.
20 */
22 /// Cost function value f(x) getter.
23 ///
24 /// <table>
25 /// <tr>
26 /// <th>Variable</th>
27 /// <th>Rows</th>
28 /// <th>Columns</th>
29 /// </tr>
30 /// <tr>
31 /// <td>x</td>
32 /// <td>num_decision_variables</td>
33 /// <td>1</td>
34 /// </tr>
35 /// <tr>
36 /// <td>f(x)</td>
37 /// <td>1</td>
38 /// <td>1</td>
39 /// </tr>
40 /// </table>
41 std::function<double(const Eigen::VectorXd& x)> f;
42
43 /// Cost function gradient ∇f(x) getter.
44 ///
45 /// <table>
46 /// <tr>
47 /// <th>Variable</th>
48 /// <th>Rows</th>
49 /// <th>Columns</th>
50 /// </tr>
51 /// <tr>
52 /// <td>x</td>
53 /// <td>num_decision_variables</td>
54 /// <td>1</td>
55 /// </tr>
56 /// <tr>
57 /// <td>∇f(x)</td>
58 /// <td>num_decision_variables</td>
59 /// <td>1</td>
60 /// </tr>
61 /// </table>
62 std::function<Eigen::SparseVector<double>(const Eigen::VectorXd& x)> g;
63
64 /// Lagrangian Hessian ∇ₓₓ²L(x, y) getter.
65 ///
66 /// L(xₖ, yₖ) = f(xₖ) − yₖᵀcₑ(xₖ)
67 ///
68 /// <table>
69 /// <tr>
70 /// <th>Variable</th>
71 /// <th>Rows</th>
72 /// <th>Columns</th>
73 /// </tr>
74 /// <tr>
75 /// <td>x</td>
76 /// <td>num_decision_variables</td>
77 /// <td>1</td>
78 /// </tr>
79 /// <tr>
80 /// <td>y</td>
81 /// <td>num_equality_constraints</td>
82 /// <td>1</td>
83 /// </tr>
84 /// <tr>
85 /// <td>∇ₓₓ²L(x, y)</td>
86 /// <td>num_decision_variables</td>
87 /// <td>num_decision_variables</td>
88 /// </tr>
89 /// </table>
90 std::function<Eigen::SparseMatrix<double>(const Eigen::VectorXd& x,
91 const Eigen::VectorXd& y)>
93
94 /// Equality constraint value cₑ(x) getter.
95 ///
96 /// <table>
97 /// <tr>
98 /// <th>Variable</th>
99 /// <th>Rows</th>
100 /// <th>Columns</th>
101 /// </tr>
102 /// <tr>
103 /// <td>x</td>
104 /// <td>num_decision_variables</td>
105 /// <td>1</td>
106 /// </tr>
107 /// <tr>
108 /// <td>cₑ(x)</td>
109 /// <td>num_equality_constraints</td>
110 /// <td>1</td>
111 /// </tr>
112 /// </table>
113 std::function<Eigen::VectorXd(const Eigen::VectorXd& x)> c_e;
114
115 /// Equality constraint Jacobian ∂cₑ/∂x getter.
116 ///
117 /// @verbatim
118 /// [∇ᵀcₑ₁(xₖ)]
119 /// Aₑ(x) = [∇ᵀcₑ₂(xₖ)]
120 /// [ ⋮ ]
121 /// [∇ᵀcₑₘ(xₖ)]
122 /// @endverbatim
123 ///
124 /// <table>
125 /// <tr>
126 /// <th>Variable</th>
127 /// <th>Rows</th>
128 /// <th>Columns</th>
129 /// </tr>
130 /// <tr>
131 /// <td>x</td>
132 /// <td>num_decision_variables</td>
133 /// <td>1</td>
134 /// </tr>
135 /// <tr>
136 /// <td>Aₑ(x)</td>
137 /// <td>num_equality_constraints</td>
138 /// <td>num_decision_variables</td>
139 /// </tr>
140 /// </table>
141 std::function<Eigen::SparseMatrix<double>(const Eigen::VectorXd& x)> A_e;
142};
143
144/**
145Finds the optimal solution to a nonlinear program using Sequential Quadratic
146Programming (SQP).
147
148A nonlinear program has the form:
149
150@verbatim
151 min_x f(x)
152subject to cₑ(x) = 0
153@endverbatim
154
155where f(x) is the cost function and cₑ(x) are the equality constraints.
156
157@param[in] matrix_callbacks Matrix callbacks.
158@param[in] iteration_callbacks The list of callbacks to call at the beginning of
159 each iteration.
160@param[in] options Solver options.
161@param[in,out] x The initial guess and output location for the decision
162 variables.
163@return The exit status.
164*/
166sqp(const SQPMatrixCallbacks& matrix_callbacks,
167 std::span<std::function<bool(const IterationInfo& info)>>
168 iteration_callbacks,
169 const Options& options, Eigen::VectorXd& x);
170
171} // namespace slp
Definition expression_graph.hpp:11
SLEIPNIR_DLLEXPORT ExitStatus sqp(const SQPMatrixCallbacks &matrix_callbacks, std::span< std::function< bool(const IterationInfo &info)> > iteration_callbacks, const Options &options, Eigen::VectorXd &x)
Finds the optimal solution to a nonlinear program using Sequential Quadratic Programming (SQP).
ExitStatus
Solver exit status.
Definition exit_status.hpp:16
Solver iteration information exposed to an iteration callback.
Definition iteration_info.hpp:13
Solver options.
Definition options.hpp:15
Matrix callbacks for the Sequential Quadratic Programming (SQP) solver.
Definition sqp.hpp:21
std::function< Eigen::SparseMatrix< double >(const Eigen::VectorXd &x)> A_e
Equality constraint Jacobian ∂cₑ/∂x getter.
Definition sqp.hpp:141
std::function< Eigen::SparseMatrix< double >(const Eigen::VectorXd &x, const Eigen::VectorXd &y)> H
Lagrangian Hessian ∇ₓₓ²L(x, y) getter.
Definition sqp.hpp:92
std::function< Eigen::VectorXd(const Eigen::VectorXd &x)> c_e
Equality constraint value cₑ(x) getter.
Definition sqp.hpp:113
std::function< double(const Eigen::VectorXd &x)> f
Cost function value f(x) getter.
Definition sqp.hpp:41
std::function< Eigen::SparseVector< double >(const Eigen::VectorXd &x)> g
Cost function gradient ∇f(x) getter.
Definition sqp.hpp:62
#define SLEIPNIR_DLLEXPORT
Definition symbol_exports.hpp:34