aligator
0.19.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Toggle main menu visibility
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
7
namespace
aligator
{
8
11
template
<
typename
Scalar>
struct
NewtonRaphson
{
12
ALIGATOR_DYNAMIC_TYPEDEFS
(Scalar);
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
fwd.hpp
Forward declarations.
aligator::compat::croc::context::Scalar
::aligator::context::Scalar Scalar
Definition
context.hpp:14
aligator
Main package namespace.
Definition
action-model-wrap.hpp:14
aligator::ManifoldAbstractTpl
Base class for manifolds, to use in cost funcs, solvers...
Definition
manifold-base.hpp:11
aligator::ManifoldAbstractTpl::integrate
void integrate(const ConstVectorRef &x, const ConstVectorRef &v, VectorRef out) const
Manifold integration operation .
aligator::NewtonRaphson::Options
Definition
newton-raphson.hpp:15
aligator::NewtonRaphson::Options::armijo_c1
Scalar armijo_c1
Definition
newton-raphson.hpp:18
aligator::NewtonRaphson::Options::alpha_min
Scalar alpha_min
Definition
newton-raphson.hpp:16
aligator::NewtonRaphson::Options::ls_beta
Scalar ls_beta
Definition
newton-raphson.hpp:17
aligator::NewtonRaphson
Newton-Raphson procedure, e.g. to compute forward dynamics from implicit functions.
Definition
newton-raphson.hpp:11
aligator::NewtonRaphson::ALIGATOR_DYNAMIC_TYPEDEFS
ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
aligator::NewtonRaphson::Manifold
ManifoldAbstractTpl< Scalar > Manifold
Definition
newton-raphson.hpp:13
aligator::NewtonRaphson::run
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{})
Definition
newton-raphson.hpp:22
include
aligator
utils
newton-raphson.hpp
Generated by
1.17.0