Apollo 10.0
自动驾驶开放平台
apollo::planning::GridSearch类 参考

#include <grid_search.h>

apollo::planning::GridSearch 的协作图:

Public 成员函数

 GridSearch (const PlannerOpenSpaceConfig &open_space_conf)
 
virtual ~GridSearch ()=default
 
bool GenerateAStarPath (const double sx, const double sy, const double ex, const double ey, const std::vector< double > &XYbounds, const std::vector< std::vector< common::math::LineSegment2d > > &obstacles_linesegments_vec, GridAStartResult *result)
 
bool GenerateDpMap (const double ex, const double ey, const std::vector< double > &XYbounds, const std::vector< std::vector< common::math::LineSegment2d > > &obstacles_linesegments_vec, const std::vector< std::vector< common::math::LineSegment2d > > &soft_boundary_linesegments_vec={{}})
 
double CheckDpMap (const double sx, const double sy)
 
 GridSearch (const WarmStartConfig &warm_start_conf)
 
double GetObstacleDistance (const double x, const double y)
 

详细描述

在文件 grid_search.h 第 114 行定义.

构造及析构函数说明

◆ GridSearch() [1/2]

apollo::planning::GridSearch::GridSearch ( const PlannerOpenSpaceConfig &  open_space_conf)
explicit

在文件 grid_search.cc 第 28 行定义.

28 {
29 xy_grid_resolution_ =
30 open_space_conf.warm_start_config().grid_a_star_xy_resolution();
31 node_radius_ =
32 open_space_conf.warm_start_config().node_radius();
33}

◆ ~GridSearch()

virtual apollo::planning::GridSearch::~GridSearch ( )
virtualdefault

◆ GridSearch() [2/2]

apollo::planning::GridSearch::GridSearch ( const WarmStartConfig &  warm_start_conf)
explicit

成员函数说明

◆ CheckDpMap()

double apollo::planning::GridSearch::CheckDpMap ( const double  sx,
const double  sy 
)

在文件 grid_search.cc 第 226 行定义.

226 {
227 std::string index = Node2d::CalcIndex(sx, sy, xy_grid_resolution_, XYbounds_);
228 if (dp_map_.find(index) != dp_map_.end()) {
229 return dp_map_[index]->GetCost() * xy_grid_resolution_;
230 } else {
231 return std::numeric_limits<double>::infinity();
232 }
233}
static std::string CalcIndex(const double x, const double y, const double xy_resolution, const std::vector< double > &XYbounds)
Definition grid_search.h:80

◆ GenerateAStarPath()

bool apollo::planning::GridSearch::GenerateAStarPath ( const double  sx,
const double  sy,
const double  ex,
const double  ey,
const std::vector< double > &  XYbounds,
const std::vector< std::vector< common::math::LineSegment2d > > &  obstacles_linesegments_vec,
GridAStartResult *  result 
)

在文件 grid_search.cc 第 107 行定义.

112 {
113 std::priority_queue<std::pair<std::string, double>,
114 std::vector<std::pair<std::string, double>>, cmp>
115 open_pq;
116 std::unordered_map<std::string, std::shared_ptr<Node2d>> open_set;
117 std::unordered_map<std::string, std::shared_ptr<Node2d>> close_set;
118 XYbounds_ = XYbounds;
119 std::shared_ptr<Node2d> start_node =
120 std::make_shared<Node2d>(sx, sy, xy_grid_resolution_, XYbounds_);
121 std::shared_ptr<Node2d> end_node =
122 std::make_shared<Node2d>(ex, ey, xy_grid_resolution_, XYbounds_);
123 std::shared_ptr<Node2d> final_node_ = nullptr;
124 obstacles_linesegments_vec_ = obstacles_linesegments_vec;
125 open_set.emplace(start_node->GetIndex(), start_node);
126 open_pq.emplace(start_node->GetIndex(), start_node->GetCost());
127
128 // Grid a star begins
129 size_t explored_node_num = 0;
130 while (!open_pq.empty()) {
131 std::string current_id = open_pq.top().first;
132 open_pq.pop();
133 std::shared_ptr<Node2d> current_node = open_set[current_id];
134 // Check destination
135 if (*(current_node) == *(end_node)) {
136 final_node_ = current_node;
137 break;
138 }
139 close_set.emplace(current_node->GetIndex(), current_node);
140 std::vector<std::shared_ptr<Node2d>> next_nodes =
141 std::move(GenerateNextNodes(current_node));
142 for (auto& next_node : next_nodes) {
143 if (!CheckConstraints(next_node)) {
144 continue;
145 }
146 if (close_set.find(next_node->GetIndex()) != close_set.end()) {
147 continue;
148 }
149 if (open_set.find(next_node->GetIndex()) == open_set.end()) {
150 ++explored_node_num;
151 next_node->SetHeuristic(
152 EuclidDistance(next_node->GetGridX(), next_node->GetGridY(),
153 end_node->GetGridX(), end_node->GetGridY()));
154 next_node->SetPreNode(current_node);
155 open_set.emplace(next_node->GetIndex(), next_node);
156 open_pq.emplace(next_node->GetIndex(), next_node->GetCost());
157 }
158 }
159 }
160
161 if (final_node_ == nullptr) {
162 AERROR << "Grid A searching return null ptr(open_set ran out)";
163 return false;
164 }
165 LoadGridAStarResult(result);
166 ADEBUG << "explored node num is " << explored_node_num;
167 return true;
168}
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44

◆ GenerateDpMap()

bool apollo::planning::GridSearch::GenerateDpMap ( const double  ex,
const double  ey,
const std::vector< double > &  XYbounds,
const std::vector< std::vector< common::math::LineSegment2d > > &  obstacles_linesegments_vec,
const std::vector< std::vector< common::math::LineSegment2d > > &  soft_boundary_linesegments_vec = {{}} 
)

在文件 grid_search.cc 第 170 行定义.

177 {
178 std::priority_queue<std::pair<std::string, double>,
179 std::vector<std::pair<std::string, double>>, cmp>
180 open_pq;
181 std::unordered_map<std::string, std::shared_ptr<Node2d>> open_set;
182 dp_map_ = decltype(dp_map_)();
183 XYbounds_ = XYbounds;
184 // XYbounds with xmin, xmax, ymin, ymax
185 max_grid_y_ = std::round((XYbounds_[3] - XYbounds_[2]) / xy_grid_resolution_);
186 max_grid_x_ = std::round((XYbounds_[1] - XYbounds_[0]) / xy_grid_resolution_);
187 std::shared_ptr<Node2d> end_node =
188 std::make_shared<Node2d>(ex, ey, xy_grid_resolution_, XYbounds_);
189 obstacles_linesegments_vec_ = obstacles_linesegments_vec;
190 open_set.emplace(end_node->GetIndex(), end_node);
191 open_pq.emplace(end_node->GetIndex(), end_node->GetCost());
192
193 // Grid a star begins
194 size_t explored_node_num = 0;
195 while (!open_pq.empty()) {
196 const std::string current_id = open_pq.top().first;
197 open_pq.pop();
198 std::shared_ptr<Node2d> current_node = open_set[current_id];
199 dp_map_.emplace(current_node->GetIndex(), current_node);
200 std::vector<std::shared_ptr<Node2d>> next_nodes =
201 std::move(GenerateNextNodes(current_node));
202 for (auto& next_node : next_nodes) {
203 if (!CheckConstraints(next_node)) {
204 continue;
205 }
206 if (dp_map_.find(next_node->GetIndex()) != dp_map_.end()) {
207 continue;
208 }
209 if (open_set.find(next_node->GetIndex()) == open_set.end()) {
210 ++explored_node_num;
211 next_node->SetPreNode(current_node);
212 open_set.emplace(next_node->GetIndex(), next_node);
213 open_pq.emplace(next_node->GetIndex(), next_node->GetCost());
214 } else {
215 if (open_set[next_node->GetIndex()]->GetCost() > next_node->GetCost()) {
216 open_set[next_node->GetIndex()]->SetCost(next_node->GetCost());
217 open_set[next_node->GetIndex()]->SetPreNode(current_node);
218 }
219 }
220 }
221 }
222 ADEBUG << "explored node num is " << explored_node_num;
223 return true;
224}

◆ GetObstacleDistance()

double apollo::planning::GridSearch::GetObstacleDistance ( const double  x,
const double  y 
)

该类的文档由以下文件生成: