crocoddyl  1.4.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
SolverAbstract Class Referenceabstract

Abstract class for optimal control solvers. More...

#include <crocoddyl/core/solver-base.hpp>

Inheritance diagram for SolverAbstract:

Public Member Functions

EIGEN_MAKE_ALIGNED_OPERATOR_NEW SolverAbstract (boost::shared_ptr< ShootingProblem > problem)
 Initialize the solver. More...
 
virtual void computeDirection (const bool &recalc)=0
 Compute the search direction \((\delta\mathbf{x},\delta\mathbf{u})\) for the current guess \((\mathbf{x}_s,\mathbf{u}_s)\). More...
 
virtual const Eigen::Vector2d & expectedImprovement ()=0
 Return the expected improvement from a given current search direction. More...
 
const double & get_cost () const
 Return the total cost.
 
const Eigen::Vector2d & get_d () const
 Return the LQ approximation of the expected improvement.
 
const double & get_dV () const
 Return the cost reduction.
 
const double & get_dVexp () const
 Return the expected cost reduction.
 
const bool & get_is_feasible () const
 Return the feasibility status of the \((\mathbf{x}_s,\mathbf{u}_s)\) trajectory.
 
const std::size_t & get_iter () const
 Return the number of iterations performed by the solver.
 
const boost::shared_ptr< ShootingProblem > & get_problem () const
 Return the shooting problem.
 
const double & get_steplength () const
 Return the step length.
 
const double & get_stop () const
 Return the value computed by stoppingCriteria()
 
const double & get_th_acceptstep () const
 Return the threshold used for accepting a step.
 
const double & get_th_stop () const
 Return the tolerance for stopping the algorithm.
 
const double & get_ureg () const
 Return the control regularization value.
 
const std::vector< Eigen::VectorXd > & get_us () const
 Return the control trajectory \(\mathbf{u}_s\).
 
const double & get_xreg () const
 Return the state regularization value.
 
const std::vector< Eigen::VectorXd > & get_xs () const
 Return the state trajectory \(\mathbf{x}_s\).
 
const std::vector< boost::shared_ptr< CallbackAbstract > > & getCallbacks () const
 "Return the list of callback functions using for diagnostic
 
void set_th_acceptstep (const double &th_acceptstep)
 Modify the threshold used for accepting step.
 
void set_th_stop (const double &th_stop)
 Modify the tolerance for stopping the algorithm.
 
void set_ureg (const double &ureg)
 Modify the control regularization value.
 
void set_us (const std::vector< Eigen::VectorXd > &us)
 Modify the control trajectory \(\mathbf{u}_s\).
 
void set_xreg (const double &xreg)
 Modify the state regularization value.
 
void set_xs (const std::vector< Eigen::VectorXd > &xs)
 Modify the state trajectory \(\mathbf{x}_s\).
 
void setCallbacks (const std::vector< boost::shared_ptr< CallbackAbstract > > &callbacks)
 Set a list of callback functions using for diagnostic. More...
 
void setCandidate (const std::vector< Eigen::VectorXd > &xs_warm=DEFAULT_VECTOR, const std::vector< Eigen::VectorXd > &us_warm=DEFAULT_VECTOR, const bool &is_feasible=false)
 Set the solver candidate warm-point values \((\mathbf{x}_s,\mathbf{u}_s)\). More...
 
virtual bool solve (const std::vector< Eigen::VectorXd > &init_xs=DEFAULT_VECTOR, const std::vector< Eigen::VectorXd > &init_us=DEFAULT_VECTOR, const std::size_t &maxiter=100, const bool &is_feasible=false, const double &reg_init=1e-9)=0
 Compute the optimal trajectory \(\mathbf{x}^*_s,\mathbf{u}^*_s\) as lists of \(T+1\) and \(T\) terms. More...
 
virtual double stoppingCriteria ()=0
 Return a positive value that quantifies the algorithm termination. More...
 
virtual double tryStep (const double &step_length=1)=0
 Try a predefined step length and compute its cost improvement. More...
 

Protected Attributes

std::vector< boost::shared_ptr< CallbackAbstract > > callbacks_
 Callback functions.
 
double cost_
 Total cost.
 
Eigen::Vector2d d_
 LQ approximation of the expected improvement.
 
double dV_
 Cost reduction obtained by tryStep()
 
double dVexp_
 Expected cost reduction.
 
bool is_feasible_
 Label that indicates is the iteration is feasible.
 
std::size_t iter_
 Number of iteration performed by the solver.
 
boost::shared_ptr< ShootingProblemproblem_
 optimal control problem
 
double steplength_
 Current applied step-length.
 
double stop_
 Value computed by stoppingCriteria()
 
double th_acceptstep_
 Threshold used for accepting step.
 
double th_stop_
 Tolerance for stopping the algorithm.
 
double ureg_
 Current control regularization values.
 
std::vector< Eigen::VectorXd > us_
 Control trajectory.
 
double xreg_
 Current state regularization value.
 
std::vector< Eigen::VectorXd > xs_
 State trajectory.
 

Detailed Description

Abstract class for optimal control solvers.

A solver resolves an optimal control solver of the form

\begin{eqnarray*} \begin{Bmatrix} \mathbf{x}^*_0,\cdots,\mathbf{x}^*_{T} \\ \mathbf{u}^*_0,\cdots,\mathbf{u}^*_{T-1} \end{Bmatrix} = \arg\min_{\mathbf{x}_s,\mathbf{u}_s} && l_T (\mathbf{x}_T) + \sum_{k=0}^{T-1} l_k(\mathbf{x}_t,\mathbf{u}_t) \\ \operatorname{subject}\,\operatorname{to} && \mathbf{x}_0 = \mathbf{\tilde{x}}_0\\ && \mathbf{x}_{k+1} = \mathbf{f}_k(\mathbf{x}_k,\mathbf{u}_k)\\ && \mathbf{x}_k\in\mathcal{X}, \mathbf{u}_k\in\mathcal{U} \end{eqnarray*}

where \(l_T(\mathbf{x}_T)\), \(l_k(\mathbf{x}_t,\mathbf{u}_t)\) are the terminal and running cost functions, respectively, \(\mathbf{f}_k(\mathbf{x}_k,\mathbf{u}_k)\) describes evolution of the system, and state and control admissible sets are defined by \(\mathbf{x}_k\in\mathcal{X}\), \(\mathbf{u}_k\in\mathcal{U}\). An action model, defined in the shooting problem, describes each node \(k\). Inside the action model, we specialize the cost functions, the system evolution and the admissible sets.

The main routines are computeDirection() and tryStep(). The former finds a search direction and typically computes the derivatives of each action model. The latter rollout the dynamics and cost (i.e. the action) to try the search direction found by computeDirection. Both functions used the current guess defined by setCandidate. Finally solve function is used to define when the search direction and length are computed in each iterate. It also describes the globalization strategy (i.e. regularization) of the numerical optimization.

See also
computeDirection() and tryStep()

Definition at line 50 of file solver-base.hpp.

Constructor & Destructor Documentation

◆ SolverAbstract()

SolverAbstract ( boost::shared_ptr< ShootingProblem problem)
explicit

Initialize the solver.

Parameters
[in]problemShooting problem

Definition at line 14 of file solver-base.cpp.

Member Function Documentation

◆ solve()

virtual bool solve ( const std::vector< Eigen::VectorXd > &  init_xs = DEFAULT_VECTOR,
const std::vector< Eigen::VectorXd > &  init_us = DEFAULT_VECTOR,
const std::size_t &  maxiter = 100,
const bool &  is_feasible = false,
const double &  reg_init = 1e-9 
)
pure virtual

Compute the optimal trajectory \(\mathbf{x}^*_s,\mathbf{u}^*_s\) as lists of \(T+1\) and \(T\) terms.

From an initial guess init_xs, init_us (feasible or not), iterate over computeDirection() and tryStep() until stoppingCriteria() is below threshold. It also describes the globalization strategy used during the numerical optimization.

Parameters
[in]init_xsinitial guess for state trajectory with \(T+1\) elements (default [])
[in]init_usinitial guess for control trajectory with \(T\) elements (default [])
[in]maxitermaximun allowed number of iterations (default 100)
[in]isFeasibletrue if the init_xs are obtained from integrating the init_us (rollout) (default false)
[in]regInitinitial guess for the regularization value. Very low values are typical used with very good guess points (init_xs, init_us)
Returns
A boolean that describes if convergence was reached.")

Implemented in SolverDDP, SolverFDDP, and SolverKKT.

◆ computeDirection()

virtual void computeDirection ( const bool &  recalc)
pure virtual

Compute the search direction \((\delta\mathbf{x},\delta\mathbf{u})\) for the current guess \((\mathbf{x}_s,\mathbf{u}_s)\).

You must call setCandidate first in order to define the current guess. A current guess defines a state and control trajectory \((\mathbf{x}_s,\mathbf{u}_s)\) of \(T+1\) and \(T\) elements, respectively.

Parameters
[in]recalcTrue for recalculating the derivatives at current state and control
Returns
The search direction \((\delta\mathbf{x},\delta\mathbf{u})\) and the dual lambdas as lists of \(T+1\), \(T\) and \(T+1\) lengths, respectively

Implemented in SolverDDP, and SolverKKT.

◆ tryStep()

virtual double tryStep ( const double &  step_length = 1)
pure virtual

Try a predefined step length and compute its cost improvement.

It uses the search direction found by computeDirection() to try a determined step length \(\alpha\); so you need to run first computeDirection(). Additionally it returns the cost improvement along the predefined step length.

Parameters
[in]stepLengthstep length
Returns
The cost improvement

Implemented in SolverDDP, and SolverKKT.

◆ stoppingCriteria()

virtual double stoppingCriteria ( )
pure virtual

Return a positive value that quantifies the algorithm termination.

These values typically represents the gradient norm which tell us that it's been reached the local minima. This function is used to evaluate the algorithm convergence. The stopping criteria strictly speaking depends on the search direction (calculated by computeDirection()) but it could also depend on the chosen step length, tested by tryStep().

Implemented in SolverDDP, and SolverKKT.

◆ expectedImprovement()

virtual const Eigen::Vector2d& expectedImprovement ( )
pure virtual

Return the expected improvement from a given current search direction.

For computing the expected improvement, you need to compute first the search direction by running computeDirection().

Implemented in SolverFDDP, SolverDDP, and SolverKKT.

◆ setCandidate()

void setCandidate ( const std::vector< Eigen::VectorXd > &  xs_warm = DEFAULT_VECTOR,
const std::vector< Eigen::VectorXd > &  us_warm = DEFAULT_VECTOR,
const bool &  is_feasible = false 
)

Set the solver candidate warm-point values \((\mathbf{x}_s,\mathbf{u}_s)\).

The solver candidates are defined as a state and control trajectories \((\mathbf{x}_s,\mathbf{u}_s)\) of \(T+1\) and \(T\) elements, respectively. Additionally, we need to define is \((\mathbf{x}_s,\mathbf{u}_s)\) pair is feasible, this means that the dynamics rollout give us produces \(\mathbf{x}_s\).

Parameters
[in]xsstate trajectory of \(T+1\) elements (default [])
[in]uscontrol trajectory of \(T\) elements (default [])
[in]isFeasibletrue if the xs are obtained from integrating the us (rollout)

Definition at line 42 of file solver-base.cpp.

◆ setCallbacks()

void setCallbacks ( const std::vector< boost::shared_ptr< CallbackAbstract > > &  callbacks)

Set a list of callback functions using for diagnostic.

Each iteration, the solver calls these set of functions in order to allowed user the diagnostic of its performance.

Parameters
callbacksset of callback functions

Definition at line 69 of file solver-base.cpp.


The documentation for this class was generated from the following files: