feasibility_driven_ddp_solver.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019-2020, LAAS-CNRS, University of Edinburgh, University of Oxford
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without specific
15 // prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
30 #ifndef EXOTICA_DDP_SOLVER_FEASIBILITY_DRIVEN_DDP_SOLVER_H_
31 #define EXOTICA_DDP_SOLVER_FEASIBILITY_DRIVEN_DDP_SOLVER_H_
32 
34 #include <exotica_ddp_solver/feasibility_driven_ddp_solver_initializer.h>
35 
36 namespace exotica
37 {
38 // Feasibility-driven DDP solver
39 // Based on the implementation in Crocoddyl: https://github.com/loco-3d/crocoddyl.git
40 // Cf. https://arxiv.org/abs/1909.04947
42 {
43 public:
44  void Solve(Eigen::MatrixXd& solution) override;
45  void SpecifyProblem(PlanningProblemPtr pointer) override;
46 
47  const std::vector<Eigen::VectorXd>& get_fs() const { return fs_; };
48  const std::vector<Eigen::VectorXd>& get_xs() const { return xs_; };
49  const std::vector<Eigen::VectorXd>& get_us() const { return us_; };
50 
51 protected:
52  int NDX_;
53  int last_T_ = -1;
54 
55  void IncreaseRegularization() override;
56  void DecreaseRegularization() override;
57  const Eigen::Vector2d& ExpectedImprovement();
59  inline bool IsNaN(const double value)
60  {
61  if (std::isnan(value) || std::isinf(value) || value >= 1e30)
62  {
63  return true;
64  }
65  else
66  {
67  return false;
68  }
69  }
70  void SetCandidate(const std::vector<Eigen::VectorXd>& xs_warm, const std::vector<Eigen::VectorXd>& us_warm, const bool is_feasible);
71  double CheckStoppingCriteria();
72 
73  double CalcDiff();
74  bool ComputeDirection(const bool recalcDiff);
75  virtual bool BackwardPassFDDP();
76  void BackwardPass() override { return (void)BackwardPassFDDP(); }
77  virtual void ComputeGains(const int t);
78  void ForwardPass(const double steplength);
79  double TryStep(const double steplength);
80 
81  virtual void AllocateData();
82 
83  Eigen::MatrixXd control_limits_;
84  double initial_regularization_rate_ = 1e-9; // Set from parameters on Instantiate
85  bool clamp_to_control_limits_in_forward_pass_ = false; // Set from parameters on Instantiate
86 
87  double steplength_;
88  Eigen::Vector2d d_;
89  double dV_;
90  double dVexp_;
91  double th_acceptstep_ = 0.1;
92  double th_stop_ = 1e-9;
93  double th_gradient_tolerance_ = 0.;
94  double stop_;
95 
96  double dg_ = 0.;
97  double dq_ = 0.;
98  double dv_ = 0.;
99  double th_acceptnegstep_ = 2.;
100  std::vector<Eigen::VectorXd> us_;
101  std::vector<Eigen::VectorXd> xs_;
102  bool is_feasible_ = false;
103  double xreg_ = 1e-9;
104  double ureg_ = 1e-9;
105  double regmin_ = 1e-9;
106  double regmax_ = 1e9;
107  double regfactor_ = 10.;
108 
109  std::vector<Eigen::VectorXd> xs_try_;
110  std::vector<Eigen::VectorXd> us_try_;
111  std::vector<Eigen::VectorXd> dx_;
112 
113  // allocate data
114  std::vector<Eigen::VectorXd> fs_;
115 
116  Eigen::VectorXd xnext_;
117  Eigen::MatrixXd FxTVxx_p_;
118  std::vector<Eigen::MatrixXd> FuTVxx_p_;
119  std::vector<Eigen::MatrixXd> Qxu_;
120  Eigen::VectorXd fTVxx_p_;
121  std::vector<Eigen::LDLT<Eigen::MatrixXd> > Quu_ldlt_;
122  std::vector<Eigen::VectorXd> Quuk_;
123  double th_grad_ = 1e-12;
124  double th_stepdec_ = 0.5;
125  double th_stepinc_ = 0.01;
126  bool was_feasible_ = false;
127 };
128 
129 class FeasibilityDrivenDDPSolver : public AbstractFeasibilityDrivenDDPSolver, public Instantiable<FeasibilityDrivenDDPSolverInitializer>
130 {
131 public:
132  void Instantiate(const FeasibilityDrivenDDPSolverInitializer& init) override;
133 };
134 
135 } // namespace exotica
136 
137 #endif // EXOTICA_DDP_SOLVER_FEASIBILITY_DRIVEN_DDP_SOLVER_H_
const std::vector< Eigen::VectorXd > & get_fs() const
double stop_
Value computed by CheckStoppingCriteria.
std::vector< Eigen::VectorXd > xs_try_
State trajectory computed by line-search procedure.
double dV_
Cost reduction obtained by TryStep.
std::vector< Eigen::VectorXd > us_try_
Control trajectory computed by line-search procedure.
double regfactor_
Factor by which the regularization gets increased/decreased.
void SetCandidate(const std::vector< Eigen::VectorXd > &xs_warm, const std::vector< Eigen::VectorXd > &us_warm, const bool is_feasible)
const std::vector< Eigen::VectorXd > & get_us() const
Eigen::Vector2d d_
LQ approximation of the expected improvement.
double th_stepinc_
Step-length threshold used to increase regularization.
double th_acceptnegstep_
Threshold used for accepting step along ascent direction.
void SpecifyProblem(PlanningProblemPtr pointer) override
Binds the solver to a specific problem which must be pre-initalised.
double th_acceptstep_
Threshold used for accepting step.
std::vector< Eigen::VectorXd > fs_
Gaps/defects between shooting nodes.
bool was_feasible_
Label that indicates in the previous iterate was feasible.
double th_grad_
Tolerance of the expected gradient used for testing the step.
double th_stop_
Tolerance for stopping the algorithm.
double th_stepdec_
Step-length threshold used to decrease regularization.
void BackwardPass() override
Computes the control gains for a the trajectory in the associated DynamicTimeIndexedProblem.
double regmin_
Minimum regularization (will not decrease lower)
std::vector< Eigen::LDLT< Eigen::MatrixXd > > Quu_ldlt_
std::shared_ptr< PlanningProblem > PlanningProblemPtr
const std::vector< Eigen::VectorXd > & get_xs() const
void Solve(Eigen::MatrixXd &solution) override
Solves the problem.
double regmax_
Maximum regularization (to exit by divergence)


exotica_ddp_solver
Author(s): Traiko Dinev
autogenerated on Sat Apr 10 2021 02:36:22