Crocoddyl
Loading...
Searching...
No Matches
fddp.hpp
1
2// BSD 3-Clause License
3//
4// Copyright (C) 2019-2025, LAAS-CNRS, University of Edinburgh,
5// Heriot-Watt University
6// Copyright note valid unless otherwise stated in individual files.
7// All rights reserved.
9
10#ifndef CROCODDYL_CORE_SOLVERS_FDDP_HPP_
11#define CROCODDYL_CORE_SOLVERS_FDDP_HPP_
12
13#include "crocoddyl/core/solver-base.hpp"
14#include "crocoddyl/core/utils/deprecate.hpp"
15
16namespace crocoddyl {
17
18enum DynamicsSolverType {
19 FeasShoot = 0,
20 MultiShoot,
21 HybridShoot,
22 SingleShoot
23};
24
25enum EqualitySolverType {
26 LuNull = 0,
27 QrNull,
28 Schur,
29};
30
69template <typename _Scalar>
70class SolverFDDPTpl : public SolverAbstractTpl<_Scalar> {
71 public:
72 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
73 CROCODDYL_DERIVED_FLOATINGPOINT_CAST(SolverBase, SolverFDDPTpl)
74
75 typedef _Scalar Scalar;
76 typedef SolverAbstractTpl<Scalar> SolverAbstract;
77 typedef ShootingProblemTpl<Scalar> ShootingProblem;
78 typedef typename ShootingProblem::ActionModelAbstract ActionModelAbstract;
79 typedef typename ShootingProblem::ActionDataAbstract ActionDataAbstract;
80 typedef CallbackAbstractTpl<Scalar> CallbackAbstract;
81 typedef MathBaseTpl<Scalar> MathBase;
82 typedef typename MathBase::VectorXs VectorXs;
83 typedef typename MathBase::Vector3s Vector3s;
84 typedef typename MathBase::MatrixXs MatrixXs;
85 typedef typename MathBase::MatrixXsRowMajor MatrixXsRowMajor;
91
99 explicit SolverFDDPTpl(std::shared_ptr<ShootingProblem> problem,
100 const DynamicsSolverType dyn_solver = FeasShoot,
101 const EqualitySolverType term_solver = LuNull);
102 virtual ~SolverFDDPTpl() = default;
103
107 virtual void computeDirection(const bool recalc = true) override;
108
112 virtual void computeCandidate(const Scalar step_length = Scalar(1.)) override;
113
128 void forwardPass(const Scalar steplength = Scalar(1.));
129
135 virtual void updateDualsAndSlacks(const Scalar stepLength = Scalar(1.));
136
140 virtual Scalar stoppingCriteria() override;
141
155 virtual Vector3s expectedImprovement() override;
156
160 virtual void computeMeritFunctionImprovement() override;
161
166
170 virtual void updateMeritFunction() override;
171
177 virtual bool checkAcceptance() override;
178
211 virtual void backwardPass();
212
220 void batchPass();
221
225 void updateDir();
226
236 const std::size_t t, const std::shared_ptr<ActionModelAbstract>& model,
237 const std::shared_ptr<ActionDataAbstract>& data);
238
247 const std::size_t t, const std::shared_ptr<ActionDataAbstract>& data);
248
263 virtual void computePolicy(const std::size_t t);
264
272 virtual void computeBatchPolicy(const std::size_t t);
273
284 const std::size_t t, const std::shared_ptr<ActionModelAbstract>& model);
285
295 virtual void computeBatchValueFunction(const std::size_t t);
296
303
313 virtual void feasShootForwardPass(const Scalar steplength);
314
323 virtual void multiShootForwardPass(const Scalar steplength);
324
334 virtual void hybridShootForwardPass(const Scalar steplength);
335
345 virtual void singleShootForwardPass(const Scalar steplength);
346
350 void updateCandidate() override;
351
356
361
366 void increaseRegularization() override;
367
372 void decreaseRegularization() override;
373
382 template <typename NewScalar>
384
388 DynamicsSolverType get_dynamics_solver() const;
389
393 EqualitySolverType get_terminal_solver() const;
394
398 Scalar get_reg_incfactor() const;
399
403 Scalar get_reg_decfactor() const;
404
409 Scalar get_th_grad() const;
410
414 Scalar get_th_stepdec() const;
415
419 Scalar get_th_stepinc() const;
420
425 Scalar get_th_minimprove() const;
426
430 Scalar get_th_acceptnegstep() const;
431
435 Scalar get_th_acceptminstep() const;
436
440 Scalar get_rho() const;
441
445 Scalar get_th_minfeas() const;
446
451 Scalar get_upsilon() const;
452
457 Scalar get_upsilon_decfactor() const;
458
465 bool get_zero_upsilon() const;
466
470 const std::vector<std::size_t>& get_Ts() const;
471
475 const std::vector<MatrixXs>& get_Vxx() const;
476
480 const std::vector<VectorXs>& get_Vx() const;
481
486 const std::vector<MatrixXs>& get_Qxx() const;
487
492 const std::vector<MatrixXs>& get_Qxu() const;
493
498 const std::vector<MatrixXs>& get_Quu() const;
499
504 const std::vector<VectorXs>& get_Qx() const;
505
510 const std::vector<VectorXs>& get_Qu() const;
511
515 const std::vector<MatrixXsRowMajor>& get_K() const;
516
520 const std::vector<VectorXs>& get_k() const;
521
525 const std::vector<MatrixXs>& get_Vxc() const;
526
531 const std::vector<MatrixXs>& get_Qxc() const;
532
537 const std::vector<MatrixXs>& get_Quc() const;
538
542 const std::vector<MatrixXs>& get_dXc() const;
543
547 const std::vector<MatrixXs>& get_dUc() const;
548
552 const std::vector<MatrixXs>& get_Kc() const;
553
558 const MatrixXs& get_dHc() const;
559
564 const VectorXs& get_hc() const;
565
570 const VectorXs& get_beta_plus() const;
571
582 void set_dynamics_solver(const DynamicsSolverType type,
583 const std::size_t Tshoot = 0);
584
590 void set_terminal_solver(const EqualitySolverType type);
591
595 void set_reg_incfactor(const Scalar reg_factor);
596
600 void set_reg_decfactor(const Scalar reg_factor);
601
606 void set_th_grad(const Scalar th_grad);
607
612 void set_th_noimprovement(const Scalar th_noimprovement);
613
617 void set_th_stepdec(const Scalar th_step);
618
622 void set_th_stepinc(const Scalar th_step);
623
628 void set_th_minimprove(const Scalar th_step);
629
633 void set_th_acceptnegstep(const Scalar th_acceptnegstep);
634
638 void set_th_acceptminstep(const Scalar th_acceptminstep);
639
643 void set_rho(const Scalar rho);
644
648 void set_th_minfeas(const Scalar th_minfeas);
649
654 void set_upsilon_decfactor(const Scalar th_step);
655
662 void set_zero_upsilon(const bool zero_upsilon);
663
664 protected:
669
673 virtual void resizeRunningData() override;
674
678 virtual void resizeTerminalData() override;
679
684
685 DynamicsSolverType dyn_solver_;
686 EqualitySolverType term_solver_;
691 Scalar th_grad_;
695 Scalar
697 Scalar
705 Scalar rho_;
708 Scalar
715 std::vector<std::size_t> Ts_;
716
717 // allocate data
718 MatrixXs Vxx_tmp_;
719 std::vector<MatrixXs>
721 std::vector<VectorXs>
724 std::vector<VectorXs>
726 std::vector<VectorXs>
729 std::vector<VectorXs>
732 std::vector<VectorXs>
735 std::vector<MatrixXs>
737 std::vector<MatrixXs>
739 std::vector<MatrixXs>
741 std::vector<VectorXs>
743 std::vector<VectorXs>
745 std::vector<MatrixXsRowMajor> K_;
746 std::vector<VectorXs> k_;
747 std::vector<VectorXs>
749 std::vector<MatrixXsRowMajor>
752 std::vector<MatrixXsRowMajor>
756 VectorXs fTVxx_p_;
758 std::vector<Eigen::LLT<MatrixXs> > Quu_llt_;
759 std::vector<VectorXs>
760 Quuk_;
762
763 std::size_t dHc_rank_;
764 std::vector<MatrixXs>
765 Vxc_;
767 std::vector<MatrixXs>
768 Qxc_;
770 std::vector<MatrixXs>
771 Quc_;
773 std::vector<MatrixXs> dXc_;
775 std::vector<MatrixXs> dUc_;
777 std::vector<MatrixXs> Kc_;
779 MatrixXs dHc_;
780 VectorXs hc_;
781 MatrixXs YZc_;
782 VectorXs Yhc_;
783 MatrixXs dHcY_;
784 MatrixXs YdHcY_;
785 VectorXs beta_plus_;
786 Eigen::LLT<MatrixXs>
787 YdHcY_llt_;
788 Eigen::FullPivLU<MatrixXs>
789 dHc_lu_;
791 Eigen::ColPivHouseholderQR<MatrixXs>
792 dHc_qr_;
794
795 DEPRECATED(
796 "Do not use this member",
797 Scalar dg_;)
798 DEPRECATED(
799 "Do not use this member",
800 Scalar dq_;)
801 DEPRECATED(
802 "Do not use this member",
803 Scalar dv_;)
804
805 using SolverAbstract::acceptstep_;
822 using SolverAbstract::feasnorm_;
842 using SolverAbstract::th_gaptol_;
848};
849
850} // namespace crocoddyl
851
852/* --- Details -------------------------------------------------------------- */
853/* --- Details -------------------------------------------------------------- */
854/* --- Details -------------------------------------------------------------- */
855#include "crocoddyl/core/solvers/fddp.hxx"
856
857CROCODDYL_DISABLE_WARNING_DEPRECATED
858
859CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS(crocoddyl::SolverFDDPTpl)
860
861CROCODDYL_ENABLE_WARNING_DEPRECATED
862
863#endif // CROCODDYL_CORE_SOLVERS_FDDP_HPP_
Abstract class for solver callbacks.
This class encapsulates a shooting problem.
Definition shooting.hpp:32
std::shared_ptr< ShootingProblem > problem_
SolverAbstractTpl(std::shared_ptr< ShootingProblem > problem)
Initialize the solver.
std::vector< std::shared_ptr< CallbackAbstract > > callbacks_
Scalar computeFeasibility(const std::vector< VectorXs > &fs)
Feasibility-driven Differential Dynamic Programming (FDDP) solver.
Definition fddp.hpp:70
Scalar get_reg_incfactor() const
Return the regularization factor used to increase the damping value.
std::vector< VectorXs > dx_
Definition fddp.hpp:748
DynamicsSolverType get_dynamics_solver() const
Return the type of solver used for handling the dynamics constraints.
const std::vector< MatrixXs > & get_Vxx() const
Return the Hessian of the Value function .
Scalar get_th_minimprove() const
Return the minimum improvement threshold used to increase regularization.
void set_reg_incfactor(const Scalar reg_factor)
Modify the regularization factor used to increase the damping value.
virtual void resizeRunningData() override
Resize data associated with the running models of the shooting problem.
std::vector< MatrixXs > Vxx_
Definition fddp.hpp:720
const std::vector< MatrixXs > & get_Kc() const
Return the feedforward gains .
void set_th_stepdec(const Scalar th_step)
Modify the step-length threshold used to decrease regularization.
virtual void computeDirection(const bool recalc=true) override
Compute the search direction for the current guess .
const std::vector< MatrixXs > & get_Quu() const
Return the Hessian of the Hamiltonian function .
std::vector< MatrixXsRowMajor > FuTVxx_p_
Definition fddp.hpp:753
virtual void computeExpectedMeritFunctionImprovement() override
Compute the expected merit function improvement for the current step.
Scalar get_rho() const
Return the rho parameter used in the merit function.
const std::vector< MatrixXs > & get_dXc() const
Return the linear update in .
void updateDir()
Update search direction associated with the batch's constraints.
void set_th_stepinc(const Scalar th_step)
Modify the step-length threshold used to increase regularization.
virtual void backwardPass()
Run the backward pass (Riccati sweep).
void set_th_acceptminstep(const Scalar th_acceptminstep)
Modify the threshold used for accepting minimum steps.
EqualitySolverType get_terminal_solver() const
Return the type of solver used for handling the terminal constraints.
virtual void hybridShootForwardPass(const Scalar steplength)
Run the multiple-shooting rollout with intervals of feasibility-driven search.
const std::vector< VectorXs > & get_Vx() const
Return the Hessian of the Value function .
virtual void computeCandidate(const Scalar step_length=Scalar(1.)) override
Compute new candidate solution using step length.
virtual void computeValueFunction(const std::size_t t, const std::shared_ptr< ActionModelAbstract > &model)
Compute the linear-quadratic approximation of the value function.
void set_th_minfeas(const Scalar th_minfeas)
Modify the threshold for switching to feasibility.
Scalar get_th_stepdec() const
Return the step-length threshold used to decrease regularization.
virtual void computeActionValueFunction(const std::size_t t, const std::shared_ptr< ActionModelAbstract > &model, const std::shared_ptr< ActionDataAbstract > &data)
Compute the linear-quadratic approximation of the control action-value function.
DynamicsSolverType dyn_solver_
Definition fddp.hpp:685
std::vector< VectorXs > Lxx_dx_
Definition fddp.hpp:727
Scalar get_th_acceptminstep() const
Return the threshold used for accepting minimum steps.
virtual void updateDualsAndSlacks(const Scalar stepLength=Scalar(1.))
Update the dual and slack variables with a predefined step length.
std::vector< VectorXs > Qx_
Definition fddp.hpp:742
void forwardPass(const Scalar steplength=Scalar(1.))
Perform a forward pass with a predefined step length.
void batchPass()
Run the batch pass to account for its constraints.
virtual void computeBatchPolicy(const std::size_t t)
Compute the feedforward and feedback terms (control policy) associated to the batch's constraints.
const std::vector< std::size_t > & get_Ts() const
Return the hybrid shooting intervals.
void allocateData()
Allocate all the internal data needed for the solver.
Scalar get_upsilon() const
Return the estimated penalty parameter that balances relative contribution of the cost function and e...
std::vector< MatrixXs > Qxx_
Definition fddp.hpp:736
const std::vector< VectorXs > & get_Qx() const
Return the Jacobian of the Hamiltonian function .
void set_th_noimprovement(const Scalar th_noimprovement)
Modify the threshold used to accept steps that cannot be be improved due to numerical errors the th n...
const std::vector< VectorXs > & get_Qu() const
Return the Jacobian of the Hamiltonian function .
const std::vector< MatrixXs > & get_Qxc() const
Return the Hessian of the Hamiltonian function .
void set_reg_decfactor(const Scalar reg_factor)
Modify the regularization factor used to decrease the damping value.
SolverFDDPTpl(std::shared_ptr< ShootingProblem > problem, const DynamicsSolverType dyn_solver=FeasShoot, const EqualitySolverType term_solver=LuNull)
Initialize the FDDP solver.
bool increaseRegularizationCriteria() override
Criteria used to increase regularization.
const std::vector< MatrixXs > & get_dUc() const
Return the linear update in .
const std::vector< MatrixXsRowMajor > & get_K() const
Return the feedback gains .
std::vector< MatrixXs > Qxu_
Definition fddp.hpp:738
virtual void computeMeritFunctionImprovement() override
Compute the merit function improvement for the current step.
void set_upsilon_decfactor(const Scalar th_step)
Modify the upsilon decresing factor used to estimate to balance optimality and feasibility.
virtual void computeBatchValueFunction(const std::size_t t)
Compute the linear-quadratic approximation of the value function associated to the batch's constraint...
void set_th_minimprove(const Scalar th_step)
Modify the minimum improvement threshold used to increase regularization.
void set_rho(const Scalar rho)
Modify the rho parameter used in the merit function.
void set_terminal_solver(const EqualitySolverType type)
Set the type of solver used for handling the terminal constraints.
Scalar get_upsilon_decfactor() const
Return the upsilon decresing factor used to estimate to balance optimality and feasibility.
const std::vector< VectorXs > & get_k() const
Return the feedforward gains .
SolverFDDPTpl< NewScalar > cast() const
Cast the FDDP solver to a different scalar type.
void set_zero_upsilon(const bool zero_upsilon)
Modify the zero-upsilon label.
virtual void feasShootForwardPass(const Scalar steplength)
Run the feasibility-driven nonlinear rollout.
std::vector< MatrixXs > Quu_
Definition fddp.hpp:740
std::vector< VectorXs > Lxu_du_
Definition fddp.hpp:733
std::vector< std::size_t > Ts_
Definition fddp.hpp:715
Scalar get_th_stepinc() const
Return the step-length threshold used to increase regularization.
std::vector< MatrixXsRowMajor > FxTVxx_p_
Definition fddp.hpp:750
const VectorXs & get_beta_plus() const
Return the next terminal-constraint multiplier .
const std::vector< MatrixXs > & get_Vxc() const
Return the Hessian of the Value function .
bool decreaseRegularizationCriteria() override
Criteria used to decrease regularization.
virtual void computeBatchActionValueFunction(const std::size_t t, const std::shared_ptr< ActionDataAbstract > &data)
Compute the linear-quadratic approximation of the control action-value function associated to the bat...
std::vector< VectorXs > Vx_
Definition fddp.hpp:725
void set_th_acceptnegstep(const Scalar th_acceptnegstep)
Modify the threshold used for accepting step along ascent direction.
std::vector< VectorXs > Qu_
Definition fddp.hpp:744
const VectorXs & get_hc() const
Return the bias term of the terminal constraint gains .
Scalar get_th_minfeas() const
Return the threshold for switching to feasibility.
virtual void resizeTerminalData() override
Resize data associated with the terminal model of the shooting problem.
const std::vector< MatrixXs > & get_Qxu() const
Return the Hessian of the Hamiltonian function .
void set_dynamics_solver(const DynamicsSolverType type, const std::size_t Tshoot=0)
Set the dynamic solver used for handling the dynamics constraints.
std::vector< MatrixXsRowMajor > K_
Definition fddp.hpp:745
bool get_zero_upsilon() const
Return the zero-upsilon label.
const std::vector< MatrixXs > & get_Qxx() const
Return the Hessian of the Hamiltonian function .
virtual void computePolicy(const std::size_t t)
Compute the feedforward and feedback terms (control policy) computed via a Cholesky decomposition.
EqualitySolverType term_solver_
Definition fddp.hpp:686
Scalar get_th_grad() const
Return the tolerance of the expected gradient used for testing the step.
void decreaseRegularization() override
Decrease the state and control regularization values by a regfactor_ factor.
std::vector< Eigen::LLT< MatrixXs > > Quu_llt_
Definition fddp.hpp:758
void increaseRegularization() override
Increase the state and control regularization values by a regfactor_ factor.
virtual Vector3s expectedImprovement() override
Return the expected improvement from a given current search direction .
virtual Scalar stoppingCriteria() override
Return a positive value that quantifies the algorithm termination.
void computeNullTerminalMultiplier()
compute the multiplier associated to the terminal constraint
virtual bool checkAcceptance() override
Check if we should accept or not the step.
virtual void updateMeritFunction() override
Update the merit function value for the current guess.
Scalar get_th_acceptnegstep() const
Return the threshold used for accepting step along ascent direction.
void updateCandidate() override
Update the candidate solution: cost, feasibilities, and merit value.
void set_th_grad(const Scalar th_grad)
Modify the tolerance of the expected gradient used for testing the step.
std::vector< VectorXs > Vxx_f_
Definition fddp.hpp:722
std::vector< VectorXs > k_
Definition fddp.hpp:746
void linearRollout()
Perform a linear rollout give the current control policy.
Scalar get_reg_decfactor() const
Return the regularization factor used to decrease the damping value.
virtual void multiShootForwardPass(const Scalar steplength)
Run the multiple-shooting rollout.
const MatrixXs & get_dHc() const
Return the Jacobian of the terminal constraint gains .
const std::vector< MatrixXs > & get_Quc() const
Return the Hessian of the Hamiltonian function .
std::vector< VectorXs > Luu_du_
Definition fddp.hpp:730
virtual void singleShootForwardPass(const Scalar steplength)
Run the classical nonlinear rollout.