10 #ifndef CROCODDYL_CORE_SOLVER_BASE_HPP_
11 #define CROCODDYL_CORE_SOLVER_BASE_HPP_
15 #include "crocoddyl/core/optctrl/shooting.hpp"
16 #include "crocoddyl/core/utils/stop-watch.hpp"
20 class CallbackAbstract;
21 static std::vector<Eigen::VectorXd> DEFAULT_VECTOR;
23 enum FeasibilityNorm { LInf = 0, L1 };
63 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
70 explicit SolverAbstract(boost::shared_ptr<ShootingProblem> problem);
94 const std::vector<Eigen::VectorXd>& init_xs = DEFAULT_VECTOR,
95 const std::vector<Eigen::VectorXd>& init_us = DEFAULT_VECTOR,
96 const std::size_t maxiter = 100,
const bool is_feasible =
false,
97 const double reg_init = NAN) = 0;
129 virtual double tryStep(
const double steplength = 1) = 0;
211 const std::vector<Eigen::VectorXd>& xs_warm = DEFAULT_VECTOR,
212 const std::vector<Eigen::VectorXd>& us_warm = DEFAULT_VECTOR,
213 const bool is_feasible =
false);
224 const std::vector<boost::shared_ptr<CallbackAbstract> >& callbacks);
229 const std::vector<boost::shared_ptr<CallbackAbstract> >&
getCallbacks()
const;
234 const boost::shared_ptr<ShootingProblem>&
get_problem()
const;
239 const std::vector<Eigen::VectorXd>&
get_xs()
const;
244 const std::vector<Eigen::VectorXd>&
get_us()
const;
249 const std::vector<Eigen::VectorXd>&
get_fs()
const;
275 const Eigen::Vector2d&
get_d()
const;
349 DEPRECATED(
"Use get_preg for primal-variable regularization",
350 double get_xreg()
const;)
351 DEPRECATED(
"Use get_preg for primal-variable regularization",
352 double get_ureg()
const;)
388 void set_xs(
const std::vector<Eigen::VectorXd>& xs);
393 void set_us(
const std::vector<Eigen::VectorXd>& us);
405 DEPRECATED(
"Use set_preg for primal-variable regularization",
406 void set_xreg(
const double xreg);)
407 DEPRECATED(
"Use set_preg for primal-variable regularization",
408 void set_ureg(
const double ureg);)
433 std::vector<Eigen::VectorXd>
xs_;
434 std::vector<Eigen::VectorXd>
us_;
435 std::vector<Eigen::VectorXd>
fs_;
436 std::vector<boost::shared_ptr<CallbackAbstract> >
465 DEPRECATED(
"Use preg_ for primal-variable regularization",
467 DEPRECATED(
"Use dreg_ for primal-variable regularization",
502 bool raiseIfNaN(
const double value);
Abstract class for solver callbacks.
CallbackAbstract()
Initialize the callback function.
virtual void operator()(SolverAbstract &solver)=0
Run the callback function given a solver.
Abstract class for optimal control solvers.
double get_cost() const
Return the cost for the current guess.
double get_dPhi() const
Return the reduction in the merit function .
double get_th_gaptol() const
Return the threshold for accepting a gap as non-zero.
double dVexp_
Expected reduction in the cost function.
std::vector< Eigen::VectorXd > xs_
State trajectory.
std::size_t get_iter() const
Return the number of iterations performed by the solver.
double get_hfeas() const
Return the equality feasibility for the current guess.
void set_th_stop(const double th_stop)
Modify the tolerance for stopping the algorithm.
double stop_
Value computed by stoppingCriteria()
boost::shared_ptr< ShootingProblem > problem_
optimal control problem
const std::vector< boost::shared_ptr< CallbackAbstract > > & getCallbacks() const
Return the list of callback functions using for diagnostic.
void set_xs(const std::vector< Eigen::VectorXd > &xs)
Modify the state trajectory .
double get_dVexp() const
Return the expected reduction in the cost function .
double dreg_
Current dual-variable regularization value.
double feas_
Total feasibility for the current guess.
bool is_feasible_
Label that indicates is the iteration is feasible.
std::vector< Eigen::VectorXd > us_
Control trajectory.
double get_dPhiexp() const
Return the expected reduction in the merit function .
double th_acceptstep_
Threshold used for accepting step.
double get_steplength() const
Return the step length .
virtual const Eigen::Vector2d & expectedImprovement()=0
Return the expected improvement from a given current search direction .
void set_th_gaptol(const double th_gaptol)
Modify the threshold for accepting a gap as non-zero.
double get_merit() const
Return the merit for the current guess.
double dPhi_
Reduction in the merit function computed by tryStep()
double computeInequalityFeasibility()
Compute the feasibility of the inequality constraints for the current guess.
double get_preg() const
Return the primal-variable regularization.
double get_hfeas_try() const
Return the equality feasibility for the current step length.
double th_stop_
Tolerance for stopping the algorithm.
double computeDynamicFeasibility()
Compute the dynamic feasibility for the current guess .
virtual void computeDirection(const bool recalc)=0
Compute the search direction for the current guess .
const Eigen::Vector2d & get_d() const
Return the linear and quadratic terms of the expected improvement.
double dPhiexp_
Expected reduction in the merit function.
enum FeasibilityNorm feasnorm_
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 .
double get_th_stop() const
Return the tolerance for stopping the algorithm.
double dfeas_
Reduction in the feasibility.
void set_feasnorm(const FeasibilityNorm feas_norm)
Modify the current norm used for computed the dynamic and constraint feasibility.
double get_ffeas() const
Return the dynamic feasibility for the current guess.
double get_gfeas() const
Return the inequality feasibility for the current guess.
double cost_
Cost for the current guess.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW SolverAbstract(boost::shared_ptr< ShootingProblem > problem)
Initialize the solver.
void setCallbacks(const std::vector< boost::shared_ptr< CallbackAbstract > > &callbacks)
Set a list of callback functions using for the solver diagnostic.
virtual double tryStep(const double steplength=1)=0
Try a predefined step length and compute its cost improvement .
void set_us(const std::vector< Eigen::VectorXd > &us)
Modify the control trajectory .
double steplength_
< Current control regularization values
double th_gaptol_
Threshold limit to check non-zero gaps.
std::size_t iter_
Number of iteration performed by the solver.
double get_feas() const
Return the total feasibility for the current guess.
const boost::shared_ptr< ShootingProblem > & get_problem() const
Return the shooting problem.
double dV_
Reduction in the cost function computed by tryStep()
double get_stop() const
Return the stopping-criteria value computed by stoppingCriteria()
double get_ffeas_try() const
Return the dynamic feasibility for the current step length.
void set_dreg(const double dreg)
Modify the dual-variable regularization value.
Eigen::Vector2d d_
LQ approximation of the expected improvement.
double get_dV() const
Return the reduction in the cost function .
const std::vector< Eigen::VectorXd > & get_fs() const
Return the dynamic infeasibility .
const std::vector< Eigen::VectorXd > & get_xs() const
Return the state trajectory .
double get_dfeas() const
Return the reduction in the feasibility.
void set_preg(const double preg)
Modify the primal-variable regularization value.
double ffeas_
Feasibility of the dynamic constraints for the current guess.
double get_gfeas_try() const
Return the inequality feasibility for the current step length.
bool get_is_feasible() const
Return the feasibility status of the trajectory.
double preg_
Current primal-variable regularization value.
const std::vector< Eigen::VectorXd > & get_us() const
Return the control trajectory .
double merit_
Merit for the current guess.
virtual void resizeData()
Resizing the solver data.
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=NAN)=0
Compute the optimal trajectory as lists of and terms.
std::vector< Eigen::VectorXd > fs_
Gaps/defects between shooting nodes.
virtual double stoppingCriteria()=0
Return a positive value that quantifies the algorithm termination.
void set_th_acceptstep(const double th_acceptstep)
Modify the threshold used for accepting step.
double tmp_feas_
Temporal variables used for computed the feasibility.
double get_th_acceptstep() const
Return the threshold used for accepting a step.
FeasibilityNorm get_feasnorm() const
Return the type of norm used to evaluate the dynamic and constraints feasibility.
double get_dreg() const
Return the dual-variable regularization.
std::vector< boost::shared_ptr< CallbackAbstract > > callbacks_
Callback functions.
double computeEqualityFeasibility()
Compute the feasibility of the equality constraints for the current guess.