aligator  0.6.1
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
linesearch.hpp
Go to the documentation of this file.
1
3#pragma once
4
5#include "aligator/fwd.hpp"
7
8namespace aligator {
9
14template <typename Scalar, typename F, typename M>
16 F &&phi, M &&model, const Scalar phi0,
17 const typename Linesearch<Scalar>::Options &ls_params, Scalar th_grad,
18 Scalar &d1, Scalar th_accept_step = 0.1, Scalar th_accept_neg_step = 2.0) {
19 const Scalar beta = ls_params.contraction_min;
20 Scalar atry = 1.;
21 Scalar phitry = phi0;
22 Scalar dVreal, dVmodel;
23 constexpr Scalar eps = std::numeric_limits<Scalar>::epsilon();
24
25 // backtrack until going under alpha_min
26 while (true) {
27 if (atry < ls_params.alpha_min + eps) {
28 break;
29 }
30 try {
31 phitry = phi(atry);
32 } catch (const ::aligator::RuntimeError &) {
33 atry *= beta;
34 continue;
35 }
36 dVreal = phitry - phi0;
37 dVmodel = model(atry) - phi0;
38 // check if descent direction
39 if (dVmodel < 0.) {
40 if (std::abs(d1) < th_grad || dVreal <= th_accept_step * dVmodel) {
41 break;
42 }
43 } else {
44 // or accept small increase in cost;
45 if (dVreal <= th_accept_neg_step * dVmodel) {
46 break;
47 }
48 }
49 atry *= beta;
50 atry = std::max(atry, ls_params.alpha_min);
51 }
52 return {atry, phitry};
53}
54
55} // namespace aligator
Forward declarations.
#define ALIGATOR_INLINE
Definition macros.hpp:13
Main package namespace.
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).