crocoddyl  1.3.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
solver-base.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2018-2020, LAAS-CNRS, University of Edinburgh
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
8 
9 #ifndef CROCODDYL_CORE_SOLVER_BASE_HPP_
10 #define CROCODDYL_CORE_SOLVER_BASE_HPP_
11 
12 #include <vector>
13 
14 #include "crocoddyl/core/optctrl/shooting.hpp"
15 
16 namespace crocoddyl {
17 
18 class CallbackAbstract; // forward declaration
19 static std::vector<Eigen::VectorXd> DEFAULT_VECTOR;
20 
22  public:
23  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
24 
25  explicit SolverAbstract(boost::shared_ptr<ShootingProblem> problem);
26  virtual ~SolverAbstract();
27 
28  virtual bool solve(const std::vector<Eigen::VectorXd>& init_xs = DEFAULT_VECTOR,
29  const std::vector<Eigen::VectorXd>& init_us = DEFAULT_VECTOR, const std::size_t& maxiter = 100,
30  const bool& is_feasible = false, const double& reg_init = 1e-9) = 0;
31  // TODO(cmastalli): computeDirection (polymorphism) returning descent direction and lambdas
32  virtual void computeDirection(const bool& recalc) = 0;
33  virtual double tryStep(const double& step_length = 1) = 0;
34  virtual double stoppingCriteria() = 0;
35  virtual const Eigen::Vector2d& expectedImprovement() = 0;
36  void setCandidate(const std::vector<Eigen::VectorXd>& xs_warm = DEFAULT_VECTOR,
37  const std::vector<Eigen::VectorXd>& us_warm = DEFAULT_VECTOR, const bool& is_feasible = false);
38 
39  void setCallbacks(const std::vector<boost::shared_ptr<CallbackAbstract> >& callbacks);
40  const std::vector<boost::shared_ptr<CallbackAbstract> >& getCallbacks() const;
41 
42  const boost::shared_ptr<ShootingProblem>& get_problem() const;
43  const std::vector<Eigen::VectorXd>& get_xs() const;
44  const std::vector<Eigen::VectorXd>& get_us() const;
45  const bool& get_is_feasible() const;
46  const double& get_cost() const;
47  const double& get_stop() const;
48  const Eigen::Vector2d& get_d() const;
49  const double& get_xreg() const;
50  const double& get_ureg() const;
51  const double& get_steplength() const;
52  const double& get_dV() const;
53  const double& get_dVexp() const;
54  const double& get_th_acceptstep() const;
55  const double& get_th_stop() const;
56  const std::size_t& get_iter() const;
57 
58  void set_xs(const std::vector<Eigen::VectorXd>& xs);
59  void set_us(const std::vector<Eigen::VectorXd>& us);
60  void set_xreg(const double& xreg);
61  void set_ureg(const double& ureg);
62  void set_th_acceptstep(const double& th_acceptstep);
63  void set_th_stop(const double& th_stop);
64 
65  protected:
66  boost::shared_ptr<ShootingProblem> problem_;
67  std::vector<Eigen::VectorXd> xs_;
68  std::vector<Eigen::VectorXd> us_;
69  std::vector<boost::shared_ptr<CallbackAbstract> > callbacks_;
70  bool is_feasible_;
71  double cost_;
72  double stop_;
73  Eigen::Vector2d d_;
74  double xreg_;
75  double ureg_;
76  double steplength_;
77  double dV_;
78  double dVexp_;
79  double th_acceptstep_;
80  double th_stop_;
81  std::size_t iter_;
82 };
83 
85  public:
86  CallbackAbstract() {}
87  virtual ~CallbackAbstract() {}
88 
89  virtual void operator()(SolverAbstract& solver) = 0;
90 };
91 
92 bool raiseIfNaN(const double& value);
93 
94 } // namespace crocoddyl
95 
96 #endif // CROCODDYL_CORE_SOLVER_BASE_HPP_
bool is_feasible_
Label that indicates is the iteration is feasible.
Definition: solver-base.hpp:70
double ureg_
Current control regularization values.
Definition: solver-base.hpp:75
double steplength_
Current applied step-length.
Definition: solver-base.hpp:76
double xreg_
Current state regularization value.
Definition: solver-base.hpp:74
std::vector< boost::shared_ptr< CallbackAbstract > > callbacks_
Callback functions.
Definition: solver-base.hpp:69
double th_acceptstep_
Threshold used for accepting step.
Definition: solver-base.hpp:79
std::vector< Eigen::VectorXd > us_
Control trajectory.
Definition: solver-base.hpp:68
double dV_
Cost reduction obtained by tryStep.
Definition: solver-base.hpp:77
Eigen::Vector2d d_
LQ approximation of the expected improvement.
Definition: solver-base.hpp:73
boost::shared_ptr< ShootingProblem > problem_
optimal control problem
Definition: solver-base.hpp:66
double dVexp_
Expected cost reduction.
Definition: solver-base.hpp:78
std::vector< Eigen::VectorXd > xs_
State trajectory.
Definition: solver-base.hpp:67
double cost_
Total cost.
Definition: solver-base.hpp:71
double th_stop_
Tolerance for stopping the algorithm.
Definition: solver-base.hpp:80
std::size_t iter_
Number of iteration performed by the solver.
Definition: solver-base.hpp:81
double stop_
Value computed by stoppingCriteria.
Definition: solver-base.hpp:72