From 1d520bffcd63cb8389c9cdf719c3cf7e7c4af567 Mon Sep 17 00:00:00 2001
From: jianghaiyue <jianghaiyue@zkyt.com>
Date: 星期四, 30 十月 2025 10:20:28 +0800
Subject: [PATCH] 优化更新
---
algo-zkd/src/main/java/com/algo/service/RemainingPathProcessor.java | 77 +++++++++++++++++++++++++++++++++++---
1 files changed, 70 insertions(+), 7 deletions(-)
diff --git a/algo-zkd/src/main/java/com/algo/service/RemainingPathProcessor.java b/algo-zkd/src/main/java/com/algo/service/RemainingPathProcessor.java
index 15f7545..273244d 100644
--- a/algo-zkd/src/main/java/com/algo/service/RemainingPathProcessor.java
+++ b/algo-zkd/src/main/java/com/algo/service/RemainingPathProcessor.java
@@ -34,6 +34,7 @@
/**
* 澶勭悊鎵�鏈塁TU鐨勫墿浣欒矾寰勶紝鏋勫缓鏃剁┖鍗犵敤琛�
+ * 馃敡 淇锛氬悓鏃跺鐞嗘湁鍓╀綑璺緞鐨凙GV鍜岄潤姝GV鐨勫綋鍓嶄綅缃崰鐢�
*
* @param agvStatusList CTU鐘舵�佸垪琛�
* @return 鏃剁┖鍗犵敤琛紝key涓�"x,y,timeSlot"锛寁alue涓篊TU缂栧彿
@@ -43,11 +44,50 @@
for (AGVStatus agv : agvStatusList) {
if (agv.hasRemainingPath()) {
+ // 澶勭悊鏈夊墿浣欒矾寰勭殑AGV
processRemainingPathOccupancy(agv, occupancyMap);
+ } else if (agv.getPosition() != null && !agv.getPosition().isEmpty()) {
+ // 澶勭悊闈欐AGV鐨勫綋鍓嶄綅缃崰鐢�
+ processStaticAgvOccupancy(agv, occupancyMap);
}
}
return occupancyMap;
+ }
+
+ /**
+ * 澶勭悊闈欐AGV鐨勪綅缃崰鐢�
+ *
+ * @param agv CTU鐘舵��
+ * @param occupancyMap 鏃剁┖鍗犵敤琛�
+ */
+ private void processStaticAgvOccupancy(AGVStatus agv, Map<String, String> occupancyMap) {
+ String position = agv.getPosition();
+ if (position == null || position.isEmpty()) {
+ return;
+ }
+
+ // 鑾峰彇浣嶇疆鍧愭爣
+ int[] coord = JsonUtils.getCoordinate(position, pathMapping);
+ if (coord == null) {
+ return;
+ }
+
+ CTUPhysicalConfig config = agv.getPhysicalConfig();
+ long currentTime = System.currentTimeMillis() / 1000; // 杞崲涓虹
+
+ // 闈欐AGV鍗犵敤褰撳墠浣嶇疆鐨勯暱鏃堕棿娈碉紙鍋囪300绉掞級
+ long occupancyDuration = 300; // 300绉掔殑鍗犵敤鏃堕棿
+
+ for (long timeSlot = currentTime; timeSlot < currentTime + occupancyDuration; timeSlot++) {
+ String spaceTimeKey = coord[0] + "," + coord[1] + "," + timeSlot;
+ occupancyMap.put(spaceTimeKey, agv.getAgvId());
+
+ occupyAdjacentSpaces(coord, timeSlot, agv.getAgvId(), occupancyMap, config);
+ }
+
+ System.out.println(" 闈欐AGV " + agv.getAgvId() + " 鍗犵敤浣嶇疆 " + position +
+ " (鍧愭爣: " + coord[0] + "," + coord[1] + ") " );
}
/**
@@ -153,8 +193,16 @@
String currentDirection = currentCode.getDirection();
String nextDirection = nextCode.getDirection();
- if (!currentDirection.equals(nextDirection)) {
- stayTime += config.getTurnTime(currentDirection, nextDirection);
+ if (currentDirection != null && nextDirection != null) {
+ if (!currentDirection.equals(nextDirection)) {
+ stayTime += config.getTurnTime(currentDirection, nextDirection);
+ }
+ } else {
+ if (pathIndex == agv.getCurrentPathIndex()) {
+ System.out.println("AGV " + agv.getAgvId() +
+ " 鐨勫墿浣欒矾寰勪腑direction瀛楁涓簄ull");
+ }
+ stayTime += 0.5;
}
}
@@ -168,7 +216,7 @@
stayTime += 2.0; // 鏀捐揣闇�瑕�2绉�
break;
case "3": // 鍏呯數
- stayTime += 10.0; // 鍏呯數鍋滈潬闇�瑕�10绉�
+ stayTime += 100.0; // 鍏呯數鍋滈潬
break;
default:
stayTime += 1.0; // 鍏朵粬鍔ㄤ綔闇�瑕�1绉�
@@ -362,11 +410,26 @@
connectedPath.setAgvId(agv.getAgvId());
connectedPath.setCodeList(remainingCodes);
- // 鐢熸垚鏂扮殑娈佃惤ID
- String segId = agv.getAgvId() + "_CONNECTED_" + System.currentTimeMillis();
- if (newPath != null && newPath.getSegId() != null) {
- segId = newPath.getSegId() + "_EXTENDED";
+ // 浣跨敤鍓╀綑璺緞鐨勫師濮媠egId
+ String segId = remainingPath.getSegId();
+
+ if (segId != null && !segId.trim().isEmpty()) {
+ // 濡傛灉鏈夋柊璺緞杩炴帴锛屽湪鍘焥egId鍩虹涓婃坊鍔犳墿灞曟爣璁�
+ if (newPath != null && newPath.getCodeList() != null && !newPath.getCodeList().isEmpty()) {
+ // 妫�鏌ユ槸鍚﹀凡缁忔湁鎵╁睍鏍囪锛岄伩鍏嶉噸澶嶆坊鍔�
+ if (!segId.endsWith("_EXTENDED")) {
+ segId = segId + "_EXTENDED";
+ }
+ }
+ } else {
+ // 濡傛灉鍘熷璺緞娌℃湁segId锛屾牴鎹儏鍐电敓鎴�
+ if (newPath != null && newPath.getSegId() != null && !newPath.getSegId().trim().isEmpty()) {
+ segId = newPath.getSegId() + "_EXTENDED";
+ } else {
+ segId = agv.getAgvId() + "_CONNECTED_" + System.currentTimeMillis();
+ }
}
+
connectedPath.setSegId(segId);
return connectedPath;
--
Gitblit v1.9.1