Astar astar; std::vector<std::vector<Node*>> paths(agvs.size()); // 得到agv的路綫 for (int i = 0; i < agvs.size(); i++) { Node* start_node = new Node(agvs[i].getCurrentX(), agvs[i].getCurrentY()); Node* end_node = new Node(agvs[i].getStartX(), agvs[i].getStartY()); Node* end_node1 = new Node(agvs[i].getEndX(), agvs[i].getEndY()); std::vector<Node*> path_to_start = astar.getPath(start_node, end_node); std::vector<Node*> path_to_end = astar.getPath(end_node, end_node1); // 去掉 end_node1 path_to_end.erase(path_to_end.begin()); std::vector<Node*> path; path.insert(path.end(), path_to_start.begin() + 1, path_to_start.end()); path.insert(path.end(), path_to_end.begin(), path_to_end.end()); paths[i] = path;,修改爲:判斷agv的load,如果是false,則將agv的current的坐標和任務的起點坐標輸入到getpath中,如果agv的load為true,則將agv的current的坐標和任務的終坐標輸入到getpath中
时间: 2023-11-22 16:53:05 浏览: 48
AStarPathFinder.rar_A * 算法_astar pathfinder_site:www.pudn.com
好的,那么您需要对代码做如下修改:
```
Astar astar;
std::vector<std::vector<Node*>> paths(agvs.size());
for (int i = 0; i < agvs.size(); i++) {
Node* start_node = new Node(agvs[i].getCurrentX(), agvs[i].getCurrentY());
Node* end_node;
if (!agvs[i].getLoad()) { // 如果load为false,将任务的起点作为终点
end_node = new Node(agvs[i].getStartX(), agvs[i].getStartY());
} else { // 如果load为true,将任务的终点作为终点
end_node = new Node(agvs[i].getEndX(), agvs[i].getEndY());
}
std::vector<Node*> path = astar.getPath(start_node, end_node); // 直接得到路径
paths[i] = path;
}
```
这样修改后,当`agv`的`load`为`false`时,`end_node`就是任务的起点;当`agv`的`load`为`true`时,`end_node`就是任务的终点。然后直接调用`astar.getPath`函数,得到路径并存储到`paths`中。
阅读全文