Crocoddyl
Loading...
Searching...
No Matches
odyn-sqp.hpp
1
2// BSD 3-Clause License
3//
4// Copyright (C) 2025-2026, Heriot-Watt University
5// Copyright note valid unless otherwise stated in individual files.
6// All rights reserved.
8
9#ifndef CROCODDYL_CORE_SOLVERS_ODYN_SQP_HPP_
10#define CROCODDYL_CORE_SOLVERS_ODYN_SQP_HPP_
11
12#include <odyn/data.hpp>
13#include <odyn/model.hpp>
14#include <odyn/params.hpp>
15#include <odyn/solver.hpp>
16
17#include "crocoddyl/core/solver-base.hpp"
18#include "crocoddyl/core/utils/deprecate.hpp"
19
20namespace crocoddyl {
21
37template <typename _Scalar>
38class SolverOdynSQPTpl : public SolverAbstractTpl<_Scalar> {
39 public:
40 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
41 CROCODDYL_DERIVED_FLOATINGPOINT_CAST(SolverBase, SolverOdynSQPTpl)
42
43 typedef _Scalar Scalar;
44 typedef SolverAbstractTpl<Scalar> SolverAbstract;
45 typedef ShootingProblemTpl<Scalar> ShootingProblem;
46 typedef typename ShootingProblem::ActionModelAbstract ActionModelAbstract;
47 typedef typename ShootingProblem::ActionDataAbstract ActionDataAbstract;
48 typedef CallbackAbstractTpl<Scalar> CallbackAbstract;
49 typedef MathBaseTpl<Scalar> MathBase;
50 typedef typename MathBase::VectorXs VectorXs;
51 typedef typename MathBase::Vector3s Vector3s;
52 typedef typename MathBase::MatrixXs MatrixXs;
53 typedef typename MathBase::MatrixXsRowMajor MatrixXsRowMajor;
54 using Solver = typename odyn::SparseQPTpl<Scalar>;
55 using Model = typename odyn::SparseModelTpl<Scalar>;
56 using Data = typename odyn::SparseDataTpl<Scalar>;
57 using Params = typename odyn::ParamsTpl<Scalar>;
63
71 explicit SolverOdynSQPTpl(std::shared_ptr<ShootingProblem> problem);
72 virtual ~SolverOdynSQPTpl() = default;
73
77 virtual void computeDirection(const bool recalc = true) override;
78
82 virtual Scalar stoppingCriteria() override;
83
87 virtual Vector3s expectedImprovement() override;
88
92 virtual void computeMeritFunctionImprovement() override;
93
98
102 virtual void updateMeritFunction() override;
103
109 virtual bool checkAcceptance() override;
110
114 virtual void computeCandidate(const Scalar step_length = Scalar(1.)) override;
115
143
147 void updateCandidate() override;
148
153
158
163 void increaseRegularization() override;
164
169 void decreaseRegularization() override;
170
176 void extractQpDirection(const VectorXs& x);
177
187 template <typename NewScalar>
189
193 Model& qp_model() noexcept;
194
198 Data& qp_data() noexcept;
199
203 std::size_t get_n() const noexcept;
204
208 std::size_t get_m() const noexcept;
209
213 std::size_t get_p() const noexcept;
214
218 Params& qp_params() noexcept;
219
223 odyn::VerboseLevel get_verbose_level() const noexcept;
224
228 Scalar get_reg_incfactor() const;
229
233 Scalar get_reg_decfactor() const;
234
239 Scalar get_th_grad() const;
240
244 Scalar get_th_stepdec() const;
245
249 Scalar get_th_stepinc() const;
250
255 Scalar get_th_minimprove() const;
256
260 Scalar get_th_acceptnegstep() const;
261
265 Scalar get_th_acceptminstep() const;
266
270 Scalar get_rho() const;
271
275 Scalar get_th_minfeas() const;
276
281 Scalar get_upsilon() const;
282
287 Scalar get_upsilon_decfactor() const;
288
295 bool get_zero_upsilon() const;
296
300 void set_qp_params(const Params& params);
301
305 void set_verbose_level(const odyn::VerboseLevel verbose_level);
306
310 void set_reg_incfactor(const Scalar reg_factor);
311
315 void set_reg_decfactor(const Scalar reg_factor);
316
321 void set_th_grad(const Scalar th_grad);
322
327 void set_th_noimprovement(const Scalar th_noimprovement);
328
332 void set_th_stepdec(const Scalar th_step);
333
337 void set_th_stepinc(const Scalar th_step);
338
343 void set_th_minimprove(const Scalar th_step);
344
348 void set_th_acceptnegstep(const Scalar th_acceptnegstep);
349
353 void set_th_acceptminstep(const Scalar th_acceptminstep);
354
358 void set_rho(const Scalar rho);
359
363 void set_th_minfeas(const Scalar th_minfeas);
364
369 void set_upsilon_decfactor(const Scalar th_step);
370
377 void set_zero_upsilon(const bool zero_upsilon);
378
379 protected:
384
388 virtual void resizeRunningData() override;
389
393 virtual void resizeTerminalData() override;
394
395 void updateStateAndControlIndex();
396
401 Scalar th_grad_;
405 Scalar
407 Scalar
415 Scalar rho_;
418 Scalar
425
426 std::size_t n_;
427 std::size_t m_;
428 std::size_t p_;
429 VectorXs x_;
430 Solver qp_solver_;
431 Model qp_model_;
432 Data qp_data_;
433 Params qp_params_;
434 odyn::VerboseLevel verbose_level_;
435 std::vector<std::size_t> xs_idx_;
436 std::vector<std::size_t> us_idx_;
437 std::vector<VectorXs>
440 std::vector<VectorXs>
443 std::vector<VectorXs>
446
447 using SolverAbstract::acceptstep_;
448 using SolverAbstract::alphas_;
449 using SolverAbstract::callbacks_;
450 using SolverAbstract::cost_;
451 using SolverAbstract::cost_try_;
452 using SolverAbstract::dfeas_;
453 using SolverAbstract::dImpr_;
454 using SolverAbstract::dPhi_;
455 using SolverAbstract::dPhiexp_;
456 using SolverAbstract::dreg_;
457 using SolverAbstract::dus_;
458 using SolverAbstract::DV_;
459 using SolverAbstract::dV_;
460 using SolverAbstract::dVexp_;
461 using SolverAbstract::dVexp_full_;
462 using SolverAbstract::dxs_;
463 using SolverAbstract::feas_;
464 using SolverAbstract::feasnorm_;
465 using SolverAbstract::ffeas_;
466 using SolverAbstract::ffeas_try_;
467 using SolverAbstract::fs_;
468 using SolverAbstract::fs_try_;
469 using SolverAbstract::gfeas_;
470 using SolverAbstract::gfeas_try_;
471 using SolverAbstract::hfeas_;
472 using SolverAbstract::hfeas_try_;
473 using SolverAbstract::is_feasible_;
474 using SolverAbstract::iter_;
475 using SolverAbstract::merit_;
476 using SolverAbstract::ng_T_;
477 using SolverAbstract::nh_T_;
478 using SolverAbstract::preg_;
479 using SolverAbstract::problem_;
480 using SolverAbstract::reg_max_;
481 using SolverAbstract::reg_min_;
482 using SolverAbstract::steplength_;
483 using SolverAbstract::stop_;
484 using SolverAbstract::th_acceptstep_;
485 using SolverAbstract::th_gaptol_;
486 using SolverAbstract::th_stop_;
487 using SolverAbstract::us_;
488 using SolverAbstract::us_try_;
489 using SolverAbstract::xs_;
490 using SolverAbstract::xs_try_;
491};
492
493} // namespace crocoddyl
494
495/* --- Details -------------------------------------------------------------- */
496/* --- Details -------------------------------------------------------------- */
497/* --- Details -------------------------------------------------------------- */
498#include "crocoddyl/core/solvers/odyn-sqp.hxx"
499
500CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS(crocoddyl::SolverOdynSQPTpl)
501
502#endif // CROCODDYL_CORE_SOLVERS_ODYN_SQP_HPP_
Abstract class for solver callbacks.
This class encapsulates a shooting problem.
Definition shooting.hpp:32
SolverAbstractTpl(std::shared_ptr< ShootingProblem > problem)
Initialize the solver.
Scalar computeFeasibility(const std::vector< VectorXs > &fs)
Odyn-based Sequential Quadratic Programming (SQP) solver.
Definition odyn-sqp.hpp:38
Scalar get_reg_incfactor() const
Return the regularization factor used to increase the damping value.
Scalar dV_
Reduction in the cost function computed by tryStep().
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.
void set_th_stepdec(const Scalar th_step)
Modify the step-length threshold used to decrease regularization.
void extractQpDirection(const VectorXs &x)
Extract the QP direction into the solver data structures.
virtual void computeDirection(const bool recalc=true) override
Compute the search direction for the current guess .
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.
std::vector< VectorXs > dxs_
Linear state direction (size T + 1).
void set_th_stepinc(const Scalar th_step)
Modify the step-length threshold used to increase regularization.
void set_th_acceptminstep(const Scalar th_acceptminstep)
Modify the threshold used for accepting minimum steps.
std::vector< VectorXs > fs_
Dynamics gaps in each node.
odyn::VerboseLevel get_verbose_level() const noexcept
Return the verbose level used in the OdynSQP solver.
virtual void computeCandidate(const Scalar step_length=Scalar(1.)) override
Compute new candidate solution using step length.
void set_th_minfeas(const Scalar th_minfeas)
Modify the threshold for switching to feasibility.
Scalar ffeas_
Feasibility of the dynamic constraints for the current guess.
std::size_t get_n() const noexcept
Return the number of decision variables in the SQP.
Scalar get_th_stepdec() const
Return the step-length threshold used to decrease regularization.
std::vector< VectorXs > Lxx_dx_
Definition odyn-sqp.hpp:438
Scalar get_th_acceptminstep() const
Return the threshold used for accepting minimum steps.
Scalar stop_
Value computed by stoppingCriteria().
std::vector< VectorXs > us_try_
Control trajectory computed by line-search procedure.
bool is_feasible_
Label that indicates is the iteration is feasible.
std::shared_ptr< ShootingProblem > problem_
optimal control problem
Vector3s DV_
LQ approximation of the expected improvement.
void allocateData()
Allocate all the internal data needed for the solver.
Scalar dreg_
Current dual-variable regularization value.
Scalar get_upsilon() const
Return the estimated penalty parameter that balances relative contribution of the cost function and e...
Scalar preg_
Current primal-variable regularization value.
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...
Scalar dPhi_
Reduction in the merit function computed by tryStep().
void set_reg_decfactor(const Scalar reg_factor)
Modify the regularization factor used to decrease the damping value.
std::size_t get_m() const noexcept
Return the number of equality constraints in the SQP.
std::size_t nh_T_
Dimension of terminal equality constraints.
Scalar th_stepinc_
Step-length threshold used to increase regularization.
Definition odyn-sqp.hpp:408
std::vector< VectorXs > fs_try_
bool increaseRegularizationCriteria() override
Criteria used to increase regularization.
virtual void computeMeritFunctionImprovement() override
Compute the merit function improvement for the current step.
Scalar steplength_
Current applied step length.
void set_upsilon_decfactor(const Scalar th_step)
Modify the upsilon decresing factor used to estimate to balance optimality and feasibility.
void set_th_minimprove(const Scalar th_step)
Modify the minimum improvement threshold used to increase regularization.
Scalar th_stepdec_
Step-length threshold used to decrease regularization.
Definition odyn-sqp.hpp:406
void set_rho(const Scalar rho)
Modify the rho parameter used in the merit function.
std::size_t get_p() const noexcept
Return the number of inequality constraints in the SQP.
std::vector< std::shared_ptr< CallbackAbstract > > callbacks_
Callback functions.
Params & qp_params() noexcept
Return the QP params used in the OdynSQP solver.
Scalar get_upsilon_decfactor() const
Return the upsilon decresing factor used to estimate to balance optimality and feasibility.
Scalar th_acceptstep_
Threshold used for accepting step.
void set_verbose_level(const odyn::VerboseLevel verbose_level)
Modify the verbose level used in the OdynSQP solver.
std::vector< VectorXs > xs_
State trajectory.
void computeQuadraticModel()
Build the local Quadratic Program (QP) for the current iterate.
std::vector< VectorXs > us_
Control trajectory.
void set_zero_upsilon(const bool zero_upsilon)
Modify the zero-upsilon label.
std::size_t iter_
Number of iteration performed by the solver.
std::vector< VectorXs > Lxu_du_
Definition odyn-sqp.hpp:444
Scalar get_th_stepinc() const
Return the step-length threshold used to increase regularization.
SolverOdynSQPTpl< NewScalar > cast() const
Cast the OdynSQP solver to a different scalar type.
bool decreaseRegularizationCriteria() override
Criteria used to decrease regularization.
void set_th_acceptnegstep(const Scalar th_acceptnegstep)
Modify the threshold used for accepting step along ascent direction.
Scalar feas_
Total feasibility for the current guess.
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.
std::vector< Scalar > alphas_
Set of step lengths using by the line-search procedure.
Data & qp_data() noexcept
Return the QP data used in the OdynSQP solver.
Scalar reg_min_
< Current control regularization values
Scalar cost_
Cost for the current guess.
std::vector< VectorXs > dus_
Linear control direction (size T).
bool get_zero_upsilon() const
Return the zero-upsilon label.
Scalar merit_
Merit for the current guess.
void set_qp_params(const Params &params)
Modify the QP params used in the OdynSQP solver.
Scalar dfeas_
Reduction in the feasibility.
std::size_t ng_T_
Dimension of termianl inequality constraints.
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.
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.
virtual bool checkAcceptance() override
Check if we should accept or not the step.
SolverOdynSQPTpl(std::shared_ptr< ShootingProblem > problem)
Initialize the OdynSQP solver.
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.
Scalar th_minfeas_
Threshold for switching to feasibility.
Definition odyn-sqp.hpp:417
Model & qp_model() noexcept
Return the QP model used in the OdynSQP solver.
Scalar get_reg_decfactor() const
Return the regularization factor used to decrease the damping value.
std::vector< VectorXs > xs_try_
State trajectory computed by line-search procedure.
std::vector< VectorXs > Luu_du_
Definition odyn-sqp.hpp:441
Scalar th_stop_
Tolerance for stopping the algorithm.
Scalar cost_try_
Total cost computed by line-search procedure.
Scalar reg_max_
Maximum allowed regularization value.