Apollo 10.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 {
47 public:
49 size_t horizon, double ts, const Eigen::MatrixXd& ego,
50 const Eigen::MatrixXi& obstacles_edges_num, const size_t obstacles_num,
51 const Eigen::MatrixXd& obstacles_A, const Eigen::MatrixXd& obstacles_b,
52 const Eigen::MatrixXd& xWS,
53 const PlannerOpenSpaceConfig& planner_open_space_config);
54
56
57 void get_optimization_results(Eigen::MatrixXd* l_warm_up,
58 Eigen::MatrixXd* n_warm_up) const;
59
61 bool get_nlp_info(int& n, int& m, int& nnz_jac_g, int& nnz_h_lag,
62 IndexStyleEnum& index_style) override;
63
65 bool get_bounds_info(int n, double* x_l, double* x_u, int m, double* g_l,
66 double* g_u) override;
67
69 bool get_starting_point(int n, bool init_x, double* x, bool init_z,
70 double* z_L, double* z_U, int m, bool init_lambda,
71 double* lambda) override;
72
74 bool eval_f(int n, const double* x, bool new_x, double& obj_value) override;
75
77 bool eval_grad_f(int n, const double* x, bool new_x, double* grad_f) override;
78
80 bool eval_g(int n, const double* x, bool new_x, int m, double* g) override;
81
86 bool eval_jac_g(int n, const double* x, bool new_x, int m, int nele_jac,
87 int* iRow, int* jCol, double* values) override;
88
94 bool eval_h(int n, const double* x, bool new_x, double obj_factor, int m,
95 const double* lambda, bool new_lambda, int nele_hess, int* iRow,
96 int* jCol, double* values) override;
97
101 void finalize_solution(Ipopt::SolverReturn status, int n, const double* x,
102 const double* z_L, const double* z_U, int m,
103 const double* g, const double* lambda,
104 double obj_value, const Ipopt::IpoptData* ip_data,
105 Ipopt::IpoptCalculatedQuantities* ip_cq) override;
106
107 //*************** start ADOL-C part ***********************************
109 template <class T>
110 bool eval_obj(int n, const T* x, T* obj_value);
111
113 template <class T>
114 bool eval_constraints(int n, const T* x, int m, T* g);
115
117 void generate_tapes(int n, int m, int* nnz_h_lag);
118 //*************** end ADOL-C part ***********************************
119
120 private:
121 int num_of_variables_;
122 int num_of_constraints_;
123 int horizon_;
124 double ts_;
125 Eigen::MatrixXd ego_;
126 int lambda_horizon_ = 0;
127 int miu_horizon_ = 0;
128 int dual_formulation_horizon_ = 0;
129
130 Eigen::MatrixXd l_warm_up_;
131 Eigen::MatrixXd n_warm_up_;
132 double wheelbase_;
133
134 double w_ev_;
135 double l_ev_;
136 std::vector<double> g_;
137 double offset_;
138 Eigen::MatrixXi obstacles_edges_num_;
139 int obstacles_num_;
140 int obstacles_edges_sum_;
141
142 // lagrangian l start index
143 int l_start_index_ = 0;
144
145 // lagrangian n start index
146 int n_start_index_ = 0;
147
148 // lagrangian d start index
149 int d_start_index_ = 0;
150
151 // obstacles_A
152 Eigen::MatrixXd obstacles_A_;
153
154 // obstacles_b
155 Eigen::MatrixXd obstacles_b_;
156
157 // states of warm up stage
158 Eigen::MatrixXd xWS_;
159
160 double weight_d_;
161
162 //*************** start ADOL-C part ***********************************
163 double* obj_lam;
164 unsigned int* rind_L; /* row indices */
165 unsigned int* cind_L; /* column indices */
166 double* hessval; /* values */
167 int nnz_L;
168 int options_L[4];
169 //*************** end ADOL-C part ***********************************
170
171// park generic
172 public:
174 size_t horizon, double ts, const Eigen::MatrixXd& ego,
175 const Eigen::MatrixXi& obstacles_edges_num, const size_t obstacles_num,
176 const Eigen::MatrixXd& obstacles_A, const Eigen::MatrixXd& obstacles_b,
177 const Eigen::MatrixXd& xWS,
178 const DualVariableWarmStartConfig& dual_variable_warm_start_config);
179};
180
181} // namespace planning
182} // namespace apollo
DualVariableWarmStartIPOPTInterface(size_t horizon, double ts, const Eigen::MatrixXd &ego, const Eigen::MatrixXi &obstacles_edges_num, const size_t obstacles_num, const Eigen::MatrixXd &obstacles_A, const Eigen::MatrixXd &obstacles_b, const Eigen::MatrixXd &xWS, const DualVariableWarmStartConfig &dual_variable_warm_start_config)
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