10#ifndef CROCODDYL_CORE_SOLVER_BASE_HPP_ 11#define CROCODDYL_CORE_SOLVER_BASE_HPP_ 13#include "crocoddyl/core/fwd.hpp" 14#include "crocoddyl/core/optctrl/shooting.hpp" 15#include "crocoddyl/core/utils/stop-watch.hpp" 19template <
typename Scalar>
21 static const std::vector<Eigen::Matrix<Scalar, Eigen::Dynamic, 1>> value;
24template <
typename Scalar>
25const std::vector<Eigen::Matrix<Scalar, Eigen::Dynamic, 1>>
26 DefaultVector<Scalar>::value = {};
28#define DEFAULT_VECTOR DefaultVector<double>::value 30enum FeasibilityNorm { LInf = 0, L1 = 1, L2 = 2 };
75template <
typename _Scalar>
78 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
80 typedef _Scalar Scalar;
82 typedef typename ShootingProblem::ActionModelAbstract ActionModelAbstract;
83 typedef typename ShootingProblem::ActionDataAbstract ActionDataAbstract;
86 typedef typename MathBase::VectorXs VectorXs;
87 typedef typename MathBase::Vector3s Vector3s;
118 const std::vector<VectorXs>& init_xs = DefaultVector<Scalar>::value,
119 const std::vector<VectorXs>& init_us = DefaultVector<Scalar>::value,
120 const std::size_t maxiter = 100,
const bool is_feasible =
false,
121 const Scalar reg_init = std::numeric_limits<Scalar>::quiet_NaN());
158 virtual Scalar
tryStep(
const Scalar steplength = Scalar(1.));
257 const std::vector<VectorXs>& xs_warm = DefaultVector<Scalar>::value,
258 const std::vector<VectorXs>& us_warm = DefaultVector<Scalar>::value,
259 const bool is_feasible =
false);
388 const std::vector<std::shared_ptr<CallbackAbstract>>& callbacks);
393 const std::vector<std::shared_ptr<CallbackAbstract>>&
getCallbacks()
const;
408 const std::vector<VectorXs>&
get_xs()
const;
413 const std::vector<VectorXs>&
get_us()
const;
418 const std::vector<VectorXs>&
get_fs()
const;
545 "Use get_preg for primal-variable regularization",
546 Scalar get_xreg()
const {
return preg_; })
548 "Use get_preg for primal-variable regularization",
549 Scalar get_ureg()
const {
return preg_; })
580 "Do not use this threshold. It is not needed by our solvers",
581 Scalar get_th_gaptol()
const {
return th_gaptol_; })
587 FeasibilityNorm get_feasnorm()
const;
602 void set_xs(
const std::vector<VectorXs>& xs);
607 void set_us(
const std::vector<VectorXs>& us);
630 "Use set_preg for primal-variable regularization",
631 void set_xreg(
const Scalar xreg) {
632 if (xreg < Scalar(0.)) {
634 "Invalid argument: " <<
"xreg value has to be positive.");
640 "Use set_preg for primal-variable regularization",
641 void set_ureg(
const Scalar ureg) {
642 if (ureg < Scalar(0.)) {
644 "Invalid argument: " <<
"ureg value has to be positive.");
663 DEPRECATED(
"Do not use this threshold. It is not needed by our solvers",
664 void set_th_gaptol(
const Scalar th_gaptol);)
670 void set_feasnorm(
const FeasibilityNorm feas_norm);
699 std::vector<std::shared_ptr<CallbackAbstract>>
705 DEPRECATED(
"Do not use this threshold. It is not needed by our solvers",
707 enum FeasibilityNorm feasnorm_;
713 std::vector<VectorXs>
xs_;
714 std::vector<VectorXs>
us_;
715 std::vector<VectorXs>
fs_;
716 std::vector<VectorXs>
718 std::vector<VectorXs>
758 DEPRECATED(
"Use preg_ for primal-variable regularization",
760 DEPRECATED(
"Use dreg_ for primal-variable regularization",
792template <
typename _Scalar>
795 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
797 typedef _Scalar Scalar;
814template <
typename Scalar>
815bool raiseIfNaN(
const Scalar value);
822#include "crocoddyl/core/solver-base.hxx" 824CROCODDYL_DISABLE_WARNING_DEPRECATED
828CROCODDYL_ENABLE_WARNING_DEPRECATED
Abstract class for solver callbacks.
CallbackAbstractTpl()
Initialize the callback function.
virtual void operator()(SolverAbstract &solver)=0
Run the callback function given a solver.
This class encapsulates a shooting problem.
Abstract class for optimal control solvers.
Scalar get_dPhiexp() const
Return the expected reduction in the merit function .
Scalar get_hfeas_try() const
Return the equality feasibility for the current step length.
DEPRECATED("Do not use this threshold. It is not needed by our solvers", Scalar th_gaptol_;) enum FeasibilityNorm feasnorm_
virtual void resizeData()
Resizing the solver data.
virtual void updateMeritFunction()
Update the merit function value for the current guess.
virtual void computeCandidate(const Scalar steplength=Scalar(1.))
Compute new candidate solution using step length.
std::size_t get_iter() const
Return the number of iterations performed by the solver.
const std::vector< VectorXs > & get_dus() const
Return the feedforward gains .
void set_th_acceptstep(const Scalar th_acceptstep)
Modify the threshold used for accepting step.
Scalar get_ffeas_try() const
Return the dynamic feasibility for the current step length.
std::vector< VectorXs > dxs_
void set_dreg(const Scalar dreg)
Modify the dual-variable regularization value.
virtual Vector3s expectedImprovement()=0
Return the expected improvement from a given current search direction .
Scalar get_steplength() const
Return the step length .
std::vector< VectorXs > fs_
const std::vector< VectorXs > & get_us() const
Return the control trajectory .
Scalar computeDynamicFeasibility()
Compute the dynamic feasibility for the current guess .
virtual void computeMeritFunctionImprovement()
Compute the merit function improvement for the current step.
void set_us(const std::vector< VectorXs > &us)
Modify the control trajectory .
void set_xs(const std::vector< VectorXs > &xs)
Modify the state trajectory .
void set_preg(const Scalar preg)
Modify the primal-variable regularization value.
virtual bool decreaseRegularizationCriteria()
Criteria used to decrease regularization.
Scalar get_reg_max() const
Return the maximum regularization value.
Scalar get_dV() const
Return the reduction in the cost function .
virtual void computeExpectedMeritFunctionImprovement()
Compute the expected merit function improvement for the current step.
virtual void resizeRunningData()
Resize data associated with the running models of the shooting problem.
std::vector< VectorXs > us_try_
Scalar get_gfeas_try() const
Return the inequality feasibility for the current step length.
std::shared_ptr< ShootingProblem > problem_
Scalar get_dVexp() const
Return the expected reduction in the cost function .
void allocateData()
Allocate all the basic data needed in solvers.
Scalar get_stop() const
Return the stopping-criteria value computed by stoppingCriteria().
virtual bool checkAcceptance()
Check if we should accept or not the step.
Scalar get_cost() const
Return the cost for the current guess.
Scalar get_gfeas() const
Return the inequality feasibility for the current guess.
virtual void resizeTerminalData()
Resize data associated with the terminal model of the shooting problem.
std::vector< VectorXs > g_adj_
Scalar get_merit() const
Return the merit for the current guess.
const std::vector< std::shared_ptr< CallbackAbstract > > & getCallbacks() const
Return the list of callback functions using for diagnostic.
SolverAbstractTpl(std::shared_ptr< ShootingProblem > problem)
Initialize the solver.
Scalar get_preg() const
Return the primal-variable regularization.
const std::vector< VectorXs > & get_us_try() const
Return the trial control trajectory .
void set_reg_min(const Scalar regmin)
Modify the minimum regularization value.
void set_th_stop(const Scalar th_stop)
Modify the tolerance for stopping the algorithm.
const std::vector< Scalar > & get_alphas() const
Return the set of step lengths using by the line-search procedure.
virtual void computeDirection(const bool recalc)=0
Compute the search direction for the current guess .
std::vector< VectorXs > fs_try_
Scalar get_reg_min() const
Return the minimum regularization value.
Scalar computeControlFeasibility(const std::vector< VectorXs > &us)
Compute the control box-constraint feasibility from a given control trajectory.
Scalar get_ffeas() const
Return the dynamic feasibility for the current guess.
const std::vector< VectorXs > & get_fs_try() const
Return the trail dynamic infeasibility .
DEPRECATED("Do not use this threshold. It is not needed by our solvers", Scalar get_th_gaptol() const { return th_gaptol_;}) FeasibilityNorm get_feasnorm() const
Return the threshold for accepting a gap as non-zero.
std::vector< std::shared_ptr< CallbackAbstract > > callbacks_
Scalar get_th_acceptstep() const
Return the threshold used for accepting a step.
Scalar get_dfeas() const
Return the reduction in the feasibility.
virtual void decreaseRegularization()
Decrease the state and control regularization values by a regfactor_ factor.
Scalar get_dreg() const
Return the dual-variable regularization.
virtual void calcDir()
Refresh the linearization of the optimal control problem around the current candidate.
Scalar computeEqualityFeasibility()
Compute the feasibility of the equality constraints for the current guess.
std::vector< VectorXs > xs_
std::vector< VectorXs > us_
void setCallbacks(const std::vector< std::shared_ptr< CallbackAbstract > > &callbacks)
Set a list of callback functions using for the solver diagnostic.
std::vector< VectorXs > u_adj_
Scalar get_hfeas() const
Return the equality feasibility for the current guess.
const std::vector< VectorXs > & get_xs_try() const
Return the trial state trajectory .
Scalar computeInequalityFeasibility()
Compute the feasibility of the inequality constraints for the current guess.
Scalar get_dPhi() const
Return the reduction in the merit function .
std::vector< Scalar > alphas_
Scalar get_feas() const
Return the total feasibility for the current guess.
virtual bool increaseRegularizationCriteria()
Criteria used to increase regularization.
std::vector< VectorXs > dus_
const Vector3s & get_DV() const
Return the constant, linear, and quadratic terms of the expected improvement.
const std::vector< VectorXs > & get_xs() const
Return the state trajectory .
bool get_is_feasible() const
Return the feasibility status of the trajectory.
const std::vector< VectorXs > & get_fs() const
Return the dynamic infeasibility .
virtual void setCandidate(const std::vector< VectorXs > &xs_warm=DefaultVector< Scalar >::value, const std::vector< VectorXs > &us_warm=DefaultVector< Scalar >::value, const bool is_feasible=false)
Set the solver candidate trajectories .
virtual bool solve(const std::vector< VectorXs > &init_xs=DefaultVector< Scalar >::value, const std::vector< VectorXs > &init_us=DefaultVector< Scalar >::value, const std::size_t maxiter=100, const bool is_feasible=false, const Scalar reg_init=std::numeric_limits< Scalar >::quiet_NaN())
Compute the optimal trajectory as lists of and terms.
virtual void increaseRegularization()
Increase the state and control regularization values by a regfactor_ factor.
void set_reg_max(const Scalar regmax)
Modify the maximum regularization value.
virtual void updateCandidate()
Update the candidate solution: cost, feasibilities, and merit value.
Scalar computeStateFeasibility(const std::vector< VectorXs > &xs)
Compute the state box-constraint feasibility from a given state trajectory.
Scalar computeFeasibility(const std::vector< VectorXs > &fs)
Compute the feasibility from a given residual vector.
Scalar get_th_stop() const
Return the tolerance for stopping the algorithm.
DEPRECATED("Do not use this threshold. It is not needed by our solvers", void set_th_gaptol(const Scalar th_gaptol);) void set_feasnorm(const FeasibilityNorm feas_norm)
Modify the threshold for accepting a gap as non-zero.
const std::vector< VectorXs > & get_dxs() const
Return the linear update in .
const std::shared_ptr< ShootingProblem > & get_problem() const
Return the shooting problem.
void set_alphas(const std::vector< Scalar > &alphas)
Modify the set of step lengths using by the line-search procedure.
std::vector< VectorXs > x_adj_
std::vector< VectorXs > xs_try_
virtual Scalar tryStep(const Scalar steplength=Scalar(1.))
Try a predefined step length and compute its cost improvement and merit improvement .
virtual Scalar stoppingCriteria()=0
Return a positive value that quantifies the algorithm termination.