aligator
0.19.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Toggle main menu visibility
Loading...
Searching...
No Matches
linesearch.hpp
Go to the documentation of this file.
1
3
#pragma once
4
5
#include "
aligator/fwd.hpp
"
6
#include "
aligator/utils/exceptions.hpp
"
7
#include "
aligator/core/linesearch-base.hpp
"
8
#include <utility>
9
10
namespace
aligator
{
11
16
template
<
typename
Scalar,
typename
F,
typename
M>
17
ALIGATOR_INLINE
std::pair<Scalar, Scalar>
fddp_goldstein_linesearch
(
18
F &&phi, M &&model,
const
Scalar phi0,
19
const
typename
Linesearch<Scalar>::Options
&ls_params, Scalar th_grad,
20
Scalar &d1, Scalar th_accept_step = 0.1, Scalar th_accept_neg_step = 2.0) {
21
const
Scalar beta = ls_params.
contraction_min
;
22
Scalar atry = 1.;
23
Scalar phitry = phi0;
24
Scalar dVreal, dVmodel;
25
constexpr
Scalar eps = std::numeric_limits<Scalar>::epsilon();
26
27
// backtrack until going under alpha_min
28
while
(
true
) {
29
if
(atry < ls_params.
alpha_min
+ eps) {
30
break
;
31
}
32
try
{
33
phitry = phi(atry);
34
}
catch
(const ::aligator::RuntimeError &) {
35
atry *= beta;
36
continue
;
37
}
38
dVreal = phitry - phi0;
39
dVmodel = model(atry) - phi0;
40
// check if descent direction
41
if
(dVmodel < 0.) {
42
if
(std::abs(d1) < th_grad || dVreal <= th_accept_step * dVmodel) {
43
break
;
44
}
45
}
else
{
46
// or accept small increase in cost;
47
if
(dVreal <= th_accept_neg_step * dVmodel) {
48
break
;
49
}
50
}
51
atry *= beta;
52
atry = std::max(atry, ls_params.
alpha_min
);
53
}
54
return
{atry, phitry};
55
}
56
57
}
// namespace aligator
aligator::Linesearch::Options
LinesearchOptions< T > Options
Definition
linesearch-base.hpp:48
exceptions.hpp
fwd.hpp
Forward declarations.
ALIGATOR_INLINE
#define ALIGATOR_INLINE
Definition
fwd.hpp:27
linesearch-base.hpp
Base structs for linesearch algorithms.
aligator
Main package namespace.
Definition
action-model-wrap.hpp:14
aligator::fddp_goldstein_linesearch
ALIGATOR_INLINE std::pair< Scalar, Scalar > fddp_goldstein_linesearch(F &&phi, M &&model, const Scalar phi0, const typename Linesearch< Scalar >::Options &ls_params, Scalar th_grad, Scalar &d1, Scalar th_accept_step=0.1, Scalar th_accept_neg_step=2.0)
The backtracking linesearch from FDDP (Mastalli et al).
Definition
linesearch.hpp:17
aligator::LinesearchOptions::alpha_min
T alpha_min
Definition
linesearch-base.hpp:26
aligator::LinesearchOptions::contraction_min
T contraction_min
Definition
linesearch-base.hpp:29
include
aligator
solvers
fddp
linesearch.hpp
Generated by
1.17.0