Apollo 11.0
自动驾驶开放平台
spiral_problem_interface.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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 * spiral_problem_interface.h
19 */
20
21#pragma once
22
23/* Workaround for coin/IpSmartPtr.hpp:18:4: error: #error "don't have header
24 * file for stddef" */
25#include <cstddef>
26#include <vector>
27
28#include <coin/IpTNLP.hpp>
29#include <coin/IpTypes.hpp>
30
31#include "Eigen/Dense"
32
34
35namespace apollo {
36namespace planning {
37
38class SpiralProblemInterface : public Ipopt::TNLP {
39 public:
40 explicit SpiralProblemInterface(std::vector<Eigen::Vector2d> points);
41
42 virtual ~SpiralProblemInterface() = default;
43
44 void set_default_max_point_deviation(const double point_max_deviation);
45
46 void set_start_point(const double x, const double y, const double theta,
47 const double kappa, const double dkappa);
48
49 void set_end_point(const double x, const double y, const double theta,
50 const double kappa, const double dkappa);
51
52 void set_end_point_position(const double x, const double y);
53
54 void set_element_weight_curve_length(const double weight_curve_length);
55
56 void set_element_weight_kappa(const double weight_kappa);
57
58 void set_element_weight_dkappa(const double weight_dkappa);
59
60 void get_optimization_results(std::vector<double>* ptr_theta,
61 std::vector<double>* ptr_kappa,
62 std::vector<double>* ptr_dkappa,
63 std::vector<double>* ptr_s,
64 std::vector<double>* ptr_x,
65 std::vector<double>* ptr_y) const;
66
68 bool get_nlp_info(int& n, int& m, int& nnz_jac_g, int& nnz_h_lag,
69 IndexStyleEnum& index_style) override;
70
72 bool get_bounds_info(int n, double* x_l, double* x_u, int m, double* g_l,
73 double* g_u) override;
74
76 bool get_starting_point(int n, bool init_x, double* x, bool init_z,
77 double* z_L, double* z_U, int m, bool init_lambda,
78 double* lambda) override;
79
81 bool eval_f(int n, const double* x, bool new_x, double& obj_value) override;
82
84 bool eval_grad_f(int n, const double* x, bool new_x, double* grad_f) override;
85
87 bool eval_g(int n, const double* x, bool new_x, int m, double* g) override;
88
93 bool eval_jac_g(int n, const double* x, bool new_x, int m, int nele_jac,
94 int* iRow, int* jCol, double* values) override;
95
101 bool eval_h(int n, const double* x, bool new_x, double obj_factor, int m,
102 const double* lambda, bool new_lambda, int nele_hess, int* iRow,
103 int* jCol, double* values) override;
104
108 void finalize_solution(Ipopt::SolverReturn status, int n, const double* x,
109 const double* z_L, const double* z_U, int m,
110 const double* g, const double* lambda,
111 double obj_value, const Ipopt::IpoptData* ip_data,
112 Ipopt::IpoptCalculatedQuantities* ip_cq) override;
113
114 public:
115 static constexpr size_t N = 10;
116
117 private:
118 void update_piecewise_spiral_paths(const double* x, const int n);
119
120 std::vector<Eigen::Vector2d> init_points_;
121
122 std::vector<double> opt_theta_;
123
124 std::vector<double> opt_kappa_;
125
126 std::vector<double> opt_dkappa_;
127
128 std::vector<double> opt_s_;
129
130 std::vector<double> opt_x_;
131
132 std::vector<double> opt_y_;
133
134 std::vector<double> point_distances_;
135
136 int num_of_variables_ = 0;
137
138 int num_of_constraints_ = 0;
139
140 int num_of_points_ = 0;
141
142 double default_max_point_deviation_ = 0.0;
143
144 const int num_of_internal_points_ = 5;
145
146 std::vector<double> relative_theta_;
147
148 std::vector<QuinticSpiralPathWithDerivation<N>> piecewise_paths_;
149
150 bool has_fixed_start_point_ = false;
151
152 double start_x_ = 0.0;
153
154 double start_y_ = 0.0;
155
156 double start_theta_ = 0.0;
157
158 double start_kappa_ = 0.0;
159
160 double start_dkappa_ = 0.0;
161
162 bool has_fixed_end_point_ = false;
163
164 double end_x_ = 0.0;
165
166 double end_y_ = 0.0;
167
168 double end_theta_ = 0.0;
169
170 double end_kappa_ = 0.0;
171
172 double end_dkappa_ = 0.0;
173
174 bool has_fixed_end_point_position_ = false;
175
176 double weight_curve_length_ = 1.0;
177
178 double weight_kappa_ = 1.0;
179
180 double weight_dkappa_ = 1.0;
181};
182
183} // namespace planning
184} // namespace apollo
void set_start_point(const double x, const double y, const double theta, const double kappa, const double dkappa)
void set_element_weight_curve_length(const double weight_curve_length)
bool eval_f(int n, const double *x, bool new_x, double &obj_value) override
Method to return the objective value
void set_element_weight_kappa(const double weight_kappa)
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_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_grad_f(int n, const double *x, bool new_x, double *grad_f) override
Method to return the gradient of the objective
void set_end_point(const double x, const double y, const double theta, const double kappa, const double dkappa)
void set_default_max_point_deviation(const double point_max_deviation)
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(std::vector< double > *ptr_theta, std::vector< double > *ptr_kappa, std::vector< double > *ptr_dkappa, std::vector< double > *ptr_s, std::vector< double > *ptr_x, std::vector< double > *ptr_y) const
bool eval_g(int n, const double *x, bool new_x, int m, double *g) override
Method to return the constraint residuals
void set_element_weight_dkappa(const double weight_dkappa)
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 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
void set_end_point_position(const double x, const double y)
Planning module main class.
class register implement
Definition arena_queue.h:37