crocoddyl  1.8.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
solver-base.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-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 
51  public:
52  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
53 
59  explicit SolverAbstract(boost::shared_ptr<ShootingProblem> problem);
60  virtual ~SolverAbstract();
61 
78  virtual bool solve(const std::vector<Eigen::VectorXd>& init_xs = DEFAULT_VECTOR,
79  const std::vector<Eigen::VectorXd>& init_us = DEFAULT_VECTOR, const std::size_t maxiter = 100,
80  const bool is_feasible = false, const double reg_init = 1e-9) = 0;
81 
93  virtual void computeDirection(const bool recalc) = 0;
94 
105  virtual double tryStep(const double step_length = 1) = 0;
106 
115  virtual double stoppingCriteria() = 0;
116 
123  virtual const Eigen::Vector2d& expectedImprovement() = 0;
124 
136  void setCandidate(const std::vector<Eigen::VectorXd>& xs_warm = DEFAULT_VECTOR,
137  const std::vector<Eigen::VectorXd>& us_warm = DEFAULT_VECTOR, const bool is_feasible = false);
138 
147  void setCallbacks(const std::vector<boost::shared_ptr<CallbackAbstract> >& callbacks);
148 
152  const std::vector<boost::shared_ptr<CallbackAbstract> >& getCallbacks() const;
153 
157  const boost::shared_ptr<ShootingProblem>& get_problem() const;
158 
162  const std::vector<Eigen::VectorXd>& get_xs() const;
163 
167  const std::vector<Eigen::VectorXd>& get_us() const;
168 
172  bool get_is_feasible() const;
173 
177  double get_cost() const;
178 
182  double get_stop() const;
183 
187  const Eigen::Vector2d& get_d() const;
188 
192  double get_xreg() const;
193 
197  double get_ureg() const;
198 
202  double get_steplength() const;
203 
207  double get_dV() const;
208 
212  double get_dVexp() const;
213 
217  double get_th_acceptstep() const;
218 
222  double get_th_stop() const;
223 
227  std::size_t get_iter() const;
228 
232  void set_xs(const std::vector<Eigen::VectorXd>& xs);
233 
237  void set_us(const std::vector<Eigen::VectorXd>& us);
238 
242  void set_xreg(const double xreg);
243 
247  void set_ureg(const double ureg);
248 
252  void set_th_acceptstep(const double th_acceptstep);
253 
257  void set_th_stop(const double th_stop);
258 
259  protected:
260  boost::shared_ptr<ShootingProblem> problem_;
261  std::vector<Eigen::VectorXd> xs_;
262  std::vector<Eigen::VectorXd> us_;
263  std::vector<boost::shared_ptr<CallbackAbstract> > callbacks_;
265  double cost_;
266  double stop_;
267  Eigen::Vector2d d_;
268  double xreg_;
269  double ureg_;
270  double steplength_;
271  double dV_;
272  double dVexp_;
273  double th_acceptstep_;
274  double th_stop_;
275  std::size_t iter_;
276 };
277 
285  public:
290  virtual ~CallbackAbstract() {}
291 
297  virtual void operator()(SolverAbstract& solver) = 0;
298 };
299 
300 bool raiseIfNaN(const double value);
301 
302 } // namespace crocoddyl
303 
304 #endif // CROCODDYL_CORE_SOLVER_BASE_HPP_
bool is_feasible_
Label that indicates is the iteration is feasible.
void set_ureg(const double ureg)
Modify the control regularization value.
double get_th_acceptstep() const
Return the threshold used for accepting a step.
const std::vector< Eigen::VectorXd > & get_us() const
Return the control trajectory .
const std::vector< Eigen::VectorXd > & get_xs() const
Return the state trajectory .
const boost::shared_ptr< ShootingProblem > & get_problem() const
Return the shooting problem.
Definition: solver-base.cpp:99
double ureg_
Current control regularization values.
double steplength_
Current applied step-length.
std::size_t get_iter() const
Return the number of iterations performed by the solver.
double get_stop() const
Return the value computed by stoppingCriteria()
void set_th_acceptstep(const double th_acceptstep)
Modify the threshold used for accepting step.
double get_th_stop() const
Return the tolerance for stopping the algorithm.
double get_dVexp() const
Return the expected cost reduction.
double get_xreg() const
Return the state regularization value.
void setCallbacks(const std::vector< boost::shared_ptr< CallbackAbstract > > &callbacks)
Set a list of callback functions using for diagnostic.
Definition: solver-base.cpp:93
double xreg_
Current state regularization value.
std::vector< boost::shared_ptr< CallbackAbstract > > callbacks_
Callback functions.
double get_cost() const
Return the total cost.
double th_acceptstep_
Threshold used for accepting step.
std::vector< Eigen::VectorXd > us_
Control trajectory.
Abstract class for optimal control solvers.
Definition: solver-base.hpp:50
double dV_
Cost reduction obtained by tryStep()
EIGEN_MAKE_ALIGNED_OPERATOR_NEW SolverAbstract(boost::shared_ptr< ShootingProblem > problem)
Initialize the solver.
Definition: solver-base.cpp:14
Eigen::Vector2d d_
LQ approximation of the expected improvement.
virtual double stoppingCriteria()=0
Return a positive value that quantifies the algorithm termination.
boost::shared_ptr< ShootingProblem > problem_
optimal control problem
double dVexp_
Expected cost reduction.
CallbackAbstract()
Initialize the callback function.
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=1e-9)=0
Compute the optimal trajectory as lists of and terms.
void set_th_stop(const double th_stop)
Modify the tolerance for stopping the algorithm.
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 warm-point values .
Definition: solver-base.cpp:42
std::vector< Eigen::VectorXd > xs_
State trajectory.
const std::vector< boost::shared_ptr< CallbackAbstract > > & getCallbacks() const
"Return the list of callback functions using for diagnostic
Definition: solver-base.cpp:97
double cost_
Total cost.
bool get_is_feasible() const
Return the feasibility status of the trajectory.
double th_stop_
Tolerance for stopping the algorithm.
double get_dV() const
Return the cost reduction.
void set_xs(const std::vector< Eigen::VectorXd > &xs)
Modify the state trajectory .
virtual void computeDirection(const bool recalc)=0
Compute the search direction for the current guess .
void set_us(const std::vector< Eigen::VectorXd > &us)
Modify the control trajectory .
virtual double tryStep(const double step_length=1)=0
Try a predefined step length and compute its cost improvement.
const Eigen::Vector2d & get_d() const
Return the LQ approximation of the expected improvement.
Abstract class for solver callbacks.
std::size_t iter_
Number of iteration performed by the solver.
double get_ureg() const
Return the control regularization value.
virtual const Eigen::Vector2d & expectedImprovement()=0
Return the expected improvement from a given current search direction.
double stop_
Value computed by stoppingCriteria()
void set_xreg(const double xreg)
Modify the state regularization value.
double get_steplength() const
Return the step length.