WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
newton.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 Newton's 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) getter.
65 ///
66 /// L(xₖ) = f(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>∇ₓₓ²L(x)</td>
81 /// <td>num_decision_variables</td>
82 /// <td>num_decision_variables</td>
83 /// </tr>
84 /// </table>
85 std::function<Eigen::SparseMatrix<double>(const Eigen::VectorXd& x)> H;
86};
87
88/**
89Finds the optimal solution to a nonlinear program using Newton's method.
90
91A nonlinear program has the form:
92
93@verbatim
94 min_x f(x)
95@endverbatim
96
97where f(x) is the cost function.
98
99@param[in] matrix_callbacks Matrix callbacks.
100@param[in] iteration_callbacks The list of callbacks to call at the beginning of
101 each iteration.
102@param[in] options Solver options.
103@param[in,out] x The initial guess and output location for the decision
104 variables.
105@return The exit status.
106*/
108newton(const NewtonMatrixCallbacks& matrix_callbacks,
109 std::span<std::function<bool(const IterationInfo& info)>>
110 iteration_callbacks,
111 const Options& options, Eigen::VectorXd& x);
112
113} // namespace slp
Definition expression_graph.hpp:11
SLEIPNIR_DLLEXPORT ExitStatus newton(const NewtonMatrixCallbacks &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 Newton's method.
ExitStatus
Solver exit status.
Definition exit_status.hpp:16
Solver iteration information exposed to an iteration callback.
Definition iteration_info.hpp:13
Matrix callbacks for the Newton's method solver.
Definition newton.hpp:21
std::function< Eigen::SparseMatrix< double >(const Eigen::VectorXd &x)> H
Lagrangian Hessian ∇ₓₓ²L(x) getter.
Definition newton.hpp:85
std::function< Eigen::SparseVector< double >(const Eigen::VectorXd &x)> g
Cost function gradient ∇f(x) getter.
Definition newton.hpp:62
std::function< double(const Eigen::VectorXd &x)> f
Cost function value f(x) getter.
Definition newton.hpp:41
Solver options.
Definition options.hpp:15
#define SLEIPNIR_DLLEXPORT
Definition symbol_exports.hpp:34