// 得到agv的路綫 for (int i = 0; i < agvs.size(); i++) { if (agvs[i].getLoad() == true) { // 如果是负载的状态 if (agvs[i].getCurrentX() == agvs[i].getEndX() && agvs[i].getCurrentY() == agvs[i].getEndY()) { // 如果到达终点 agvs[i].setLoad(false); // 设置为空载状态 agvs[i].setState(true);//agv設置為可用狀態 std::cout << "agv__id :" << agvs[i].getid() << " ,agv_get_task_id :" << agvs[i].get_task_id() << endl; for (int j = 0; j < tasks.size(); j++) { if (tasks[j].id == agvs[i].get_task_id()) { completed_task_index = j; break; } } if (completed_task_index != -1) { tasks[completed_task_index].completed = 2; } task_to_agv(); // 更新任务分配 update(); // 更新AGV状态 } else { // 否则行驶到终点 Node* start_node = new Node(agvs[i].getCurrentX(), agvs[i].getCurrentY()); Node* end_node1 = new Node(agvs[i].getEndX(), agvs[i].getEndY()); std::vector<Node*> path = astar.getPath(start_node, end_node1); path.erase(path.begin()); paths[i] = path; } } else { // 如果是空载的状态 if (agvs[i].getCurrentX() == agvs[i].getStartX() && agvs[i].getCurrentY() == agvs[i].getStartY()) { // 如果到达起点 agvs[i].setLoad(true); // 设置为负载状态 } else { // 否则行驶到起点 Node* start_node = new Node(agvs[i].getCurrentX(), agvs[i].getCurrentY()); Node* end_node = new Node(agvs[i].getStartX(), agvs[i].getStartY()); std::vector<Node*> path = astar.getPath(start_node, end_node); path.erase(path.begin()); paths[i] = path; } } },添加代碼:添加首要條件,agv對應的task的completed是1則執行,反之跳出
时间: 2024-01-26 18:02:40 浏览: 64
AGVS.rar_AGVS调度_gulf5j4_scheduling AGV_wpf agv调度系统_调度控制
5星 · 资源好评率100%
你可以在代码中添加以下条件来判断是否执行任务:
```
if (tasks[agvs[i].get_task_id()].completed == 1) {
// 执行任务
} else {
continue; // 跳出循环,继续下一个 AGV
}
```
这样,当 AGV 对应的任务已经完成时,就不会继续执行该任务。你可以将此条件添加到 `if (agvs[i].getLoad() == true)` 的条件判断中。完整的代码如下所示:
```
for (int i = 0; i < agvs.size(); i++) {
if (agvs[i].getLoad() == true) {
// 如果是负载的状态
if (agvs[i].getCurrentX() == agvs[i].getEndX() && agvs[i].getCurrentY() == agvs[i].getEndY()) {
// 如果到达终点
agvs[i].setLoad(false); // 设置为空载状态
agvs[i].setState(true);//agv設置為可用狀態
std::cout << "agv__id :" << agvs[i].getid() << " ,agv_get_task_id :" << agvs[i].get_task_id() << endl;
int completed_task_index = -1;
for (int j = 0; j < tasks.size(); j++) {
if (tasks[j].id == agvs[i].get_task_id()) {
completed_task_index = j;
break;
}
}
if (completed_task_index != -1) {
tasks[completed_task_index].completed = 2;
}
task_to_agv(); // 更新任务分配
update(); // 更新AGV状态
if (tasks[agvs[i].get_task_id()].completed == 1) {
// 执行任务
} else {
continue; // 跳出循环,继续下一个 AGV
}
} else {
// 否则行驶到终点
Node* start_node = new Node(agvs[i].getCurrentX(), agvs[i].getCurrentY());
Node* end_node1 = new Node(agvs[i].getEndX(), agvs[i].getEndY());
std::vector<Node*> path = astar.getPath(start_node, end_node1);
path.erase(path.begin());
paths[i] = path;
}
} else {
// 如果是空载的状态
if (agvs[i].getCurrentX() == agvs[i].getStartX() && agvs[i].getCurrentY() == agvs[i].getStartY()) {
// 如果到达起点
agvs[i].setLoad(true); // 设置为负载状态
} else {
// 否则行驶到起点
Node* start_node = new Node(agvs[i].getCurrentX(), agvs[i].getCurrentY());
Node* end_node = new Node(agvs[i].getStartX(), agvs[i].getStartY());
std::vector<Node*> path = astar.getPath(start_node, end_node);
path.erase(path.begin());
paths[i] = path;
}
}
}
```
阅读全文