crocoddyl 1.9.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
 
Loading...
Searching...
No Matches
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}^k,\delta\mathbf{u}^k)\) for the current guess \((\mathbf{x}^k_s,\mathbf{u}^k_s)\). More...
 
double computeDynamicFeasibility ()
 Compute the dynamic feasibility \(\|\mathbf{f}_{\mathbf{s}}\|_{\infty,1}\) for the current guess \((\mathbf{x}^k,\mathbf{u}^k)\). More...
 
virtual const Eigen::Vector2d & expectedImprovement ()=0
 Return the expected improvement \(dV_{exp}\) from a given current search direction \((\delta\mathbf{x}^k,\delta\mathbf{u}^k)\). More...
 
double get_cost () const
 Return the total cost. More...
 
const Eigen::Vector2d & get_d () const
 Return the LQ approximation of the expected improvement. More...
 
double get_dV () const
 Return the cost reduction \(dV\). More...
 
double get_dVexp () const
 Return the expected cost reduction \(dV_{exp}\). More...
 
double get_ffeas () const
 Return the feasibility of the dynamic constraints \(\|\mathbf{f}_{\mathbf{s}}\|_{\infty,1}\) of the current guess. More...
 
const std::vector< Eigen::VectorXd > & get_fs () const
 Return the gaps \(\mathbf{f}_{s}\). More...
 
bool get_inffeas () const
 Return the norm used for the computing the feasibility (true for \(\ell_\infty\), false for \(\ell_1\)) More...
 
bool get_is_feasible () const
 Return the feasibility status of the \((\mathbf{x}_s,\mathbf{u}_s)\) trajectory. More...
 
std::size_t get_iter () const
 Return the number of iterations performed by the solver. More...
 
const boost::shared_ptr< ShootingProblem > & get_problem () const
 Return the shooting problem. More...
 
double get_steplength () const
 Return the step length \(\alpha\). More...
 
double get_stop () const
 Return the value computed by stoppingCriteria() More...
 
double get_th_acceptstep () const
 Return the threshold used for accepting a step. More...
 
double get_th_gaptol () const
 Return the threshold for accepting a gap as non-zero. More...
 
double get_th_stop () const
 Return the tolerance for stopping the algorithm. More...
 
double get_ureg () const
 Return the control regularization value. More...
 
const std::vector< Eigen::VectorXd > & get_us () const
 Return the control trajectory \(\mathbf{u}_s\). More...
 
double get_xreg () const
 Return the state regularization value. More...
 
const std::vector< Eigen::VectorXd > & get_xs () const
 Return the state trajectory \(\mathbf{x}_s\). More...
 
const std::vector< boost::shared_ptr< CallbackAbstract > > & getCallbacks () const
 Return the list of callback functions using for diagnostic. More...
 
virtual void resizeData ()
 Resizing the solver data. More...
 
void set_inffeas (const bool inffeas)
 Modify the current norm used for computed the feasibility. More...
 
void set_th_acceptstep (const double th_acceptstep)
 Modify the threshold used for accepting step. More...
 
void set_th_gaptol (const double th_gaptol)
 Modify the threshold for accepting a gap as non-zero. More...
 
void set_th_stop (const double th_stop)
 Modify the tolerance for stopping the algorithm. More...
 
void set_ureg (const double ureg)
 Modify the control regularization value. More...
 
void set_us (const std::vector< Eigen::VectorXd > &us)
 Modify the control trajectory \(\mathbf{u}_s\). More...
 
void set_xreg (const double xreg)
 Modify the state regularization value. More...
 
void set_xs (const std::vector< Eigen::VectorXd > &xs)
 Modify the state trajectory \(\mathbf{x}_s\). More...
 
void setCallbacks (const std::vector< boost::shared_ptr< CallbackAbstract > > &callbacks)
 Set a list of callback functions using for the solver 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 trajectories \((\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 steplength=1)=0
 Try a predefined step length \(\alpha\) and compute its cost improvement \(dV\). More...
 

Protected Attributes

std::vector< boost::shared_ptr< CallbackAbstract > > callbacks_
 Callback functions. More...
 
double cost_
 Total cost. More...
 
Eigen::Vector2d d_
 LQ approximation of the expected improvement. More...
 
double dV_
 Cost reduction obtained by tryStep() More...
 
double dVexp_
 Expected cost reduction. More...
 
double ffeas_
 Feasibility of the dynamic constraints. More...
 
std::vector< Eigen::VectorXd > fs_
 Gaps/defects between shooting nodes. More...
 
bool inffeas_
 
bool is_feasible_
 Label that indicates is the iteration is feasible. More...
 
std::size_t iter_
 Number of iteration performed by the solver. More...
 
boost::shared_ptr< ShootingProblemproblem_
 optimal control problem More...
 
double steplength_
 Current applied step-length. More...
 
double stop_
 Value computed by stoppingCriteria() More...
 
double th_acceptstep_
 Threshold used for accepting step. More...
 
double th_gaptol_
 Threshold limit to check non-zero gaps. More...
 
double th_stop_
 Tolerance for stopping the algorithm. More...
 
double tmp_feas_
 Temporal variables used for computed the feasibility. More...
 
double ureg_
 Current control regularization values. More...
 
std::vector< Eigen::VectorXd > us_
 Control trajectory. More...
 
bool was_feasible_
 Label that indicates in the previous iterate was feasible. More...
 
double xreg_
 Current state regularization value. More...
 
std::vector< Eigen::VectorXd > xs_
 State trajectory. More...
 

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
solve(), computeDirection(), tryStep(), stoppingCriteria()

Definition at line 51 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 18 of file solver-base.cpp.

◆ ~SolverAbstract()

~SolverAbstract ( )
virtual

Definition at line 54 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]maxitermaximum 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}^k,\delta\mathbf{u}^k)\) for the current guess \((\mathbf{x}^k_s,\mathbf{u}^k_s)\).

You must call setCandidate() first in order to define the current guess. A current guess defines a state and control trajectory \((\mathbf{x}^k_s,\mathbf{u}^k_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  steplength = 1)
pure virtual

Try a predefined step length \(\alpha\) and compute its cost improvement \(dV\).

It uses the search direction found by computeDirection() to try a determined step length \(\alpha\). Therefore, it assumes that we have run computeDirection() first. Additionally, it returns the cost improvement \(dV\) along the predefined step length \(\alpha\).

Parameters
[in]steplengthapplied step length ( \(0\leq\alpha\leq1\))
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. 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 \(dV_{exp}\) from a given current search direction \((\delta\mathbf{x}^k,\delta\mathbf{u}^k)\).

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

Implemented in SolverDDP, SolverFDDP, and SolverKKT.

◆ resizeData()

void resizeData ( )
virtual

Resizing the solver data.

If the shooting problem has changed after construction, then this function resizes all the data before starting resolve the problem.

Reimplemented in SolverBoxDDP, SolverBoxFDDP, and SolverDDP.

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

◆ computeDynamicFeasibility()

double computeDynamicFeasibility ( )

Compute the dynamic feasibility \(\|\mathbf{f}_{\mathbf{s}}\|_{\infty,1}\) for the current guess \((\mathbf{x}^k,\mathbf{u}^k)\).

The feasibility can be computed using the computed using the \(\ell_\infty\) and \(\ell_1\) norms. By default we use the \(\ell_\infty\) norm; however, we can use the \(\ell_1\) norm via set_inffeas(). Note that \(\mathbf{f}_{\mathbf{s}}\) are the gaps on the dynamics, which are computed at each node as \(\mathbf{x}^{'}-\mathbf{f}(\mathbf{x},\mathbf{u})\).

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

◆ 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 trajectories \((\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 the dynamic feasibility of the \((\mathbf{x}_s,\mathbf{u}_s)\) pair. Note that the trajectories are feasible if \(\mathbf{x}_s\) is the resulting trajectory from the system rollout with \(\mathbf{u}_s\) inputs.

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 103 of file solver-base.cpp.

◆ setCallbacks()

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

Set a list of callback functions using for the solver 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 160 of file solver-base.cpp.

◆ getCallbacks()

const std::vector< boost::shared_ptr< CallbackAbstract > > & getCallbacks ( ) const

Return the list of callback functions using for diagnostic.

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

◆ get_problem()

const boost::shared_ptr< ShootingProblem > & get_problem ( ) const

Return the shooting problem.

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

◆ get_xs()

const std::vector< Eigen::VectorXd > & get_xs ( ) const

Return the state trajectory \(\mathbf{x}_s\).

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

◆ get_us()

const std::vector< Eigen::VectorXd > & get_us ( ) const

Return the control trajectory \(\mathbf{u}_s\).

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

◆ get_fs()

const std::vector< Eigen::VectorXd > & get_fs ( ) const

Return the gaps \(\mathbf{f}_{s}\).

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

◆ get_is_feasible()

bool get_is_feasible ( ) const

Return the feasibility status of the \((\mathbf{x}_s,\mathbf{u}_s)\) trajectory.

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

◆ get_cost()

double get_cost ( ) const

Return the total cost.

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

◆ get_stop()

double get_stop ( ) const

Return the value computed by stoppingCriteria()

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

◆ get_d()

const Eigen::Vector2d & get_d ( ) const

Return the LQ approximation of the expected improvement.

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

◆ get_xreg()

double get_xreg ( ) const

Return the state regularization value.

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

◆ get_ureg()

double get_ureg ( ) const

Return the control regularization value.

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

◆ get_steplength()

double get_steplength ( ) const

Return the step length \(\alpha\).

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

◆ get_dV()

double get_dV ( ) const

Return the cost reduction \(dV\).

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

◆ get_dVexp()

double get_dVexp ( ) const

Return the expected cost reduction \(dV_{exp}\).

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

◆ get_th_acceptstep()

double get_th_acceptstep ( ) const

Return the threshold used for accepting a step.

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

◆ get_th_stop()

double get_th_stop ( ) const

Return the tolerance for stopping the algorithm.

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

◆ get_iter()

std::size_t get_iter ( ) const

Return the number of iterations performed by the solver.

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

◆ get_th_gaptol()

double get_th_gaptol ( ) const

Return the threshold for accepting a gap as non-zero.

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

◆ get_ffeas()

double get_ffeas ( ) const

Return the feasibility of the dynamic constraints \(\|\mathbf{f}_{\mathbf{s}}\|_{\infty,1}\) of the current guess.

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

◆ get_inffeas()

bool get_inffeas ( ) const

Return the norm used for the computing the feasibility (true for \(\ell_\infty\), false for \(\ell_1\))

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

◆ set_xs()

void set_xs ( const std::vector< Eigen::VectorXd > &  xs)

Modify the state trajectory \(\mathbf{x}_s\).

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

◆ set_us()

void set_us ( const std::vector< Eigen::VectorXd > &  us)

Modify the control trajectory \(\mathbf{u}_s\).

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

◆ set_xreg()

void set_xreg ( const double  xreg)

Modify the state regularization value.

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

◆ set_ureg()

void set_ureg ( const double  ureg)

Modify the control regularization value.

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

◆ set_th_acceptstep()

void set_th_acceptstep ( const double  th_acceptstep)

Modify the threshold used for accepting step.

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

◆ set_th_stop()

void set_th_stop ( const double  th_stop)

Modify the tolerance for stopping the algorithm.

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

◆ set_th_gaptol()

void set_th_gaptol ( const double  th_gaptol)

Modify the threshold for accepting a gap as non-zero.

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

◆ set_inffeas()

void set_inffeas ( const bool  inffeas)

Modify the current norm used for computed the feasibility.

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

Member Data Documentation

◆ problem_

boost::shared_ptr<ShootingProblem> problem_
protected

optimal control problem

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

◆ xs_

std::vector<Eigen::VectorXd> xs_
protected

State trajectory.

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

◆ us_

std::vector<Eigen::VectorXd> us_
protected

Control trajectory.

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

◆ fs_

std::vector<Eigen::VectorXd> fs_
protected

Gaps/defects between shooting nodes.

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

◆ callbacks_

std::vector<boost::shared_ptr<CallbackAbstract> > callbacks_
protected

Callback functions.

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

◆ is_feasible_

bool is_feasible_
protected

Label that indicates is the iteration is feasible.

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

◆ was_feasible_

bool was_feasible_
protected

Label that indicates in the previous iterate was feasible.

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

◆ cost_

double cost_
protected

Total cost.

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

◆ stop_

double stop_
protected

Value computed by stoppingCriteria()

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

◆ d_

Eigen::Vector2d d_
protected

LQ approximation of the expected improvement.

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

◆ xreg_

double xreg_
protected

Current state regularization value.

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

◆ ureg_

double ureg_
protected

Current control regularization values.

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

◆ steplength_

double steplength_
protected

Current applied step-length.

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

◆ dV_

double dV_
protected

Cost reduction obtained by tryStep()

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

◆ dVexp_

double dVexp_
protected

Expected cost reduction.

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

◆ th_acceptstep_

double th_acceptstep_
protected

Threshold used for accepting step.

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

◆ th_stop_

double th_stop_
protected

Tolerance for stopping the algorithm.

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

◆ iter_

std::size_t iter_
protected

Number of iteration performed by the solver.

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

◆ th_gaptol_

double th_gaptol_
protected

Threshold limit to check non-zero gaps.

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

◆ ffeas_

double ffeas_
protected

Feasibility of the dynamic constraints.

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

◆ inffeas_

bool inffeas_
protected

True indicates if we use l-inf norm for computing the feasibility, otherwise false represents the l-1 norm

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

◆ tmp_feas_

double tmp_feas_
protected

Temporal variables used for computed the feasibility.

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


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