aligator  0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
newton-raphson.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "aligator/fwd.hpp"
4
5#include <Eigen/LU>
6
7namespace aligator {
8
11template <typename Scalar> struct NewtonRaphson {
13 using Manifold = ManifoldAbstractTpl<Scalar>;
14
15 struct Options {
16 Scalar alpha_min = 1e-4;
17 Scalar ls_beta = 0.7071;
18 Scalar armijo_c1 = 1e-2;
19 };
20
21 template <typename Fun, typename JacFun>
22 static bool run(const Manifold &space, Fun &&fun, JacFun &&jac_fun,
23 const ConstVectorRef &xinit, VectorRef xout, VectorRef f0,
24 VectorRef dx, MatrixRef Jf0, Scalar eps = 1e-6,
25 std::size_t max_iters = 1000, Options options = Options{}) {
26
27 xout = xinit;
28
29 fun(xout, f0);
30
31 // workspace
32 VectorXs dx_ls = dx;
33 VectorXs xcand = xout;
34
35 Scalar err = f0.norm();
36 std::size_t iter = 0;
37 while (true) {
38
39 if (err <= eps) {
40 return true;
41 } else if (iter >= max_iters) {
42 return false;
43 }
44
45 jac_fun(xout, Jf0);
46 dx = Jf0.lu().solve(-f0);
47
48 // linesearch
49 Scalar alpha = 1.;
50 while (alpha > options.alpha_min) {
51 dx_ls = alpha * dx; // avoid malloc in ls
52 space.integrate(xout, dx_ls, xcand);
53 fun(xcand, f0);
54 Scalar cand_err = f0.norm();
55 if (cand_err <= (1. - options.armijo_c1) * err) {
56 xout = xcand;
57 err = cand_err;
58 break;
59 }
60 alpha *= options.ls_beta;
61 }
62
63 iter++;
64 }
65 }
66};
67
68} // namespace aligator
Forward declarations.
Main package namespace.
Newton-Raphson procedure, e.g. to compute forward dynamics from implicit functions.
ManifoldAbstractTpl< Scalar > Manifold
static bool run(const Manifold &space, Fun &&fun, JacFun &&jac_fun, const ConstVectorRef &xinit, VectorRef xout, VectorRef f0, VectorRef dx, MatrixRef Jf0, Scalar eps=1e-6, std::size_t max_iters=1000, Options options=Options{})