Apollo  6.0
Open source self driving car software
piecewise_jerk_path_ipopt_solver.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
21 #pragma once
22 
23 #include <utility>
24 #include <vector>
25 
26 #include <coin/IpTNLP.hpp>
27 #include <coin/IpTypes.hpp>
28 
29 namespace apollo {
30 namespace planning {
31 
32 class PiecewiseJerkPathIpoptSolver : public Ipopt::TNLP {
33  public:
34  PiecewiseJerkPathIpoptSolver(const double d_init, const double d_prime_init,
35  const double d_pprime_init, const double delta_s,
36  const double d_ppprime_max,
37  std::vector<std::pair<double, double>> d_bounds);
38 
39  virtual ~PiecewiseJerkPathIpoptSolver() = default;
40 
41  void set_objective_weights(const double w_x, const double w_dx,
42  const double w_ddx, const double w_dddx,
43  const double w_d_obs);
44 
46  bool get_nlp_info(int& n, int& m, int& nnz_jac_g, int& nnz_h_lag,
47  IndexStyleEnum& index_style) override;
48 
50  bool get_bounds_info(int n, double* x_l, double* x_u, int m, double* g_l,
51  double* g_u) override;
52 
54  bool get_starting_point(int n, bool init_x, double* x, bool init_z,
55  double* z_L, double* z_U, int m, bool init_lambda,
56  double* lambda) override;
57 
59  bool eval_f(int n, const double* x, bool new_x, double& obj_value) override;
60 
62  bool eval_grad_f(int n, const double* x, bool new_x, double* grad_f) override;
63 
65  bool eval_g(int n, const double* x, bool new_x, int m, double* g) override;
66 
71  bool eval_jac_g(int n, const double* x, bool new_x, int m, int nele_jac,
72  int* iRow, int* jCol, double* values) override;
73 
79  bool eval_h(int n, const double* x, bool new_x, double obj_factor, int m,
80  const double* lambda, bool new_lambda, int nele_hess, int* iRow,
81  int* jCol, double* values) override;
82 
86  void finalize_solution(Ipopt::SolverReturn status, int n, const double* x,
87  const double* z_L, const double* z_U, int m,
88  const double* g, const double* lambda,
89  double obj_value, const Ipopt::IpoptData* ip_data,
90  Ipopt::IpoptCalculatedQuantities* ip_cq) override;
91 
92  void GetOptimizationResult(std::vector<double>* ptr_opt_d,
93  std::vector<double>* ptr_opt_d_prime,
94  std::vector<double>* ptr_opt_d_pprime) const;
95 
96  private:
97  int num_of_points_;
98 
99  int num_of_variables_;
100 
101  int num_of_constraints_;
102 
103  double x_init_ = 0.0;
104 
105  double dx_init_ = 0.0;
106 
107  double ddx_init_ = 0.0;
108 
109  double delta_s_ = 0.0;
110 
111  double dddx_max_ = 0.0;
112 
113  std::vector<std::pair<double, double>> d_bounds_;
114 
115  double w_x_ = 1.0;
116 
117  double w_dx_ = 1.0;
118 
119  double w_ddx_ = 1.0;
120 
121  double w_dddx_ = 1.0;
122 
123  double w_obs_ = 1.0;
124 
125  std::vector<double> opt_x_;
126 
127  std::vector<double> opt_dx_;
128 
129  std::vector<double> opt_ddx_;
130 };
131 
132 } // namespace planning
133 } // namespace apollo
void GetOptimizationResult(std::vector< double > *ptr_opt_d, std::vector< double > *ptr_opt_d_prime, std::vector< double > *ptr_opt_d_pprime) const
bool eval_g(int n, const double *x, bool new_x, int m, double *g) override
PiecewiseJerkPathIpoptSolver(const double d_init, const double d_prime_init, const double d_pprime_init, const double delta_s, const double d_ppprime_max, std::vector< std::pair< double, double >> d_bounds)
bool eval_h(int n, const double *x, bool new_x, double obj_factor, int m, const double *lambda, bool new_lambda, int nele_hess, int *iRow, int *jCol, double *values) override
bool eval_grad_f(int n, const double *x, bool new_x, double *grad_f) override
Definition: piecewise_jerk_path_ipopt_solver.h:32
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
bool get_nlp_info(int &n, int &m, int &nnz_jac_g, int &nnz_h_lag, IndexStyleEnum &index_style) override
Planning module main class. It processes GPS and IMU as input, to generate planning info...
bool get_starting_point(int n, bool init_x, double *x, bool init_z, double *z_L, double *z_U, int m, bool init_lambda, double *lambda) override
bool eval_f(int n, const double *x, bool new_x, double &obj_value) override
void set_objective_weights(const double w_x, const double w_dx, const double w_ddx, const double w_dddx, const double w_d_obs)
void finalize_solution(Ipopt::SolverReturn status, int n, const double *x, const double *z_L, const double *z_U, int m, const double *g, const double *lambda, double obj_value, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq) override
bool get_bounds_info(int n, double *x_l, double *x_u, int m, double *g_l, double *g_u) override
bool eval_jac_g(int n, const double *x, bool new_x, int m, int nele_jac, int *iRow, int *jCol, double *values) override