Apollo 11.0
自动驾驶开放平台
cos_theta_ipopt_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#pragma once
18
19#include <cstddef>
20#include <map>
21#include <utility>
22#include <vector>
23
24#include <adolc/adolc.h>
25#include <adolc/adolc_sparse.h>
26#include <adolc/adouble.h>
27#include <coin/IpIpoptApplication.hpp>
28#include <coin/IpIpoptCalculatedQuantities.hpp>
29#include <coin/IpIpoptData.hpp>
30#include <coin/IpOrigIpoptNLP.hpp>
31#include <coin/IpSolveStatistics.hpp>
32#include <coin/IpTNLP.hpp>
33#include <coin/IpTNLPAdapter.hpp>
34#include <coin/IpTypes.hpp>
35
36#define tag_f 1
37#define tag_g 2
38#define tag_L 3
39#define HPOFF 30
40
41namespace apollo {
42namespace planning {
43
44class CosThetaIpoptInterface : public Ipopt::TNLP {
45 public:
46 CosThetaIpoptInterface(std::vector<std::pair<double, double>> points,
47 std::vector<double> bounds);
48
49 virtual ~CosThetaIpoptInterface() = default;
50
51 void set_weight_cos_included_angle(const double weight_cos_included_angle);
52
53 void set_weight_anchor_points(const double weight_anchor_points);
54
55 void set_weight_length(const double weight_length);
56
57 void set_automatic_differentiation_flag(const bool use_ad);
58
59 void get_optimization_results(std::vector<double>* ptr_x,
60 std::vector<double>* ptr_y) const;
61
63 bool get_nlp_info(int& n, int& m, int& nnz_jac_g, int& nnz_h_lag,
64 IndexStyleEnum& index_style) override;
65
67 bool get_bounds_info(int n, double* x_l, double* x_u, int m, double* g_l,
68 double* g_u) override;
69
71 bool get_starting_point(int n, bool init_x, double* x, bool init_z,
72 double* z_L, double* z_U, int m, bool init_lambda,
73 double* lambda) override;
74
76 bool eval_f(int n, const double* x, bool new_x, double& obj_value) override;
77
79 bool eval_grad_f(int n, const double* x, bool new_x, double* grad_f) override;
80
82 bool eval_g(int n, const double* x, bool new_x, int m, double* g) override;
83
88 bool eval_jac_g(int n, const double* x, bool new_x, int m, int nele_jac,
89 int* iRow, int* jCol, double* values) override;
90
96 bool eval_h(int n, const double* x, bool new_x, double obj_factor, int m,
97 const double* lambda, bool new_lambda, int nele_hess, int* iRow,
98 int* jCol, double* values) override;
99
103 void finalize_solution(Ipopt::SolverReturn status, int n, const double* x,
104 const double* z_L, const double* z_U, int m,
105 const double* g, const double* lambda,
106 double obj_value, const Ipopt::IpoptData* ip_data,
107 Ipopt::IpoptCalculatedQuantities* ip_cq) override;
108
109 //*************** start ADOL-C part ***********************************
110
112 template <class T>
113 bool eval_obj(int n, const T* x, T* obj_value);
114
116 template <class T>
117 bool eval_constraints(int n, const T* x, int m, T* g);
118
120 virtual void generate_tapes(int n, int m, int* nnz_jac_g, int* nnz_h_lag);
121
122 //*************** end ADOL-C part ***********************************
123
124 private:
125 std::vector<std::pair<double, double>> ref_points_;
126
127 std::vector<double> bounds_;
128
129 std::vector<double> opt_x_;
130
131 std::vector<double> opt_y_;
132
133 size_t num_of_variables_ = 0;
134
135 size_t num_of_constraints_ = 0;
136
137 size_t nnz_jac_g_ = 0;
138
139 size_t nnz_h_lag_ = 0;
140
141 size_t num_of_points_ = 0;
142
143 std::map<std::pair<size_t, size_t>, size_t> idx_map_;
144
145 void hessian_strcuture();
146
147 double weight_cos_included_angle_ = 0.0;
148
149 double weight_anchor_points_ = 0.0;
150
151 double weight_length_ = 0.0;
152
153 //*************** start ADOL-C part ***********************************
154
155 bool use_automatic_differentiation_ = false;
160
161 std::vector<double> obj_lam_;
162
163 // TODO(Jinyun): Not changed to std::vector yet, need further debug
164 //** variables for sparsity exploitation
165 // std::vector<unsigned int> rind_g_; /* row indices */
166 // std::vector<unsigned int> cind_g_; /* column indices */
167 // std::vector<double> jacval_; /* values */
168 // std::vector<unsigned int> rind_L_; /* row indices */
169 // std::vector<unsigned int> cind_L_; /* column indices */
170 // std::vector<double> hessval_; /* values */
171
172 //** variables for sparsity exploitation
173 unsigned int* rind_g_; /* row indices */
174 unsigned int* cind_g_; /* column indices */
175 double* jacval_; /* values */
176 unsigned int* rind_L_; /* row indices */
177 unsigned int* cind_L_; /* column indices */
178 double* hessval_; /* values */
179
180 int nnz_jac_ = 0;
181 int nnz_L_ = 0;
182 int options_g_[4];
183 int options_L_[4];
184
185 //*************** end ADOL-C part ***********************************
186};
187} // namespace planning
188} // namespace apollo
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_constraints(int n, const T *x, int m, T *g)
Template to compute contraints
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 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
bool eval_g(int n, const double *x, bool new_x, int m, double *g) override
Method to return the constraint residuals
void set_weight_length(const double weight_length)
virtual void generate_tapes(int n, int m, int *nnz_jac_g, int *nnz_h_lag)
Method to generate the required tapes
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_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_obj(int n, const T *x, T *obj_value)
Template to return the objective value
void set_weight_cos_included_angle(const double weight_cos_included_angle)
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
void get_optimization_results(std::vector< double > *ptr_x, std::vector< double > *ptr_y) const
void set_weight_anchor_points(const double weight_anchor_points)
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
Planning module main class.
class register implement
Definition arena_queue.h:37