Apollo 11.0
自动驾驶开放平台
dual_variable_warm_start_ipopt_qp_interface.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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 <limits>
24#include <vector>
25
26#include <adolc/adolc.h>
27#include <adolc/adolc_sparse.h>
28#include <coin/IpTNLP.hpp>
29#include <coin/IpTypes.hpp>
30
31#include "Eigen/Dense"
32
33#include "modules/common_msgs/config_msgs/vehicle_config.pb.h"
34#include "modules/planning/planning_open_space/proto/planner_open_space_config.pb.h"
35
37
38// #define tag_f 1
39// #define tag_g 2
40#define tag_L 3
41// #define HPOFF
42
43namespace apollo {
44namespace planning {
45
46class DualVariableWarmStartIPOPTQPInterface : public Ipopt::TNLP {
47public:
49 size_t horizon,
50 double ts,
51 const Eigen::MatrixXd& ego,
52 const Eigen::MatrixXi& obstacles_edges_num,
53 const size_t obstacles_num,
54 const Eigen::MatrixXd& obstacles_A,
55 const Eigen::MatrixXd& obstacles_b,
56 const Eigen::MatrixXd& xWS,
57 const PlannerOpenSpaceConfig& planner_open_space_config);
58
60
61 void get_optimization_results(Eigen::MatrixXd* l_warm_up, Eigen::MatrixXd* n_warm_up) const;
62
63 void check_solution(const Eigen::MatrixXd& l_warm_up, const Eigen::MatrixXd& n_warm_up);
64
66 bool get_nlp_info(int& n, int& m, int& nnz_jac_g, int& nnz_h_lag, IndexStyleEnum& index_style) override;
67
69 bool get_bounds_info(int n, double* x_l, double* x_u, int m, double* g_l, double* g_u) override;
70
73 int n,
74 bool init_x,
75 double* x,
76 bool init_z,
77 double* z_L,
78 double* z_U,
79 int m,
80 bool init_lambda,
81 double* lambda) override;
82
84 bool eval_f(int n, const double* x, bool new_x, double& obj_value) override;
85
87 bool eval_grad_f(int n, const double* x, bool new_x, double* grad_f) override;
88
90 bool eval_g(int n, const double* x, bool new_x, int m, double* g) override;
91
96 bool eval_jac_g(int n, const double* x, bool new_x, int m, int nele_jac, int* iRow, int* jCol, double* values)
97 override;
98
104 bool eval_h(
105 int n,
106 const double* x,
107 bool new_x,
108 double obj_factor,
109 int m,
110 const double* lambda,
111 bool new_lambda,
112 int nele_hess,
113 int* iRow,
114 int* jCol,
115 double* values) override;
116
121 Ipopt::SolverReturn status,
122 int n,
123 const double* x,
124 const double* z_L,
125 const double* z_U,
126 int m,
127 const double* g,
128 const double* lambda,
129 double obj_value,
130 const Ipopt::IpoptData* ip_data,
131 Ipopt::IpoptCalculatedQuantities* ip_cq) override;
132
133 //*************** start ADOL-C part ***********************************
135 template <class T>
136 bool eval_obj(int n, const T* x, T* obj_value);
137
139 template <class T>
140 bool eval_constraints(int n, const T* x, int m, T* g);
141
143 void generate_tapes(int n, int m, int* nnz_h_lag);
144 //*************** end ADOL-C part ***********************************
145
146private:
147 int num_of_variables_;
148 int num_of_constraints_;
149 int horizon_;
150 double ts_;
151 Eigen::MatrixXd ego_;
152 int lambda_horizon_ = 0;
153 int miu_horizon_ = 0;
154 int dual_formulation_horizon_ = 0;
155
156 Eigen::MatrixXd l_warm_up_;
157 Eigen::MatrixXd n_warm_up_;
158 double wheelbase_;
159
160 double w_ev_;
161 double l_ev_;
162 std::vector<double> g_;
163 double offset_;
164 Eigen::MatrixXi obstacles_edges_num_;
165 int obstacles_num_;
166 int obstacles_edges_sum_;
167
168 // lagrangian l start index
169 int l_start_index_ = 0;
170
171 // lagrangian n start index
172 int n_start_index_ = 0;
173
174 // lagrangian d start index
175 int d_start_index_ = 0;
176
177 // obstacles_A
178 Eigen::MatrixXd obstacles_A_;
179
180 // obstacles_b
181 Eigen::MatrixXd obstacles_b_;
182
183 // states of warm up stage
184 Eigen::MatrixXd xWS_;
185
186 double min_safety_distance_;
187
188 //*************** start ADOL-C part ***********************************
189 double* obj_lam;
190 unsigned int* rind_L; /* row indices */
191 unsigned int* cind_L; /* column indices */
192 double* hessval; /* values */
193 int nnz_L;
194 int options_L[4];
195 //*************** end ADOL-C part ***********************************
196
197 // park generic
198public:
200 size_t horizon,
201 double ts,
202 const Eigen::MatrixXd& ego,
203 const Eigen::MatrixXi& obstacles_edges_num,
204 const size_t obstacles_num,
205 const Eigen::MatrixXd& obstacles_A,
206 const Eigen::MatrixXd& obstacles_b,
207 const Eigen::MatrixXd& xWS,
208 const DualVariableWarmStartConfig& dual_variable_warm_start_config);
209};
210
211} // namespace planning
212} // namespace apollo
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...
void generate_tapes(int n, int m, int *nnz_h_lag)
Method to generate the required tapes
bool eval_g(int n, const double *x, bool new_x, int m, double *g) override
Method to return the constraint residuals
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_grad_f(int n, const double *x, bool new_x, double *grad_f) override
Method to return the gradient of the objective
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
bool eval_f(int n, const double *x, bool new_x, double &obj_value) override
Method to return the objective value
bool eval_constraints(int n, const T *x, int m, T *g)
Template to compute constraints
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...
void get_optimization_results(Eigen::MatrixXd *l_warm_up, Eigen::MatrixXd *n_warm_up) const
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
void check_solution(const Eigen::MatrixXd &l_warm_up, const Eigen::MatrixXd &n_warm_up)
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_obj(int n, const T *x, T *obj_value)
Template to return the objective value
Planning module main class.
class register implement
Definition arena_queue.h:37