Apollo 10.0
自动驾驶开放平台
distance_approach_problem.cc
浏览该文件的文档.
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 * @file
19 */
20
22
23#include <string>
24#include <unordered_map>
25
27
28namespace apollo {
29namespace planning {
30
32 const PlannerOpenSpaceConfig& planner_open_space_config) {
33 planner_open_space_config_ = planner_open_space_config;
34}
35
37 const Eigen::MatrixXd& x0, const Eigen::MatrixXd& xF,
38 const Eigen::MatrixXd& last_time_u, const size_t horizon, const double ts,
39 const Eigen::MatrixXd& ego, const Eigen::MatrixXd& xWS,
40 const Eigen::MatrixXd& uWS, const Eigen::MatrixXd& l_warm_up,
41 const Eigen::MatrixXd& n_warm_up, const Eigen::MatrixXd& s_warm_up,
42 const std::vector<double>& XYbounds, const size_t obstacles_num,
43 const Eigen::MatrixXi& obstacles_edges_num,
44 const Eigen::MatrixXd& obstacles_A, const Eigen::MatrixXd& obstacles_b,
45 Eigen::MatrixXd* state_result, Eigen::MatrixXd* control_result,
46 Eigen::MatrixXd* time_result, Eigen::MatrixXd* dual_l_result,
47 Eigen::MatrixXd* dual_n_result) {
48 // TODO(QiL) : evaluate whether need to new it everytime
50
51 DistanceApproachInterface* ptop = nullptr;
52
53 if (planner_open_space_config_.distance_approach_config()
56 horizon, ts, ego, xWS, uWS, l_warm_up, n_warm_up, x0, xF, last_time_u,
57 XYbounds, obstacles_edges_num, obstacles_num, obstacles_A, obstacles_b,
58 planner_open_space_config_);
59 } else if (planner_open_space_config_.distance_approach_config()
63 horizon, ts, ego, xWS, uWS, l_warm_up, n_warm_up, x0, xF, last_time_u,
64 XYbounds, obstacles_edges_num, obstacles_num, obstacles_A, obstacles_b,
65 planner_open_space_config_);
66 } else if (planner_open_space_config_.distance_approach_config()
69 horizon, ts, ego, xWS, uWS, l_warm_up, n_warm_up, x0, xF, last_time_u,
70 XYbounds, obstacles_edges_num, obstacles_num, obstacles_A, obstacles_b,
71 planner_open_space_config_);
72 } else if (planner_open_space_config_.distance_approach_config()
76 horizon, ts, ego, xWS, uWS, l_warm_up, n_warm_up, x0, xF, last_time_u,
77 XYbounds, obstacles_edges_num, obstacles_num, obstacles_A, obstacles_b,
78 planner_open_space_config_);
79 } else if (planner_open_space_config_.distance_approach_config()
83 horizon, ts, ego, xWS, uWS, l_warm_up, n_warm_up, x0, xF, last_time_u,
84 XYbounds, obstacles_edges_num, obstacles_num, obstacles_A, obstacles_b,
85 planner_open_space_config_);
86 } else if (planner_open_space_config_.distance_approach_config()
90 horizon, ts, ego, xWS, uWS, l_warm_up, n_warm_up, s_warm_up, x0, xF,
91 last_time_u, XYbounds, obstacles_edges_num, obstacles_num, obstacles_A,
92 obstacles_b, planner_open_space_config_);
93 }
94
95 Ipopt::SmartPtr<Ipopt::TNLP> problem = ptop;
96
97 // Create an instance of the IpoptApplication
98 Ipopt::SmartPtr<Ipopt::IpoptApplication> app = IpoptApplicationFactory();
99
100 app->Options()->SetIntegerValue(
101 "print_level", planner_open_space_config_.distance_approach_config()
102 .ipopt_config()
104 app->Options()->SetIntegerValue(
105 "mumps_mem_percent", planner_open_space_config_.distance_approach_config()
106 .ipopt_config()
108 app->Options()->SetNumericValue(
109 "mumps_pivtol", planner_open_space_config_.distance_approach_config()
110 .ipopt_config()
111 .mumps_pivtol());
112 app->Options()->SetIntegerValue(
113 "max_iter", planner_open_space_config_.distance_approach_config()
114 .ipopt_config()
115 .ipopt_max_iter());
116 app->Options()->SetNumericValue(
117 "tol", planner_open_space_config_.distance_approach_config()
118 .ipopt_config()
119 .ipopt_tol());
120 app->Options()->SetNumericValue(
121 "acceptable_constr_viol_tol",
122 planner_open_space_config_.distance_approach_config()
123 .ipopt_config()
125 app->Options()->SetNumericValue(
126 "min_hessian_perturbation",
127 planner_open_space_config_.distance_approach_config()
128 .ipopt_config()
130 app->Options()->SetNumericValue(
131 "jacobian_regularization_value",
132 planner_open_space_config_.distance_approach_config()
133 .ipopt_config()
135 app->Options()->SetStringValue(
136 "print_timing_statistics",
137 planner_open_space_config_.distance_approach_config()
138 .ipopt_config()
140 app->Options()->SetStringValue(
141 "alpha_for_y", planner_open_space_config_.distance_approach_config()
142 .ipopt_config()
144 app->Options()->SetStringValue(
145 "recalc_y", planner_open_space_config_.distance_approach_config()
146 .ipopt_config()
147 .ipopt_recalc_y());
148 app->Options()->SetNumericValue(
149 "mu_init", planner_open_space_config_.distance_approach_config()
150 .ipopt_config()
151 .ipopt_mu_init());
152
153 Ipopt::ApplicationReturnStatus status = app->Initialize();
154 if (status != Ipopt::Solve_Succeeded) {
155 AERROR << "*** Distance Approach problem error during initialization!";
156 return false;
157 }
158
159 status = app->OptimizeTNLP(problem);
160
161 if (status == Ipopt::Solve_Succeeded ||
162 status == Ipopt::Solved_To_Acceptable_Level) {
163 // Retrieve some statistics about the solve
164 Ipopt::Index iter_count = app->Statistics()->IterationCount();
165 ADEBUG << "*** The problem solved in " << iter_count << " iterations!";
166
167 Ipopt::Number final_obj = app->Statistics()->FinalObjective();
168 ADEBUG << "*** The final value of the objective function is " << final_obj
169 << '.';
170
171 PERF_BLOCK_END("DistanceApproachProblemSolving");
172 } else {
173 /*
174 return detailed failure information,
175 reference resource: Ipopt::ApplicationReturnStatus, https://
176 www.coin-or.org/Doxygen/CoinAll/_ip_return_codes__inc_8h-source.html
177 */
178 std::unordered_map<int, std::string> failure_status = {
179 {0, "Solve_Succeeded"},
180 {1, "Solved_To_Acceptable_Level"},
181 {2, "Infeasible_Problem_Detected"},
182 {3, "Search_Direction_Becomes_Too_Small"},
183 {4, "Diverging_Iterates"},
184 {5, "User_Requested_Stop"},
185 {6, "Feasible_Point_Found"},
186 {-1, "Maximum_Iterations_Exceeded"},
187 {-2, "Restoration_Failed"},
188 {-3, "Error_In_Step_Computation"},
189 {-10, "Not_Enough_Degrees_Of_Freedom"},
190 {-11, "Invalid_Problem_Definition"},
191 {-12, "Invalid_Option"},
192 {-13, "Invalid_Number_Detected"},
193 {-100, "Unrecoverable_Exception"},
194 {-101, "NonIpopt_Exception_Thrown"},
195 {-102, "Insufficient_Memory"},
196 {-199, "Internal_Error"}};
197
198 if (!failure_status.count(static_cast<size_t>(status))) {
199 AINFO << "Solver ends with unknown failure code: "
200 << static_cast<int>(status);
201 } else {
202 AINFO << "Solver failure case: "
203 << failure_status[static_cast<size_t>(status)];
204 }
205 }
206
207 ptop->get_optimization_results(state_result, control_result, time_result,
208 dual_l_result, dual_n_result);
209
210 return status == Ipopt::Solve_Succeeded ||
211 status == Ipopt::Solved_To_Acceptable_Level;
212}
213
214} // namespace planning
215} // namespace apollo
virtual void get_optimization_results(Eigen::MatrixXd *state_result, Eigen::MatrixXd *control_result, Eigen::MatrixXd *time_result, Eigen::MatrixXd *dual_l_result, Eigen::MatrixXd *dual_n_result) const =0
DistanceApproachProblem(const PlannerOpenSpaceConfig &planner_open_space_config)
bool Solve(const Eigen::MatrixXd &x0, const Eigen::MatrixXd &xF, const Eigen::MatrixXd &last_time_u, const size_t horizon, const double ts, const Eigen::MatrixXd &ego, const Eigen::MatrixXd &xWS, const Eigen::MatrixXd &uWS, const Eigen::MatrixXd &l_warm_up, const Eigen::MatrixXd &n_warm_up, const Eigen::MatrixXd &s_warm_up, const std::vector< double > &XYbounds, const size_t obstacles_num, const Eigen::MatrixXi &obstacles_edges_num, const Eigen::MatrixXd &obstacles_A, const Eigen::MatrixXd &obstacles_b, Eigen::MatrixXd *state_result, Eigen::MatrixXd *control_result, Eigen::MatrixXd *time_result, Eigen::MatrixXd *dual_l_result, Eigen::MatrixXd *dual_n_result)
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37
#define PERF_BLOCK_START()
Definition perf_util.h:126
#define PERF_BLOCK_END
Definition profiler.h:53
optional DistanceApproachConfig distance_approach_config