aligator  0.9.0
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/macros.hpp"
8#include <utility>
9
10namespace aligator {
11
16template <typename Scalar, typename F, typename M>
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
#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).