Apollo 11.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
59public:
61 const size_t horizon,
62 const double ts,
63 const Eigen::MatrixXd& ego,
64 const Eigen::MatrixXd& xWS,
65 const Eigen::MatrixXd& uWS,
66 const Eigen::MatrixXd& l_warm_up,
67 const Eigen::MatrixXd& n_warm_up,
68 const Eigen::MatrixXd& s_warm_up,
69 const Eigen::MatrixXd& x0,
70 const Eigen::MatrixXd& xf,
71 const Eigen::MatrixXd& last_time_u,
72 const std::vector<double>& XYbounds,
73 const Eigen::MatrixXi& obstacles_edges_num,
74 const size_t obstacles_num,
75 const Eigen::MatrixXd& obstacles_A,
76 const Eigen::MatrixXd& obstacles_b,
77 const PlannerOpenSpaceConfig& planner_open_space_config);
78
80
82 bool get_nlp_info(
83 int& n,
84 int& m,
85 int& nnz_jac_g,
86 int& nnz_h_lag, // NOLINT
87 IndexStyleEnum& index_style) override; // NOLINT
88
90 bool get_bounds_info(int n, double* x_l, double* x_u, int m, double* g_l, double* g_u) override;
91
94 int n,
95 bool init_x,
96 double* x,
97 bool init_z,
98 double* z_L,
99 double* z_U,
100 int m,
101 bool init_lambda,
102 double* lambda) override;
103
105 bool eval_f(int n, const double* x, bool new_x, double& obj_value) override;
106
108 bool eval_grad_f(int n, const double* x, bool new_x, double* grad_f) override;
109
111 bool eval_g(int n, const double* x, bool new_x, int m, double* g) override;
112
114 bool check_g(int n, const double* x, int m, const double* g);
115
120 bool eval_jac_g(int n, const double* x, bool new_x, int m, int nele_jac, int* iRow, int* jCol, double* values)
121 override;
122
123 // sequential implementation to jac_g
124 bool eval_jac_g_ser(int n, const double* x, bool new_x, int m, int nele_jac, int* iRow, int* jCol, double* values)
125 override;
126
132 bool eval_h(
133 int n,
134 const double* x,
135 bool new_x,
136 double obj_factor,
137 int m,
138 const double* lambda,
139 bool new_lambda,
140 int nele_hess,
141 int* iRow,
142 int* jCol,
143 double* values) override;
144
149 Ipopt::SolverReturn status,
150 int n,
151 const double* x,
152 const double* z_L,
153 const double* z_U,
154 int m,
155 const double* g,
156 const double* lambda,
157 double obj_value,
158 const Ipopt::IpoptData* ip_data,
159 Ipopt::IpoptCalculatedQuantities* ip_cq) override;
160
162 Eigen::MatrixXd* state_result,
163 Eigen::MatrixXd* control_result,
164 Eigen::MatrixXd* time_result,
165 Eigen::MatrixXd* dual_l_result,
166 Eigen::MatrixXd* dual_n_result) const override;
167
168 //*************** start ADOL-C part ***********************************
170 template <class T>
171 void eval_obj(int n, const T* x, T* obj_value);
172
174 template <class T>
175 void eval_constraints(int n, const T* x, int m, T* g);
176
178 void generate_tapes(int n, int m, int* nnz_jac_g, int* nnz_h_lag);
179 //*************** end ADOL-C part ***********************************
180
181private:
182 int num_of_variables_ = 0;
183 int num_of_constraints_ = 0;
184 int horizon_ = 0;
185 int lambda_horizon_ = 0;
186 int miu_horizon_ = 0;
187 int slack_horizon_ = 0;
188 double ts_ = 0.0;
189
190 Eigen::MatrixXd ego_;
191 Eigen::MatrixXd xWS_;
192 Eigen::MatrixXd uWS_;
193 Eigen::MatrixXd l_warm_up_;
194 Eigen::MatrixXd n_warm_up_;
195 Eigen::MatrixXd slack_warm_up_;
196 Eigen::MatrixXd x0_;
197 Eigen::MatrixXd xf_;
198 Eigen::MatrixXd last_time_u_;
199 std::vector<double> XYbounds_;
200
201 // debug flag
202 bool enable_constraint_check_;
203
204 // penalty
205 double weight_state_x_ = 0.0;
206 double weight_state_y_ = 0.0;
207 double weight_state_phi_ = 0.0;
208 double weight_state_v_ = 0.0;
209 double weight_input_steer_ = 0.0;
210 double weight_input_a_ = 0.0;
211 double weight_rate_steer_ = 0.0;
212 double weight_rate_a_ = 0.0;
213 double weight_stitching_steer_ = 0.0;
214 double weight_stitching_a_ = 0.0;
215 double weight_first_order_time_ = 0.0;
216 double weight_second_order_time_ = 0.0;
217 double weight_end_state_ = 0.0;
218 double weight_slack_ = 0.0;
219
220 double w_ev_ = 0.0;
221 double l_ev_ = 0.0;
222 std::vector<double> g_;
223 double offset_ = 0.0;
224 Eigen::MatrixXi obstacles_edges_num_;
225 int obstacles_num_ = 0;
226 int obstacles_edges_sum_ = 0;
227 double wheelbase_ = 0.0;
228
229 Eigen::MatrixXd state_result_;
230 Eigen::MatrixXd dual_l_result_;
231 Eigen::MatrixXd dual_n_result_;
232 Eigen::MatrixXd control_result_;
233 Eigen::MatrixXd time_result_;
234 Eigen::MatrixXd slack_result_;
235
236 // obstacles_A
237 Eigen::MatrixXd obstacles_A_;
238
239 // obstacles_b
240 Eigen::MatrixXd obstacles_b_;
241
242 // whether to use fix time
243 bool use_fix_time_ = false;
244
245 // state start index
246 int state_start_index_ = 0;
247
248 // control start index.
249 int control_start_index_ = 0;
250
251 // time start index
252 int time_start_index_ = 0;
253
254 // lagrangian l start index
255 int l_start_index_ = 0;
256
257 // lagrangian n start index
258 int n_start_index_ = 0;
259
260 // slack s start index
261 int slack_index_ = 0;
262
263 double min_safety_distance_ = 0.0;
264
265 double max_safety_distance_ = 0.0;
266
267 double max_steer_angle_ = 0.0;
268
269 double max_speed_forward_ = 0.0;
270
271 double max_speed_reverse_ = 0.0;
272
273 double max_acceleration_forward_ = 0.0;
274
275 double max_acceleration_reverse_ = 0.0;
276
277 double min_time_sample_scaling_ = 0.0;
278
279 double max_time_sample_scaling_ = 0.0;
280
281 double max_steer_rate_ = 0.0;
282
283 double max_lambda_ = 0.0;
284
285 double max_miu_ = 0.0;
286
287 bool enable_jacobian_ad_ = false;
288
289private:
290 DistanceApproachConfig distance_approach_config_;
292
293private:
294 //*************** start ADOL-C part ***********************************
295 double* obj_lam;
296 //** variables for sparsity exploitation
297 unsigned int* rind_g; /* row indices */
298 unsigned int* cind_g; /* column indices */
299 double* jacval; /* values */
300 unsigned int* rind_L; /* row indices */
301 unsigned int* cind_L; /* column indices */
302 double* hessval; /* values */
303 int nnz_jac;
304 int nnz_L;
305 int options_g[4];
306 int options_L[4];
307 //*************** end ADOL-C part ***********************************
308
309 // park generic
310public:
312 const size_t horizon,
313 const double ts,
314 const Eigen::MatrixXd& ego,
315 const Eigen::MatrixXd& xWS,
316 const Eigen::MatrixXd& uWS,
317 const Eigen::MatrixXd& l_warm_up,
318 const Eigen::MatrixXd& n_warm_up,
319 const Eigen::MatrixXd& s_warm_up,
320 const Eigen::MatrixXd& x0,
321 const Eigen::MatrixXd& xf,
322 const Eigen::MatrixXd& last_time_u,
323 const std::vector<double>& XYbounds,
324 const Eigen::MatrixXi& obstacles_edges_num,
325 const size_t obstacles_num,
326 const Eigen::MatrixXd& obstacles_A,
327 const Eigen::MatrixXd& obstacles_b,
328 const DistanceApproachConfig& distance_approach_config);
329};
330
331} // namespace planning
332} // 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
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