Apollo 10.0
自动驾驶开放平台
black_list_range_generator.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
18
19namespace apollo {
20namespace routing {
21
22constexpr double S_GAP_FOR_BLACK = 0.01;
23
24namespace {
25
26double MoveSForward(double s, double upper_bound) {
27 if (s > upper_bound) {
28 AERROR << "Illegal s: " << s << ", upper bound: " << upper_bound;
29 return s;
30 }
31 if (s + S_GAP_FOR_BLACK < upper_bound) {
32 return (s + S_GAP_FOR_BLACK);
33 } else {
34 return ((s + upper_bound) / 2.0);
35 }
36}
37
38double MoveSBackward(double s, double lower_bound) {
39 if (s < lower_bound) {
40 AERROR << "Illegal s: " << s << ", lower bound: " << lower_bound;
41 return s;
42 }
43 if (s - S_GAP_FOR_BLACK > lower_bound) {
44 return (s - S_GAP_FOR_BLACK);
45 } else {
46 return ((s + lower_bound) / 2.0);
47 }
48}
49
50void GetOutParallelLane(const TopoNode* node,
51 std::unordered_set<const TopoNode*>* const node_set) {
52 for (const auto* edge : node->OutToLeftOrRightEdge()) {
53 const auto* to_node = edge->ToNode();
54 if (node_set->count(to_node) == 0) {
55 node_set->emplace(to_node);
56 GetOutParallelLane(to_node, node_set);
57 }
58 }
59}
60
61void GetInParallelLane(const TopoNode* node,
62 std::unordered_set<const TopoNode*>* const node_set) {
63 for (const auto* edge : node->InFromLeftOrRightEdge()) {
64 const auto* from_node = edge->FromNode();
65 if (node_set->count(from_node) == 0) {
66 node_set->emplace(from_node);
67 GetInParallelLane(from_node, node_set);
68 }
69 }
70}
71
72// for new navigator
73void AddBlackMapFromRoad(const routing::RoutingRequest& request,
74 const TopoGraph* graph,
75 TopoRangeManager* const range_manager) {
76 for (const auto& road_id : request.blacklisted_road()) {
77 std::unordered_set<const TopoNode*> road_nodes_set;
78 graph->GetNodesByRoadId(road_id, &road_nodes_set);
79 for (const auto& node : road_nodes_set) {
80 range_manager->Add(node, 0.0, node->Length());
81 }
82 }
83}
84
85// for new navigator
86void AddBlackMapFromLane(const routing::RoutingRequest& request,
87 const TopoGraph* graph,
88 TopoRangeManager* const range_manager) {
89 for (const auto& lane : request.blacklisted_lane()) {
90 const auto* node = graph->GetNode(lane.id());
91 if (node) {
92 range_manager->Add(node, lane.start_s(), lane.end_s());
93 }
94 }
95}
96
97void AddBlackMapFromOutParallel(const TopoNode* node, double cut_ratio,
98 TopoRangeManager* const range_manager) {
99 std::unordered_set<const TopoNode*> par_node_set;
100 GetOutParallelLane(node, &par_node_set);
101 par_node_set.erase(node);
102 for (const auto* par_node : par_node_set) {
103 double par_cut_s = cut_ratio * par_node->Length();
104 range_manager->Add(par_node, par_cut_s, par_cut_s);
105 }
106}
107
108void AddBlackMapFromInParallel(const TopoNode* node, double cut_ratio,
109 TopoRangeManager* const range_manager) {
110 std::unordered_set<const TopoNode*> par_node_set;
111 GetInParallelLane(node, &par_node_set);
112 par_node_set.erase(node);
113 for (const auto* par_node : par_node_set) {
114 double par_cut_s = cut_ratio * par_node->Length();
115 range_manager->Add(par_node, par_cut_s, par_cut_s);
116 }
117}
118
119} // namespace
120
122 const routing::RoutingRequest& request, const TopoGraph* graph,
123 TopoRangeManager* const range_manager) const {
124 AddBlackMapFromLane(request, graph, range_manager);
125 AddBlackMapFromRoad(request, graph, range_manager);
126 range_manager->SortAndMerge();
127}
128
130 const TopoNode* src_node, const TopoNode* dest_node, double start_s,
131 double end_s, TopoRangeManager* const range_manager) const {
132 double start_length = src_node->Length();
133 double end_length = dest_node->Length();
134
135 static constexpr double kEpsilon = 1e-2;
136 const double start_s_adjusted =
137 (start_s > start_length && start_s - start_length <= kEpsilon)
138 ? start_length
139 : start_s;
140 const double end_s_adjusted =
141 (end_s > end_length && end_s - end_length <= kEpsilon) ? end_length
142 : end_s;
143
144 if (start_s_adjusted < 0.0 || start_s_adjusted > start_length) {
145 AERROR << "Illegal start_s: " << start_s << ", length: " << start_length;
146 return;
147 }
148 if (end_s_adjusted < 0.0 || end_s_adjusted > end_length) {
149 AERROR << "Illegal end_s: " << end_s << ", length: " << end_length;
150 return;
151 }
152
153 double start_cut_s = MoveSBackward(start_s_adjusted, 0.0);
154 range_manager->Add(src_node, start_cut_s, start_cut_s);
155 AddBlackMapFromOutParallel(src_node, start_cut_s / start_length,
156 range_manager);
157
158 double end_cut_s = MoveSForward(end_s_adjusted, end_length);
159 range_manager->Add(dest_node, end_cut_s, end_cut_s);
160 AddBlackMapFromInParallel(dest_node, end_cut_s / end_length, range_manager);
161 range_manager->SortAndMerge();
162}
163
164} // namespace routing
165} // namespace apollo
void AddBlackMapFromTerminal(const TopoNode *src_node, const TopoNode *dest_node, double start_s, double end_s, TopoRangeManager *const range_manager) const
void GenerateBlackMapFromRequest(const routing::RoutingRequest &request, const TopoGraph *graph, TopoRangeManager *const range_manager) const
void GetNodesByRoadId(const std::string &road_id, std::unordered_set< const TopoNode * > *const node_in_road) const
Definition topo_graph.cc:99
const TopoNode * GetNode(const std::string &id) const
Definition topo_graph.cc:91
const std::unordered_set< const TopoEdge * > & OutToLeftOrRightEdge() const
Definition topo_node.cc:213
const std::unordered_set< const TopoEdge * > & InFromLeftOrRightEdge() const
Definition topo_node.cc:192
void Add(const TopoNode *node, double start_s, double end_s)
#define AERROR
Definition log.h:44
constexpr double S_GAP_FOR_BLACK
class register implement
Definition arena_queue.h:37
repeated apollo::routing::LaneSegment blacklisted_lane
Definition routing.proto:15