Apollo 11.0
自动驾驶开放平台
cos_theta_smoother.cc
浏览该文件的文档.
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
18
19#include <coin/IpIpoptApplication.hpp>
20#include <coin/IpSolveStatistics.hpp>
21
22#include "cyber/common/log.h"
24
25namespace apollo {
26namespace planning {
28 : config_(config) {}
29
31 const std::vector<std::pair<double, double>>& raw_point2d,
32 const std::vector<double>& bounds, std::vector<double>* opt_x,
33 std::vector<double>* opt_y) {
34 const double weight_cos_included_angle = config_.weight_cos_included_angle();
35 const double weight_anchor_points = config_.weight_anchor_points();
36 const double weight_length = config_.weight_length();
37 const size_t print_level = config_.print_level();
38 const size_t max_num_of_iterations = config_.max_num_of_iterations();
39 const size_t acceptable_num_of_iterations =
41 const double tol = config_.tol();
42 const double acceptable_tol = config_.acceptable_tol();
43 const bool use_automatic_differentiation =
45
46 CosThetaIpoptInterface* smoother =
47 new CosThetaIpoptInterface(raw_point2d, bounds);
48
49 smoother->set_weight_cos_included_angle(weight_cos_included_angle);
50 smoother->set_weight_anchor_points(weight_anchor_points);
51 smoother->set_weight_length(weight_length);
52 smoother->set_automatic_differentiation_flag(use_automatic_differentiation);
53
54 Ipopt::SmartPtr<Ipopt::TNLP> problem = smoother;
55
56 // Create an instance of the IpoptApplication
57 Ipopt::SmartPtr<Ipopt::IpoptApplication> app = IpoptApplicationFactory();
58
59 app->Options()->SetIntegerValue("print_level", static_cast<int>(print_level));
60 app->Options()->SetIntegerValue("max_iter",
61 static_cast<int>(max_num_of_iterations));
62 app->Options()->SetIntegerValue(
63 "acceptable_iter", static_cast<int>(acceptable_num_of_iterations));
64 app->Options()->SetNumericValue("tol", tol);
65 app->Options()->SetNumericValue("acceptable_tol", acceptable_tol);
66
67 Ipopt::ApplicationReturnStatus status = app->Initialize();
68 if (status != Ipopt::Solve_Succeeded) {
69 AERROR << "*** Error during initialization!";
70 return false;
71 }
72
73 status = app->OptimizeTNLP(problem);
74
75 if (status == Ipopt::Solve_Succeeded ||
76 status == Ipopt::Solved_To_Acceptable_Level) {
77 // Retrieve some statistics about the solve
78 Ipopt::Index iter_count = app->Statistics()->IterationCount();
79 ADEBUG << "*** The problem solved in " << iter_count << " iterations!";
80 } else {
81 AERROR << "Solver fails with return code: " << static_cast<int>(status);
82 return false;
83 }
84 smoother->get_optimization_results(opt_x, opt_y);
85 return true;
86}
87} // namespace planning
88} // namespace apollo
void set_weight_length(const double weight_length)
void set_weight_cos_included_angle(const double weight_cos_included_angle)
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)
CosThetaSmoother(const CosThetaSmootherConfig &config)
bool Solve(const std::vector< std::pair< double, double > > &raw_point2d, const std::vector< double > &bounds, std::vector< double > *opt_x, std::vector< double > *opt_y)
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
class register implement
Definition arena_queue.h:37