Apollo 10.0
自动驾驶开放平台
distance_approach_ipopt_relax_end_slack_interface.h
浏览该文件的文档.
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
17/*
18 * @file
19 */
20
21#pragma once
22
23#include <algorithm>
24#include <limits>
25#include <vector>
26
27#include <omp.h>
28
29#include <adolc/adolc.h>
30#include <adolc/adolc_openmp.h>
31#include <adolc/adolc_sparse.h>
32#include <adolc/adouble.h>
33
34#include <coin/IpTNLP.hpp>
35#include <coin/IpTypes.hpp>
36
37#include "Eigen/Dense"
38
39#include "modules/common_msgs/config_msgs/vehicle_config.pb.h"
40#include "modules/planning/planning_open_space/proto/planner_open_space_config.pb.h"
41
42#include "cyber/common/log.h"
43#include "cyber/common/macros.h"
49
50#define tag_f 1
51#define tag_g 2
52#define tag_L 3
53#define HPOFF 30
54
55namespace apollo {
56namespace planning {
57
60 public:
62 const size_t horizon, const double ts, const Eigen::MatrixXd& ego,
63 const Eigen::MatrixXd& xWS, const Eigen::MatrixXd& uWS,
64 const Eigen::MatrixXd& l_warm_up, const Eigen::MatrixXd& n_warm_up,
65 const Eigen::MatrixXd& s_warm_up, const Eigen::MatrixXd& x0,
66 const Eigen::MatrixXd& xf, const Eigen::MatrixXd& last_time_u,
67 const std::vector<double>& XYbounds,
68 const Eigen::MatrixXi& obstacles_edges_num, const size_t obstacles_num,
69 const Eigen::MatrixXd& obstacles_A, const Eigen::MatrixXd& obstacles_b,
70 const PlannerOpenSpaceConfig& planner_open_space_config);
71
73
75 bool get_nlp_info(int& n, int& m, int& nnz_jac_g, int& nnz_h_lag, // NOLINT
76 IndexStyleEnum& index_style) override; // NOLINT
77
79 bool get_bounds_info(int n, double* x_l, double* x_u, int m, double* g_l,
80 double* g_u) override;
81
83 bool get_starting_point(int n, bool init_x, double* x, bool init_z,
84 double* z_L, double* z_U, int m, bool init_lambda,
85 double* lambda) override;
86
88 bool eval_f(int n, const double* x, bool new_x, double& obj_value) override;
89
91 bool eval_grad_f(int n, const double* x, bool new_x, double* grad_f) override;
92
94 bool eval_g(int n, const double* x, bool new_x, int m, double* g) override;
95
97 bool check_g(int n, const double* x, int m, const double* g);
98
103 bool eval_jac_g(int n, const double* x, bool new_x, int m, int nele_jac,
104 int* iRow, int* jCol, double* values) override;
105
106 // sequential implementation to jac_g
107 bool eval_jac_g_ser(int n, const double* x, bool new_x, int m, int nele_jac,
108 int* iRow, int* jCol, double* values) override;
109
115 bool eval_h(int n, const double* x, bool new_x, double obj_factor, int m,
116 const double* lambda, bool new_lambda, int nele_hess, int* iRow,
117 int* jCol, double* values) override;
118
122 void finalize_solution(Ipopt::SolverReturn status, int n, const double* x,
123 const double* z_L, const double* z_U, int m,
124 const double* g, const double* lambda,
125 double obj_value, const Ipopt::IpoptData* ip_data,
126 Ipopt::IpoptCalculatedQuantities* ip_cq) override;
127
128 void get_optimization_results(Eigen::MatrixXd* state_result,
129 Eigen::MatrixXd* control_result,
130 Eigen::MatrixXd* time_result,
131 Eigen::MatrixXd* dual_l_result,
132 Eigen::MatrixXd* dual_n_result) const override;
133
134 //*************** start ADOL-C part ***********************************
136 template <class T>
137 void eval_obj(int n, const T* x, T* obj_value);
138
140 template <class T>
141 void eval_constraints(int n, const T* x, int m, T* g);
142
144 void generate_tapes(int n, int m, int* nnz_jac_g, int* nnz_h_lag);
145 //*************** end ADOL-C part ***********************************
146
147 private:
148 int num_of_variables_ = 0;
149 int num_of_constraints_ = 0;
150 int horizon_ = 0;
151 int lambda_horizon_ = 0;
152 int miu_horizon_ = 0;
153 int slack_horizon_ = 0;
154 double ts_ = 0.0;
155
156 Eigen::MatrixXd ego_;
157 Eigen::MatrixXd xWS_;
158 Eigen::MatrixXd uWS_;
159 Eigen::MatrixXd l_warm_up_;
160 Eigen::MatrixXd n_warm_up_;
161 Eigen::MatrixXd slack_warm_up_;
162 Eigen::MatrixXd x0_;
163 Eigen::MatrixXd xf_;
164 Eigen::MatrixXd last_time_u_;
165 std::vector<double> XYbounds_;
166
167 // debug flag
168 bool enable_constraint_check_;
169
170 // penalty
171 double weight_state_x_ = 0.0;
172 double weight_state_y_ = 0.0;
173 double weight_state_phi_ = 0.0;
174 double weight_state_v_ = 0.0;
175 double weight_input_steer_ = 0.0;
176 double weight_input_a_ = 0.0;
177 double weight_rate_steer_ = 0.0;
178 double weight_rate_a_ = 0.0;
179 double weight_stitching_steer_ = 0.0;
180 double weight_stitching_a_ = 0.0;
181 double weight_first_order_time_ = 0.0;
182 double weight_second_order_time_ = 0.0;
183 double weight_end_state_ = 0.0;
184 double weight_slack_ = 0.0;
185
186 double w_ev_ = 0.0;
187 double l_ev_ = 0.0;
188 std::vector<double> g_;
189 double offset_ = 0.0;
190 Eigen::MatrixXi obstacles_edges_num_;
191 int obstacles_num_ = 0;
192 int obstacles_edges_sum_ = 0;
193 double wheelbase_ = 0.0;
194
195 Eigen::MatrixXd state_result_;
196 Eigen::MatrixXd dual_l_result_;
197 Eigen::MatrixXd dual_n_result_;
198 Eigen::MatrixXd control_result_;
199 Eigen::MatrixXd time_result_;
200 Eigen::MatrixXd slack_result_;
201
202 // obstacles_A
203 Eigen::MatrixXd obstacles_A_;
204
205 // obstacles_b
206 Eigen::MatrixXd obstacles_b_;
207
208 // whether to use fix time
209 bool use_fix_time_ = false;
210
211 // state start index
212 int state_start_index_ = 0;
213
214 // control start index.
215 int control_start_index_ = 0;
216
217 // time start index
218 int time_start_index_ = 0;
219
220 // lagrangian l start index
221 int l_start_index_ = 0;
222
223 // lagrangian n start index
224 int n_start_index_ = 0;
225
226 // slack s start index
227 int slack_index_ = 0;
228
229 double min_safety_distance_ = 0.0;
230
231 double max_safety_distance_ = 0.0;
232
233 double max_steer_angle_ = 0.0;
234
235 double max_speed_forward_ = 0.0;
236
237 double max_speed_reverse_ = 0.0;
238
239 double max_acceleration_forward_ = 0.0;
240
241 double max_acceleration_reverse_ = 0.0;
242
243 double min_time_sample_scaling_ = 0.0;
244
245 double max_time_sample_scaling_ = 0.0;
246
247 double max_steer_rate_ = 0.0;
248
249 double max_lambda_ = 0.0;
250
251 double max_miu_ = 0.0;
252
253 bool enable_jacobian_ad_ = false;
254
255 private:
256 DistanceApproachConfig distance_approach_config_;
257 const common::VehicleParam vehicle_param_ =
259
260 private:
261 //*************** start ADOL-C part ***********************************
262 double* obj_lam;
263 //** variables for sparsity exploitation
264 unsigned int* rind_g; /* row indices */
265 unsigned int* cind_g; /* column indices */
266 double* jacval; /* values */
267 unsigned int* rind_L; /* row indices */
268 unsigned int* cind_L; /* column indices */
269 double* hessval; /* values */
270 int nnz_jac;
271 int nnz_L;
272 int options_g[4];
273 int options_L[4];
274 //*************** end ADOL-C part ***********************************
275
276// park generic
277 public:
279 const size_t horizon, const double ts, const Eigen::MatrixXd& ego,
280 const Eigen::MatrixXd& xWS, const Eigen::MatrixXd& uWS,
281 const Eigen::MatrixXd& l_warm_up, const Eigen::MatrixXd& n_warm_up,
282 const Eigen::MatrixXd& s_warm_up, const Eigen::MatrixXd& x0,
283 const Eigen::MatrixXd& xf, const Eigen::MatrixXd& last_time_u,
284 const std::vector<double>& XYbounds,
285 const Eigen::MatrixXi& obstacles_edges_num, const size_t obstacles_num,
286 const Eigen::MatrixXd& obstacles_A, const Eigen::MatrixXd& obstacles_b,
287 const DistanceApproachConfig& distance_approach_config);
288};
289
290} // namespace planning
291} // namespace apollo
static const VehicleConfig & GetConfig()
Get the current vehicle configuration.
void generate_tapes(int n, int m, int *nnz_jac_g, int *nnz_h_lag)
Method to generate the required tapes by ADOL-C
bool get_nlp_info(int &n, int &m, int &nnz_jac_g, int &nnz_h_lag, IndexStyleEnum &index_style) override
Method to return some info about the nlp
bool eval_jac_g(int n, const double *x, bool new_x, int m, int nele_jac, int *iRow, int *jCol, double *values) override
Method to return: 1) The structure of the jacobian (if "values" is nullptr) 2) The values of the jaco...
bool eval_jac_g_ser(int n, const double *x, bool new_x, int m, int nele_jac, int *iRow, int *jCol, double *values) override
DistanceApproachIPOPTRelaxEndSlackInterface(const size_t horizon, const double ts, const Eigen::MatrixXd &ego, const Eigen::MatrixXd &xWS, const Eigen::MatrixXd &uWS, const Eigen::MatrixXd &l_warm_up, const Eigen::MatrixXd &n_warm_up, const Eigen::MatrixXd &s_warm_up, const Eigen::MatrixXd &x0, const Eigen::MatrixXd &xf, const Eigen::MatrixXd &last_time_u, const std::vector< double > &XYbounds, const Eigen::MatrixXi &obstacles_edges_num, const size_t obstacles_num, const Eigen::MatrixXd &obstacles_A, const Eigen::MatrixXd &obstacles_b, const DistanceApproachConfig &distance_approach_config)
void eval_obj(int n, const T *x, T *obj_value)
Template to return the objective value
bool get_bounds_info(int n, double *x_l, double *x_u, int m, double *g_l, double *g_u) override
Method to return the bounds for my problem
bool eval_f(int n, const double *x, bool new_x, double &obj_value) override
Method to return the objective value
void eval_constraints(int n, const T *x, int m, T *g)
Template to compute constraints
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
Method to return the starting point for the algorithm
bool eval_grad_f(int n, const double *x, bool new_x, double *grad_f) override
Method to return the gradient of the objective
void get_optimization_results(Eigen::MatrixXd *state_result, Eigen::MatrixXd *control_result, Eigen::MatrixXd *time_result, Eigen::MatrixXd *dual_l_result, Eigen::MatrixXd *dual_n_result) const override
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
Method to return: 1) The structure of the hessian of the lagrangian (if "values" is nullptr) 2) The v...
bool eval_g(int n, const double *x, bool new_x, int m, double *g) override
Method to return the constraint residuals
bool check_g(int n, const double *x, int m, const double *g)
Check unfeasible constraints for further study
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
This method is called when the algorithm is complete so the TNLP can store/write the solution
Planning module main class.
Math-related util functions.
Some util functions.
class register implement
Definition arena_queue.h:37
optional VehicleParam vehicle_param