Apollo 11.0
自动驾驶开放平台
fem_pos_deviation_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 <utility>
20#include <vector>
21
22#include <adolc/adolc.h>
23#include <adolc/adolc_sparse.h>
24#include <adolc/adouble.h>
25#include <coin/IpIpoptApplication.hpp>
26#include <coin/IpIpoptCalculatedQuantities.hpp>
27#include <coin/IpIpoptData.hpp>
28#include <coin/IpOrigIpoptNLP.hpp>
29#include <coin/IpSolveStatistics.hpp>
30#include <coin/IpTNLP.hpp>
31#include <coin/IpTNLPAdapter.hpp>
32#include <coin/IpTypes.hpp>
33
34#define tag_f 1
35#define tag_g 2
36#define tag_L 3
37#define HPOFF 30
38
39namespace apollo {
40namespace planning {
41
42class FemPosDeviationIpoptInterface : public Ipopt::TNLP {
43 public:
44 FemPosDeviationIpoptInterface(std::vector<std::pair<double, double>> points,
45 std::vector<double> bounds);
46
47 virtual ~FemPosDeviationIpoptInterface() = default;
48
49 void set_weight_fem_pos_deviation(const double weight_fem_pos_deviation) {
50 weight_fem_pos_deviation_ = weight_fem_pos_deviation;
51 }
52
53 void set_weight_path_length(const double weight_path_length) {
54 weight_path_length_ = weight_path_length;
55 }
56
57 void set_weight_ref_deviation(const double weight_ref_deviation) {
58 weight_ref_deviation_ = weight_ref_deviation;
59 }
60
62 const double weight_curvature_constraint_slack_var) {
63 weight_curvature_constraint_slack_var_ =
64 weight_curvature_constraint_slack_var;
65 }
66
67 void set_curvature_constraint(const double curvature_constraint) {
68 curvature_constraint_ = curvature_constraint;
69 }
70
71 void get_optimization_results(std::vector<double>* ptr_x,
72 std::vector<double>* ptr_y) const;
73
75 bool get_nlp_info(int& n, int& m, int& nnz_jac_g, int& nnz_h_lag,
76 IndexStyleEnum& index_style) override;
77
79 bool get_bounds_info(int n, double* x_l, double* x_u, int m, double* g_l,
80 double* g_u) override;
81
83 bool get_starting_point(int n, bool init_x, double* x, bool init_z,
84 double* z_L, double* z_U, int m, bool init_lambda,
85 double* lambda) override;
86
88 bool eval_f(int n, const double* x, bool new_x, double& obj_value) override;
89
91 bool eval_grad_f(int n, const double* x, bool new_x, double* grad_f) override;
92
94 bool eval_g(int n, const double* x, bool new_x, int m, double* g) override;
95
100 bool eval_jac_g(int n, const double* x, bool new_x, int m, int nele_jac,
101 int* iRow, int* jCol, double* values) override;
102
108 bool eval_h(int n, const double* x, bool new_x, double obj_factor, int m,
109 const double* lambda, bool new_lambda, int nele_hess, int* iRow,
110 int* jCol, double* values) override;
111
115 void finalize_solution(Ipopt::SolverReturn status, int n, const double* x,
116 const double* z_L, const double* z_U, int m,
117 const double* g, const double* lambda,
118 double obj_value, const Ipopt::IpoptData* ip_data,
119 Ipopt::IpoptCalculatedQuantities* ip_cq) override;
120
121 //*************** start ADOL-C part ***********************************
122
124 template <class T>
125 bool eval_obj(int n, const T* x, T* obj_value);
126
128 template <class T>
129 bool eval_constraints(int n, const T* x, int m, T* g);
130
132 virtual void generate_tapes(int n, int m, int* nnz_jac_g, int* nnz_h_lag);
133
134 //*************** end ADOL-C part ***********************************
135
136 private:
137 // Reference points and deviation bounds
138 std::vector<std::pair<double, double>> ref_points_;
139 std::vector<double> bounds_around_refs_;
140
141 // Weights in optimization cost function
142 double weight_fem_pos_deviation_ = 1.0e8;
143 double weight_path_length_ = 1.0;
144 double weight_ref_deviation_ = 1.0;
145 double weight_curvature_constraint_slack_var_ = 1.0e2;
146
147 double curvature_constraint_ = 0.2;
148
149 size_t num_of_variables_ = 0;
150 size_t num_of_constraints_ = 0;
151 size_t nnz_jac_g_ = 0;
152 size_t nnz_h_lag_ = 0;
153 size_t num_of_points_ = 0;
154 size_t num_of_slack_var_ = 0;
155 size_t num_of_curvature_constr_ = 0;
156 size_t num_of_slack_constr_ = 0;
157
158 size_t slack_var_start_index_ = 0;
159 size_t slack_var_end_index_ = 0;
160 size_t curvature_constr_start_index_ = 0;
161 size_t curvature_constr_end_index_ = 0;
162 size_t slack_constr_start_index_ = 0;
163 size_t slack_constr_end_index_ = 0;
164
165 std::vector<double> opt_x_;
166 std::vector<double> opt_y_;
167
168 //*************** start ADOL-C part ***********************************
169
175
176 std::vector<double> obj_lam_;
177
178 //** variables for sparsity exploitation
179 unsigned int* rind_g_; /* row indices */
180 unsigned int* cind_g_; /* column indices */
181 double* jacval_; /* values */
182 unsigned int* rind_L_; /* row indices */
183 unsigned int* cind_L_; /* column indices */
184 double* hessval_; /* values */
185
186 int nnz_jac_ = 0;
187 int nnz_L_ = 0;
188 int options_g_[4];
189 int options_L_[4];
190
191 //*************** end ADOL-C part ***********************************
192};
193} // namespace planning
194} // namespace apollo
void set_weight_fem_pos_deviation(const double weight_fem_pos_deviation)
void get_optimization_results(std::vector< double > *ptr_x, std::vector< double > *ptr_y) const
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
void set_weight_ref_deviation(const double weight_ref_deviation)
bool eval_g(int n, const double *x, bool new_x, int m, double *g) override
Method to return the constraint residuals
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_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
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_weight_curvature_constraint_slack_var(const double weight_curvature_constraint_slack_var)
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_constraints(int n, const T *x, int m, T *g)
Template to compute contraints
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_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 set_curvature_constraint(const double curvature_constraint)
virtual void generate_tapes(int n, int m, int *nnz_jac_g, int *nnz_h_lag)
Method to generate the required tapes
bool eval_f(int n, const double *x, bool new_x, double &obj_value) override
Method to return the objective value
Planning module main class.
class register implement
Definition arena_queue.h:37