Template Class SolverKKTTpl
Defined in File kkt.hpp
Inheritance Relationships
Base Type
public crocoddyl::SolverAbstractTpl< _Scalar >(Template Class SolverAbstractTpl)
Class Documentation
-
template<typename _Scalar>
class SolverKKTTpl : public crocoddyl::SolverAbstractTpl<_Scalar> Public Types
-
typedef SolverAbstractTpl<Scalar> SolverAbstract
-
typedef ShootingProblemTpl<Scalar> ShootingProblem
-
typedef ShootingProblem::ActionModelAbstract ActionModelAbstract
-
typedef ShootingProblem::ActionDataAbstract ActionDataAbstract
-
typedef CallbackAbstractTpl<Scalar> CallbackAbstract
-
typedef MathBaseTpl<Scalar> MathBase
Public Functions
-
virtual ~SolverKKTTpl() = default
-
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 regInit = 1e-9) override
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 overcomputeDirection()andtryStep()untilstoppingCriteria()is below threshold. It also describes the globalization strategy used during the numerical optimization.- Parameters:
init_xs – [in] initial guess for state trajectory with \(T+1\) elements (default [])
init_us – [in] initial guess for control trajectory with \(T\) elements (default [])
maxiter – [in] maximum allowed number of iterations (default 100)
is_feasible – [in] true if the
init_xsare obtained from integrating theinit_us(rollout) (default false)init_reg – [in] initial guess for the regularization value. Very low values are typical used with very good guess points (default 1e-9).
- Returns:
A boolean that describes if convergence was reached.
-
virtual void computeDirection(const bool recalc = true) override
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. Whenrecalcis true (the default in the provided algorithms), the method refreshes the linearization by callingcalcDir()before running the backward pass. Settingrecalcto false reuses the most recent derivatives, which is useful whencalcDir()has already been triggered explicitly. The resulting state and control variations, together with the dynamics multipliers, are stored in the solver data structures (e.g.,dxs_,dus_, andlambdas_).- Parameters:
recalc – [in] true to refresh the derivatives before computing the search direction
-
virtual Scalar tryStep(const Scalar steplength = Scalar(1.)) override
Try a predefined step length \(\alpha\) and compute its cost improvement \(dV\) and merit improvement \(d\Phi\).
It uses the search direction found by
computeDirection()to try a determined step length \(\alpha\). Therefore, it assumes that we have runcomputeDirection()first. Additionally, it returns the cost improvement \(dV\) along the predefined step length \(\alpha\). Internally, it updates the cost improvement \(dV\) and merit improvement \(d\Phi\).- Parameters:
steplength – [in] applied step length ( \(0\leq\alpha\leq1\), with 1 as default)
- Returns:
the cost improvement
-
virtual Scalar stoppingCriteria() override
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 bytryStep().
-
virtual Vector3s expectedImprovement() override
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(). The quadratic improvement model is described as dV = DV_0 + DV_1 + 0.5 * DV_2, where DV_0, DV_1, and DV_2 are the constant, linear, and quadratic terms, respectively.
-
template<typename NewScalar>
SolverKKTTpl<NewScalar> cast() const Cast the KKT solver to a different scalar type.
It is useful for operations requiring different precision or scalar types.
- Template Parameters:
NewScalar – The new scalar type to cast to.
- Returns:
SolverKKTTpl<NewScalar> A KKT solver with the new scalar type.
-
std::size_t get_nx() const
-
std::size_t get_ndx() const
-
std::size_t get_nu() const
-
void set_alphas(const std::vector<Scalar> &alphas)
Modify the set of step lengths using by the line-search procedure.
-
void set_reg_incfactor(const Scalar reg_factor)
Modify the regularization factor used to increase the damping value.
-
void set_reg_decfactor(const Scalar reg_factor)
Modify the regularization factor used to decrease the damping value.
-
void set_th_grad(const Scalar th_grad)
Modify the tolerance of the expected gradient used for testing the step.
-
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 \((\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. Updating the candidate invalidates any previously computed linearization; the next call to
computeDirection()will therefore refresh the derivatives on demand.- Parameters:
xs – [in] state trajectory of \(T+1\) elements (default [])
us – [in] control trajectory of \(T\) elements (default [])
isFeasible – [in] true if the
xsare obtained from integrating theus(rollout)
Public Members
- EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar
Protected Functions
-
void allocateData()
Protected Attributes
-
bool was_feasible_
-
std::vector<std::shared_ptr<CallbackAbstract>> callbacks_
Callback functions.
-
bool is_feasible_
Label that indicates is the iteration is feasible.
-
std::size_t iter_
Number of iteration performed by the solver.
-
std::shared_ptr<ShootingProblem> problem_
optimal control problem
-
Scalar stop_
Value computed by
stoppingCriteria().
-
typedef SolverAbstractTpl<Scalar> SolverAbstract