Apollo 11.0
自动驾驶开放平台
dual_variable_warm_start_ipopt_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 30
42
43namespace apollo {
44namespace planning {
45
46class DualVariableWarmStartIPOPTInterface : 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
64 bool get_nlp_info(int& n, int& m, int& nnz_jac_g, int& nnz_h_lag, IndexStyleEnum& index_style) override;
65
67 bool get_bounds_info(int n, double* x_l, double* x_u, int m, double* g_l, double* g_u) override;
68
71 int n,
72 bool init_x,
73 double* x,
74 bool init_z,
75 double* z_L,
76 double* z_U,
77 int m,
78 bool init_lambda,
79 double* lambda) override;
80
82 bool eval_f(int n, const double* x, bool new_x, double& obj_value) override;
83
85 bool eval_grad_f(int n, const double* x, bool new_x, double* grad_f) override;
86
88 bool eval_g(int n, const double* x, bool new_x, int m, double* g) override;
89
94 bool eval_jac_g(int n, const double* x, bool new_x, int m, int nele_jac, int* iRow, int* jCol, double* values)
95 override;
96
102 bool eval_h(
103 int n,
104 const double* x,
105 bool new_x,
106 double obj_factor,
107 int m,
108 const double* lambda,
109 bool new_lambda,
110 int nele_hess,
111 int* iRow,
112 int* jCol,
113 double* values) override;
114
119 Ipopt::SolverReturn status,
120 int n,
121 const double* x,
122 const double* z_L,
123 const double* z_U,
124 int m,
125 const double* g,
126 const double* lambda,
127 double obj_value,
128 const Ipopt::IpoptData* ip_data,
129 Ipopt::IpoptCalculatedQuantities* ip_cq) override;
130
131 //*************** start ADOL-C part ***********************************
133 template <class T>
134 bool eval_obj(int n, const T* x, T* obj_value);
135
137 template <class T>
138 bool eval_constraints(int n, const T* x, int m, T* g);
139
141 void generate_tapes(int n, int m, int* nnz_h_lag);
142 //*************** end ADOL-C part ***********************************
143
144private:
145 int num_of_variables_;
146 int num_of_constraints_;
147 int horizon_;
148 double ts_;
149 Eigen::MatrixXd ego_;
150 int lambda_horizon_ = 0;
151 int miu_horizon_ = 0;
152 int dual_formulation_horizon_ = 0;
153
154 Eigen::MatrixXd l_warm_up_;
155 Eigen::MatrixXd n_warm_up_;
156 double wheelbase_;
157
158 double w_ev_;
159 double l_ev_;
160 std::vector<double> g_;
161 double offset_;
162 Eigen::MatrixXi obstacles_edges_num_;
163 int obstacles_num_;
164 int obstacles_edges_sum_;
165
166 // lagrangian l start index
167 int l_start_index_ = 0;
168
169 // lagrangian n start index
170 int n_start_index_ = 0;
171
172 // lagrangian d start index
173 int d_start_index_ = 0;
174
175 // obstacles_A
176 Eigen::MatrixXd obstacles_A_;
177
178 // obstacles_b
179 Eigen::MatrixXd obstacles_b_;
180
181 // states of warm up stage
182 Eigen::MatrixXd xWS_;
183
184 double weight_d_;
185
186 //*************** start ADOL-C part ***********************************
187 double* obj_lam;
188 unsigned int* rind_L; /* row indices */
189 unsigned int* cind_L; /* column indices */
190 double* hessval; /* values */
191 int nnz_L;
192 int options_L[4];
193 //*************** end ADOL-C part ***********************************
194
195 // park generic
196public:
198 size_t horizon,
199 double ts,
200 const Eigen::MatrixXd& ego,
201 const Eigen::MatrixXi& obstacles_edges_num,
202 const size_t obstacles_num,
203 const Eigen::MatrixXd& obstacles_A,
204 const Eigen::MatrixXd& obstacles_b,
205 const Eigen::MatrixXd& xWS,
206 const DualVariableWarmStartConfig& dual_variable_warm_start_config);
207};
208
209} // namespace planning
210} // namespace apollo
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_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
void get_optimization_results(Eigen::MatrixXd *l_warm_up, Eigen::MatrixXd *n_warm_up) const
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 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 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_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_grad_f(int n, const double *x, bool new_x, double *grad_f) override
Method to return the gradient of the objective
bool eval_obj(int n, const T *x, T *obj_value)
Template to return the objective value
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
Planning module main class.
class register implement
Definition arena_queue.h:37