crocoddyl 1.9.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
 
Loading...
Searching...
No Matches
solver-base.hpp
1
2// BSD 3-Clause License
3//
4// Copyright (C) 2019-2021, 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#include "crocoddyl/core/utils/stop-watch.hpp"
16
17namespace crocoddyl {
18
19class CallbackAbstract; // forward declaration
20static std::vector<Eigen::VectorXd> DEFAULT_VECTOR;
21
52 public:
53 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
54
60 explicit SolverAbstract(boost::shared_ptr<ShootingProblem> problem);
61 virtual ~SolverAbstract();
62
79 virtual bool solve(const std::vector<Eigen::VectorXd>& init_xs = DEFAULT_VECTOR,
80 const std::vector<Eigen::VectorXd>& init_us = DEFAULT_VECTOR, const std::size_t maxiter = 100,
81 const bool is_feasible = false, const double reg_init = 1e-9) = 0;
82
94 virtual void computeDirection(const bool recalc) = 0;
95
106 virtual double tryStep(const double steplength = 1) = 0;
107
115 virtual double stoppingCriteria() = 0;
116
123 virtual const Eigen::Vector2d& expectedImprovement() = 0;
124
131 virtual void resizeData();
132
143
156 void setCandidate(const std::vector<Eigen::VectorXd>& xs_warm = DEFAULT_VECTOR,
157 const std::vector<Eigen::VectorXd>& us_warm = DEFAULT_VECTOR, const bool is_feasible = false);
158
167 void setCallbacks(const std::vector<boost::shared_ptr<CallbackAbstract> >& callbacks);
168
172 const std::vector<boost::shared_ptr<CallbackAbstract> >& getCallbacks() const;
173
177 const boost::shared_ptr<ShootingProblem>& get_problem() const;
178
182 const std::vector<Eigen::VectorXd>& get_xs() const;
183
187 const std::vector<Eigen::VectorXd>& get_us() const;
188
192 const std::vector<Eigen::VectorXd>& get_fs() const;
193
197 bool get_is_feasible() const;
198
202 double get_cost() const;
203
207 double get_stop() const;
208
212 const Eigen::Vector2d& get_d() const;
213
217 double get_xreg() const;
218
222 double get_ureg() const;
223
227 double get_steplength() const;
228
232 double get_dV() const;
233
237 double get_dVexp() const;
238
242 double get_th_acceptstep() const;
243
247 double get_th_stop() const;
248
252 std::size_t get_iter() const;
253
257 double get_th_gaptol() const;
258
263 double get_ffeas() const;
264
268 bool get_inffeas() const;
269
273 void set_xs(const std::vector<Eigen::VectorXd>& xs);
274
278 void set_us(const std::vector<Eigen::VectorXd>& us);
279
283 void set_xreg(const double xreg);
284
288 void set_ureg(const double ureg);
289
293 void set_th_acceptstep(const double th_acceptstep);
294
298 void set_th_stop(const double th_stop);
299
303 void set_th_gaptol(const double th_gaptol);
304
308 void set_inffeas(const bool inffeas);
309
310 protected:
311 boost::shared_ptr<ShootingProblem> problem_;
312 std::vector<Eigen::VectorXd> xs_;
313 std::vector<Eigen::VectorXd> us_;
314 std::vector<Eigen::VectorXd> fs_;
315 std::vector<boost::shared_ptr<CallbackAbstract> > callbacks_;
318 double cost_;
319 double stop_;
320 Eigen::Vector2d d_;
321 double xreg_;
322 double ureg_;
323 double steplength_;
324 double dV_;
325 double dVexp_;
327 double th_stop_;
328 std::size_t iter_;
329 double th_gaptol_;
330 double ffeas_;
331 bool inffeas_;
333 double tmp_feas_;
334};
335
343 public:
348 virtual ~CallbackAbstract() {}
349
355 virtual void operator()(SolverAbstract& solver) = 0;
356};
357
358bool raiseIfNaN(const double value);
359
360} // namespace crocoddyl
361
362#endif // CROCODDYL_CORE_SOLVER_BASE_HPP_
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.
Definition: solver-base.hpp:51
double get_cost() const
Return the total cost.
double get_th_gaptol() const
Return the threshold for accepting a gap as non-zero.
double get_xreg() const
Return the state regularization value.
bool was_feasible_
Label that indicates in the previous iterate was feasible.
double dVexp_
Expected cost reduction.
std::vector< Eigen::VectorXd > xs_
State trajectory.
void set_inffeas(const bool inffeas)
Modify the current norm used for computed the feasibility.
std::size_t get_iter() const
Return the number of iterations performed by the solver.
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
void set_ureg(const double ureg)
Modify the control regularization value.
const std::vector< boost::shared_ptr< CallbackAbstract > > & getCallbacks() const
Return the list of callback functions using for diagnostic.
void set_xreg(const double xreg)
Modify the state regularization value.
void set_xs(const std::vector< Eigen::VectorXd > &xs)
Modify the state trajectory .
double get_dVexp() const
Return the expected cost reduction .
bool is_feasible_
Label that indicates is the iteration is feasible.
std::vector< Eigen::VectorXd > us_
Control trajectory.
double th_acceptstep_
Threshold used for accepting step.
double get_steplength() const
Return the step length .
void set_th_gaptol(const double th_gaptol)
Modify the threshold for accepting a gap as non-zero.
virtual const Eigen::Vector2d & expectedImprovement()=0
Return the expected improvement from a given current search direction .
double th_stop_
Tolerance for stopping the algorithm.
double computeDynamicFeasibility()
Compute the dynamic feasibility for the current guess .
Definition: solver-base.cpp:66
virtual void computeDirection(const bool recalc)=0
Compute the search direction for the current guess .
const Eigen::Vector2d & get_d() const
Return the LQ approximation of the expected improvement.
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 get_ffeas() const
Return the feasibility of the dynamic constraints of the current guess.
double cost_
Total cost.
double xreg_
Current state regularization value.
void setCallbacks(const std::vector< boost::shared_ptr< CallbackAbstract > > &callbacks)
Set a list of callback functions using for the solver diagnostic.
double ureg_
Current control regularization values.
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 applied step-length.
double th_gaptol_
Threshold limit to check non-zero gaps.
std::size_t iter_
Number of iteration performed by the solver.
double get_ureg() const
Return the control regularization value.
const boost::shared_ptr< ShootingProblem > & get_problem() const
Return the shooting problem.
double dV_
Cost reduction obtained by tryStep()
double get_stop() const
Return the value computed by stoppingCriteria()
Eigen::Vector2d d_
LQ approximation of the expected improvement.
double get_dV() const
Return the cost reduction .
const std::vector< Eigen::VectorXd > & get_fs() const
Return the gaps .
const std::vector< Eigen::VectorXd > & get_xs() const
Return the state trajectory .
bool get_inffeas() const
Return the norm used for the computing the feasibility (true for , false for )
double ffeas_
Feasibility of the dynamic constraints.
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.
bool get_is_feasible() const
Return the feasibility status of the trajectory.
const std::vector< Eigen::VectorXd > & get_us() const
Return the control trajectory .
virtual void resizeData()
Resizing the solver data.
Definition: solver-base.cpp:56
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.
std::vector< boost::shared_ptr< CallbackAbstract > > callbacks_
Callback functions.