2026.2.9 小车避让

This commit is contained in:
1009473166@qq.com
2026-02-09 22:10:59 +08:00
parent 93da2f1cd0
commit cbc76be62f
2 changed files with 82 additions and 106 deletions

View File

@@ -99,17 +99,10 @@ public class PathFinder {
Collections.reverse(path); Collections.reverse(path);
return path; return path;
} }
/** /**
* 使用 A* 算法查找从起点到终点的最短路径。 * 使用 A* 算法查找从起点到终点的最短路径。
* *
@@ -203,7 +196,9 @@ public class PathFinder {
// 如果终点不可达 // 如果终点不可达
if (gCost[endX][endY] == Integer.MAX_VALUE) { if (gCost[endX][endY] == Integer.MAX_VALUE) {
return null; List<int[]> path = new ArrayList<>();
path.add(new int[]{-1, -1});
return path;
} }
// 回溯路径 // 回溯路径
@@ -272,14 +267,6 @@ public class PathFinder {
} }
/** /**
* 提取路径中的拐点(1→2 或 2→1 的边界点) * 提取路径中的拐点(1→2 或 2→1 的边界点)
* *
@@ -315,15 +302,12 @@ public class PathFinder {
List<int[]> collect = inflectionPoints.stream().distinct().collect(Collectors.toList()); List<int[]> collect = inflectionPoints.stream().distinct().collect(Collectors.toList());
return collect; return collect;
} }
/** /**
* 使用 BFS 查找从起点开始,路径上所有点的值为 2,直到终点(值为 1 或 2)的最短路径。 * 使用 BFS 查找从起点开始,路径上所有点的值为 2,直到终点(值为 1 或 2)的最短路径。
* *
@@ -398,9 +382,6 @@ public class PathFinder {
} }
/** /**
* 提取路径中的拐点: * 提取路径中的拐点:
* - 区域类型转换点(1 ↔ 2) * - 区域类型转换点(1 ↔ 2)
@@ -488,7 +469,7 @@ public class PathFinder {
* 按算法查找多个目标点(原点)的最优路径 * 按算法查找多个目标点(原点)的最优路径
* *
* */ * */
public static Site findOptimalCarWithObstacles(int[][] grid, Site srcSite, List<Site> tarSites){ public static Site findOptimalCarWithObstacles(int[][] grid, Site srcSite, List<Site> tarSites) {
//所有车先都设置为障碍 //所有车先都设置为障碍
tarSites.forEach(site -> { tarSites.forEach(site -> {
int[] pos = site.getStartPoint(); int[] pos = site.getStartPoint();
@@ -507,7 +488,6 @@ public class PathFinder {
} }
// 计算路径 // 计算路径
List<int[]> path = findShortestPath(grid, startPoint[0], startPoint[1], srcSite.getStartPoint()[0], srcSite.getStartPoint()[1]); List<int[]> path = findShortestPath(grid, startPoint[0], startPoint[1], srcSite.getStartPoint()[0], srcSite.getStartPoint()[1]);
if (path == null) { if (path == null) {
@@ -515,7 +495,6 @@ public class PathFinder {
} }
// 检查路径冲突 // 检查路径冲突
boolean blocked = tarSites.stream() boolean blocked = tarSites.stream()
.filter(other -> other != car) .filter(other -> other != car)
@@ -552,7 +531,7 @@ public class PathFinder {
* 载货查找最佳,使用情景 * 载货查找最佳,使用情景
* *
* */ * */
public static Site findOptimalWithCargo(int[][] grid, Site srcSite, List<Site> tarSites){ public static Site findOptimalWithCargo(int[][] grid, Site srcSite, List<Site> tarSites) {
// 并行计算所有车辆的路径 // 并行计算所有车辆的路径
Map<Site, PathInfo> carPathInfo = tarSites.parallelStream() Map<Site, PathInfo> carPathInfo = tarSites.parallelStream()
@@ -572,7 +551,6 @@ public class PathFinder {
} }
// 检查路径冲突 // 检查路径冲突
boolean blocked = tarSites.stream() boolean blocked = tarSites.stream()
.filter(other -> other != car) .filter(other -> other != car)
@@ -605,13 +583,12 @@ public class PathFinder {
} }
/* /*
* 空载查找最佳,使用情景 * 空载查找最佳,使用情景
* 小车不载货,一个原点(目标点),多个目标点(原点) * 小车不载货,一个原点(目标点),多个目标点(原点)
* *
* */ * */
public static Site findOptimalWithNoCargo(int[][] grid, Site srcSite, List<Site> tarSites){ public static Site findOptimalWithNoCargo(int[][] grid, Site srcSite, List<Site> tarSites) {
// 并行计算所有车辆的路径 // 并行计算所有车辆的路径
@@ -625,7 +602,6 @@ public class PathFinder {
} }
// 计算路径 // 计算路径
List<int[]> path = findShortestPath(grid, startPoint[0], startPoint[1], srcSite.getStartPoint()[0], srcSite.getStartPoint()[1]); List<int[]> path = findShortestPath(grid, startPoint[0], startPoint[1], srcSite.getStartPoint()[0], srcSite.getStartPoint()[1]);
if (path == null) { if (path == null) {
@@ -634,7 +610,6 @@ public class PathFinder {
} }
// 检查路径冲突 // 检查路径冲突
boolean blocked = tarSites.stream() boolean blocked = tarSites.stream()
.filter(other -> other != car) .filter(other -> other != car)
@@ -669,7 +644,6 @@ public class PathFinder {
} }
/* /*
* *
* 同层多车选择最优 * 同层多车选择最优
@@ -743,9 +717,6 @@ public class PathFinder {
} }
public static Site findOptimalCarForDestinationByFull( public static Site findOptimalCarForDestinationByFull(
int[][] grid, int endX, int endY, List<Site> cars) { int[][] grid, int endX, int endY, List<Site> cars) {
// 创建网格副本 // 创建网格副本
@@ -878,7 +849,4 @@ public class PathFinder {
} }
} }

View File

@@ -570,6 +570,16 @@ public class BaseSRgvThread implements Runnable, SRgvThreadInterface {
// endSite="07050"+deviceSrgv.getCurrFloor(); // endSite="07050"+deviceSrgv.getCurrFloor();
// } // }
// //
//处理地图
int[][] emptyMap = roadCacheService.handleMap(arrByRoadSite, deviceSrgv);
//计算最短路径
List<int[]> shortestPath = PathFinder.findShortestPath(emptyMap, arrByRoadSite.get(startSite).getX(), arrByRoadSite.get(startSite).getY(), arrByRoadSite.get(endSite).getX(), arrByRoadSite.get(endSite).getY());
if (shortestPath.size() == 1 && shortestPath.get(0)[0] == -1 && shortestPath.get(0)[1] == -1) {
shortestPath = null;
String endBlockAgv = null; String endBlockAgv = null;
DeviceSrgv endBlockDevice = null; DeviceSrgv endBlockDevice = null;
// TODO 通过arrByRoadSite 中的站点 查询是否存在其他车的站点,如果存在则生成其他车到避让点的队列 // TODO 通过arrByRoadSite 中的站点 查询是否存在其他车的站点,如果存在则生成其他车到避让点的队列
@@ -618,8 +628,8 @@ public class BaseSRgvThread implements Runnable, SRgvThreadInterface {
taskB.setExecutionStatus("1");// 初始状态 taskB.setExecutionStatus("1");// 初始状态
taskB.setStartSite(endBlockDevice.getCurrSite()); taskB.setStartSite(endBlockDevice.getCurrSite());
taskB.setCargoPickSite(endBlockDevice.getCurrSite()); taskB.setCargoPickSite(endBlockDevice.getCurrSite());
taskB.setCargoPlaceSite("05020"+endBlockDevice.getCurrFloor()); taskB.setCargoPlaceSite("05020" + endBlockDevice.getCurrFloor());
taskB.setEndSite("05020"+endBlockDevice.getCurrFloor()); taskB.setEndSite("05020" + endBlockDevice.getCurrFloor());
taskB.setTheFloor(floor.toString()); taskB.setTheFloor(floor.toString());
taskB.setDefault03(endBlockDevice.getCurrSite()); taskB.setDefault03(endBlockDevice.getCurrSite());
taskB.setDefault07(floor.toString()); taskB.setDefault07(floor.toString());
@@ -627,16 +637,12 @@ public class BaseSRgvThread implements Runnable, SRgvThreadInterface {
taskB.setCreateDate(DateUtil.now()); taskB.setCreateDate(DateUtil.now());
wcsSagvQueueMapper.insertWcsSrgvQueue(taskB); wcsSagvQueueMapper.insertWcsSrgvQueue(taskB);
taskCache++; taskCache++;
log.info("目标点 {} 被小车 {} 占用,已调度其前往避让点 {}", endSite, endBlockAgv, "02050"+endBlockDevice.getCurrFloor()); log.info("目标点 {" + deviceSrgv.getCurrSite() + "} 被小车 {" + deviceSrgv.getDeviceId() + "} 占用,已调度其前往避让点 {}", endSite, endBlockAgv, "02050" + endBlockDevice.getCurrFloor());
// 当前车等待下一轮调度(待阻挡车移开后自然可达) // 当前车等待下一轮调度(待阻挡车移开后自然可达)
return false; return false;
} }
}
//处理地图
int[][] emptyMap = roadCacheService.handleMap(arrByRoadSite, deviceSrgv);
//计算最短路径
List<int[]> shortestPath = PathFinder.findShortestPath(emptyMap, arrByRoadSite.get(startSite).getX(), arrByRoadSite.get(startSite).getY(), arrByRoadSite.get(endSite).getX(), arrByRoadSite.get(endSite).getY());
//判断是否能规划出最短路径 //判断是否能规划出最短路径
if (shortestPath == null || shortestPath.isEmpty()) { if (shortestPath == null || shortestPath.isEmpty()) {
@@ -697,9 +703,11 @@ public class BaseSRgvThread implements Runnable, SRgvThreadInterface {
return false; return false;
} }
//获取拐点路径 //获取拐点路径
List<int[]> trun = PathFinder.extractInflectionPoints2(shortestPath); List<int[]> trun = PathFinder.extractInflectionPoints2(shortestPath);
// 路径点拼接 // 路径点拼接
StringBuilder pathBuilder = new StringBuilder(); StringBuilder pathBuilder = new StringBuilder();
if (!shortestPath.isEmpty()) { if (!shortestPath.isEmpty()) {