Apollo 11.0
自动驾驶开放平台
cruise_scenario_features.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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 <memory>
20#include <queue>
21#include <utility>
22
24
25namespace apollo {
26namespace prediction {
27
29using ConstLaneInfoPtr = std::shared_ptr<const LaneInfo>;
31
35
37
39 const std::string& lane_id) const {
40 return lane_ids_of_interest_.find(lane_id) != lane_ids_of_interest_.end();
41}
42
43void CruiseScenarioFeatures::InsertLaneOfInterest(const std::string& lane_id) {
44 lane_ids_of_interest_.insert(lane_id);
45}
46
48 const EnvironmentFeatures& environment_features) {
49 // Forward lanes
50 if (environment_features.has_ego_lane()) {
51 auto ego_lane = environment_features.GetEgoLane();
52 const std::string& ego_lane_id = ego_lane.first;
53 double ego_lane_s = ego_lane.second;
54 SearchForwardAndInsert(ego_lane_id, ego_lane_s, 50.0);
55 }
56 if (environment_features.has_left_neighbor_lane()) {
57 auto left_lane = environment_features.GetLeftNeighborLane();
58 const std::string& left_lane_id = left_lane.first;
59 double left_lane_s = left_lane.second;
60 SearchForwardAndInsert(left_lane_id, left_lane_s, 50.0);
61 }
62 if (environment_features.has_right_neighbor_lane()) {
63 auto right_lane = environment_features.GetRightNeighborLane();
64 const std::string& right_lane_id = right_lane.first;
65 double right_lane_s = right_lane.second;
66 SearchForwardAndInsert(right_lane_id, right_lane_s, 50.0);
67 }
68
69 // Reverse lanes
70 const std::unordered_set<std::string>& reverse_lane_ids =
71 environment_features.nonneglectable_reverse_lanes();
72 if (reverse_lane_ids.empty()) {
73 ADEBUG << "No reverse lane considered";
74 }
75 for (const std::string& reverse_lane_id : reverse_lane_ids) {
76 lane_ids_of_interest_.insert(reverse_lane_id);
77 }
78 for (const std::string& reverse_lane_id : reverse_lane_ids) {
79 std::shared_ptr<const LaneInfo> reverse_lane_info =
80 PredictionMap::LaneById(reverse_lane_id);
81 for (const auto& prede_id : reverse_lane_info->lane().predecessor_id()) {
82 lane_ids_of_interest_.insert(prede_id.id());
83 }
84 }
85}
86
87void CruiseScenarioFeatures::SearchForwardAndInsert(
88 const std::string& start_lane_id, const double start_lane_s,
89 const double range) {
90 ConstLaneInfoPtr start_lane_info = PredictionMap::LaneById(start_lane_id);
91 double start_lane_length = start_lane_info->total_length();
92 double start_accumulated_s = start_lane_length - start_lane_s;
93 std::queue<std::pair<ConstLaneInfoPtr, double>> lane_queue;
94 lane_queue.emplace(start_lane_info, start_accumulated_s);
95
96 while (!lane_queue.empty()) {
97 ConstLaneInfoPtr lane_info = lane_queue.front().first;
98 double accumulated_s = lane_queue.front().second;
99 lane_queue.pop();
100 InsertLaneOfInterest(lane_info->id().id());
101 const Lane& lane = lane_info->lane();
102 for (const auto prede_lane_id : lane.predecessor_id()) {
103 InsertLaneOfInterest(prede_lane_id.id());
104 }
105 if (accumulated_s > range) {
106 continue;
107 }
108 for (const auto succ_lane_id : lane.successor_id()) {
109 ConstLaneInfoPtr succ_lane_info =
110 PredictionMap::LaneById(succ_lane_id.id());
111 double succ_lane_length = succ_lane_info->total_length();
112 lane_queue.emplace(succ_lane_info, accumulated_s + succ_lane_length);
113 }
114 }
115}
116
117} // namespace prediction
118} // namespace apollo
void BuildCruiseScenarioFeatures(const EnvironmentFeatures &environment_features)
bool IsLaneOfInterest(const std::string &lane_id) const
void InsertLaneOfInterest(const std::string &lane_id)
std::pair< std::string, double > GetLeftNeighborLane() const
std::pair< std::string, double > GetRightNeighborLane() const
const std::unordered_set< std::string > & nonneglectable_reverse_lanes() const
std::pair< std::string, double > GetEgoLane() const
static std::shared_ptr< const hdmap::LaneInfo > LaneById(const std::string &id)
Get a shared pointer to a lane by lane ID.
#define ADEBUG
Definition log.h:41
std::shared_ptr< const LaneInfo > ConstLaneInfoPtr
class register implement
Definition arena_queue.h:37