WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
interior_point.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 interior-point method 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, z) getter.
65 ///
66 /// L(xₖ, yₖ, zₖ) = f(xₖ) − yₖᵀcₑ(xₖ) − zₖᵀ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>z</td>
86 /// <td>num_inequality_constraints</td>
87 /// <td>1</td>
88 /// </tr>
89 /// <tr>
90 /// <td>∇ₓₓ²L(x, y, z)</td>
91 /// <td>num_decision_variables</td>
92 /// <td>num_decision_variables</td>
93 /// </tr>
94 /// </table>
95 std::function<Eigen::SparseMatrix<double>(const Eigen::VectorXd& x,
96 const Eigen::VectorXd& y,
97 const Eigen::VectorXd& z)>
99
100 /// Equality constraint value cₑ(x) getter.
101 ///
102 /// <table>
103 /// <tr>
104 /// <th>Variable</th>
105 /// <th>Rows</th>
106 /// <th>Columns</th>
107 /// </tr>
108 /// <tr>
109 /// <td>x</td>
110 /// <td>num_decision_variables</td>
111 /// <td>1</td>
112 /// </tr>
113 /// <tr>
114 /// <td>cₑ(x)</td>
115 /// <td>num_equality_constraints</td>
116 /// <td>1</td>
117 /// </tr>
118 /// </table>
119 std::function<Eigen::VectorXd(const Eigen::VectorXd& x)> c_e;
120
121 /// Equality constraint Jacobian ∂cₑ/∂x getter.
122 ///
123 /// @verbatim
124 /// [∇ᵀcₑ₁(xₖ)]
125 /// Aₑ(x) = [∇ᵀcₑ₂(xₖ)]
126 /// [ ⋮ ]
127 /// [∇ᵀcₑₘ(xₖ)]
128 /// @endverbatim
129 ///
130 /// <table>
131 /// <tr>
132 /// <th>Variable</th>
133 /// <th>Rows</th>
134 /// <th>Columns</th>
135 /// </tr>
136 /// <tr>
137 /// <td>x</td>
138 /// <td>num_decision_variables</td>
139 /// <td>1</td>
140 /// </tr>
141 /// <tr>
142 /// <td>Aₑ(x)</td>
143 /// <td>num_equality_constraints</td>
144 /// <td>num_decision_variables</td>
145 /// </tr>
146 /// </table>
147 std::function<Eigen::SparseMatrix<double>(const Eigen::VectorXd& x)> A_e;
148
149 /// Inequality constraint value cᵢ(x) getter.
150 ///
151 /// <table>
152 /// <tr>
153 /// <th>Variable</th>
154 /// <th>Rows</th>
155 /// <th>Columns</th>
156 /// </tr>
157 /// <tr>
158 /// <td>x</td>
159 /// <td>num_decision_variables</td>
160 /// <td>1</td>
161 /// </tr>
162 /// <tr>
163 /// <td>cᵢ(x)</td>
164 /// <td>num_inequality_constraints</td>
165 /// <td>1</td>
166 /// </tr>
167 /// </table>
168 std::function<Eigen::VectorXd(const Eigen::VectorXd& x)> c_i;
169
170 /// Inequality constraint Jacobian ∂cᵢ/∂x getter.
171 ///
172 /// @verbatim
173 /// [∇ᵀcᵢ₁(xₖ)]
174 /// Aᵢ(x) = [∇ᵀcᵢ₂(xₖ)]
175 /// [ ⋮ ]
176 /// [∇ᵀcᵢₘ(xₖ)]
177 /// @endverbatim
178 ///
179 /// <table>
180 /// <tr>
181 /// <th>Variable</th>
182 /// <th>Rows</th>
183 /// <th>Columns</th>
184 /// </tr>
185 /// <tr>
186 /// <td>x</td>
187 /// <td>num_decision_variables</td>
188 /// <td>1</td>
189 /// </tr>
190 /// <tr>
191 /// <td>Aᵢ(x)</td>
192 /// <td>num_inequality_constraints</td>
193 /// <td>num_decision_variables</td>
194 /// </tr>
195 /// </table>
196 std::function<Eigen::SparseMatrix<double>(const Eigen::VectorXd& x)> A_i;
197};
198
199/**
200Finds the optimal solution to a nonlinear program using the interior-point
201method.
202
203A nonlinear program has the form:
204
205@verbatim
206 min_x f(x)
207subject to cₑ(x) = 0
208 cᵢ(x) ≥ 0
209@endverbatim
210
211where f(x) is the cost function, cₑ(x) are the equality constraints, and cᵢ(x)
212are the inequality constraints.
213
214@param[in] matrix_callbacks Matrix callbacks.
215@param[in] iteration_callbacks The list of callbacks to call at the beginning of
216 each iteration.
217@param[in] options Solver options.
218@param[in,out] x The initial guess and output location for the decision
219 variables.
220@return The exit status.
221*/
224 std::span<std::function<bool(const IterationInfo& info)>>
225 iteration_callbacks,
226 const Options& options,
227#ifdef SLEIPNIR_ENABLE_BOUND_PROJECTION
228 const Eigen::ArrayX<bool>& bound_constraint_mask,
229#endif
230 Eigen::VectorXd& x);
231
232} // namespace slp
Definition expression_graph.hpp:11
ExitStatus
Solver exit status.
Definition exit_status.hpp:16
SLEIPNIR_DLLEXPORT ExitStatus interior_point(const InteriorPointMatrixCallbacks &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 the interior-point method.
Matrix callbacks for the interior-point method solver.
Definition interior_point.hpp:21
std::function< Eigen::SparseMatrix< double >(const Eigen::VectorXd &x)> A_i
Inequality constraint Jacobian ∂cᵢ/∂x getter.
Definition interior_point.hpp:196
std::function< Eigen::SparseMatrix< double >(const Eigen::VectorXd &x)> A_e
Equality constraint Jacobian ∂cₑ/∂x getter.
Definition interior_point.hpp:147
std::function< Eigen::SparseVector< double >(const Eigen::VectorXd &x)> g
Cost function gradient ∇f(x) getter.
Definition interior_point.hpp:62
std::function< Eigen::VectorXd(const Eigen::VectorXd &x)> c_e
Equality constraint value cₑ(x) getter.
Definition interior_point.hpp:119
std::function< double(const Eigen::VectorXd &x)> f
Cost function value f(x) getter.
Definition interior_point.hpp:41
std::function< Eigen::VectorXd(const Eigen::VectorXd &x)> c_i
Inequality constraint value cᵢ(x) getter.
Definition interior_point.hpp:168
std::function< Eigen::SparseMatrix< double >(const Eigen::VectorXd &x, const Eigen::VectorXd &y, const Eigen::VectorXd &z)> H
Lagrangian Hessian ∇ₓₓ²L(x, y, z) getter.
Definition interior_point.hpp:98
Solver iteration information exposed to an iteration callback.
Definition iteration_info.hpp:13
Solver options.
Definition options.hpp:15
#define SLEIPNIR_DLLEXPORT
Definition symbol_exports.hpp:34