From 0ae57663de53c0c988d4b06a1218c1a4c5440651 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期一, 23 十二月 2024 15:55:53 +0800
Subject: [PATCH] #

---
 zy-acs-flow/src/map/constants.js                                                       |    2 
 /dev/null                                                                              |  203 ----------------------------------------
 zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/MapDataWsScheduler.java |    4 
 zy-acs-manager/src/main/resources/agv.py                                               |   49 ++++++---
 4 files changed, 37 insertions(+), 221 deletions(-)

diff --git a/zy-acs-flow/src/map/constants.js b/zy-acs-flow/src/map/constants.js
index 8088dcf..d7d46c0 100644
--- a/zy-acs-flow/src/map/constants.js
+++ b/zy-acs-flow/src/map/constants.js
@@ -1,5 +1,5 @@
 
-export const ANIMATE_DURING_TIME = 200;
+export const ANIMATE_DURING_TIME = 800;
 
 export const MAP_DEFAULT_ROTATION = 270;
 
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/MapDataWsScheduler.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/MapDataWsScheduler.java
index e7d5133..3870b56 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/MapDataWsScheduler.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/MapDataWsScheduler.java
@@ -33,7 +33,7 @@
 @Component
 public class MapDataWsScheduler {
 
-    public static final int WEBSOCKET_BROADCAST_INTERVAL = 200;
+    public static final int WEBSOCKET_BROADCAST_INTERVAL = 800;
 
     private ExecutorService singleThreadExecutor;
 
@@ -58,7 +58,7 @@
                     MapWsVo mapWsVo = new MapWsVo();
                     mapWsVo.setAgvVos(syncAgv());
                     MapWebSocket.broadcast(GsonUtils.toJson(mapWsVo));
-                    Thread.sleep(WEBSOCKET_BROADCAST_INTERVAL);
+                    Thread.sleep(WEBSOCKET_BROADCAST_INTERVAL / 2);
                 } catch (Exception e) {
                     log.error("MapDataWsScheduler.init", e);
                 }
diff --git a/zy-acs-manager/src/main/resources/agv.py b/zy-acs-manager/src/main/resources/agv.py
index 23d4dd6..d6b5632 100644
--- a/zy-acs-manager/src/main/resources/agv.py
+++ b/zy-acs-manager/src/main/resources/agv.py
@@ -19,29 +19,45 @@
 
 def getWaveScopeByCode_iterative(x, y, codeMatrix, cdaMatrix, radiusLen):
     """
-    浣跨敤骞垮害浼樺厛鎼滅储锛圔FS锛夋潵浠f浛閫掑綊锛屼互閬垮厤閫掑綊娣卞害杩囧ぇ鐨勯棶棰樸��
+    浣跨敤骞垮害浼樺厛鎼滅储锛圔FS锛夊苟璺熻釜鎵╁睍鏂瑰悜锛屼互閬垮厤閫掑綊娣卞害杩囧ぇ鍜屼笉蹇呰鐨勮祫婧愭氮璐广��
+    褰撻亣鍒� 'NONE' 鑺傜偣鏃讹紝浠呭湪褰撳墠鏂瑰悜涓婄户缁墿灞曘��
     """
     includeList = []
     existNodes = set()
     queue = deque()
 
-    originNode = {"x": x, "y": y}
-    currNode = {"x": x, "y": y}
-    queue.append(currNode)
+    # 鍒濆鑺傜偣锛屾病鏈夋柟鍚�
+    originNode = {"x": x, "y": y, "dir": None}
+    queue.append(originNode)
     existNodes.add((x, y))
 
     while queue:
         node = queue.popleft()
-        node_x, node_y = node['x'], node['y']
-        neighbors = [
-            (node_x + 1, node_y),
-            (node_x - 1, node_y),
-            (node_x, node_y + 1),
-            (node_x, node_y - 1)
-        ]
+        node_x, node_y, current_dir = node['x'], node['y'], node['dir']
 
-        for neighbor in neighbors:
-            nx, ny = neighbor
+        # 鏍规嵁褰撳墠鏂瑰悜鍐冲畾鎵╁睍鐨勬柟鍚�
+        if current_dir is None:
+            # 濡傛灉娌℃湁鏂瑰悜锛屽悜鍥涗釜鏂瑰悜鎵╁睍
+            neighbors = [
+                (node_x + 1, node_y, 'right'),
+                (node_x - 1, node_y, 'left'),
+                (node_x, node_y + 1, 'down'),
+                (node_x, node_y - 1, 'up')
+            ]
+        else:
+            # 濡傛灉鏈夋柟鍚戯紝浠呭湪璇ユ柟鍚戜笂鎵╁睍
+            if current_dir == 'right':
+                neighbors = [(node_x + 1, node_y, 'right')]
+            elif current_dir == 'left':
+                neighbors = [(node_x - 1, node_y, 'left')]
+            elif current_dir == 'down':
+                neighbors = [(node_x, node_y + 1, 'down')]
+            elif current_dir == 'up':
+                neighbors = [(node_x, node_y - 1, 'up')]
+            else:
+                neighbors = []
+
+        for nx, ny, direction in neighbors:
             # 妫�鏌ヨ竟鐣屾潯浠�
             if (nx < 0 or nx >= codeMatrix.shape[0] or ny < 0 or ny >= codeMatrix.shape[1]):
                 continue
@@ -52,8 +68,10 @@
             neighbor_code = codeMatrix[nx, ny]
 
             if neighbor_code == 'NONE':
-                queue.append({"x": nx, "y": ny})
+                # 閬囧埌 'NONE' 鑺傜偣锛岀户缁湪褰撳墠鏂瑰悜涓婃墿灞�
+                queue.append({"x": nx, "y": ny, "dir": direction})
             else:
+                # 妫�鏌ヨ窛绂绘潯浠�
                 o1Cda = convert_to_float_array(cdaMatrix[x, y])
                 o2Cda = convert_to_float_array(cdaMatrix[nx, ny])
 
@@ -65,7 +83,8 @@
                         "y": int(ny),
                         "code": str(codeMatrix[nx, ny])
                     })
-                    queue.append({"x": nx, "y": ny})
+                    # 闈� 'NONE' 鑺傜偣锛岄噸缃柟鍚�
+                    queue.append({"x": nx, "y": ny, "dir": None})
 
     return includeList
 
diff --git a/zy-acs-manager/src/main/resources/agv1.py b/zy-acs-manager/src/main/resources/agv1.py
deleted file mode 100644
index 245bb6e..0000000
--- a/zy-acs-manager/src/main/resources/agv1.py
+++ /dev/null
@@ -1,203 +0,0 @@
-import ast
-import sys
-import numpy as np
-import json
-import time
-import redis
-from collections import deque
-
-radiusLen = None
-
-# 灏嗗瓧绗︿覆杞崲涓烘诞鐐瑰瀷鏁扮粍
-def convert_to_float_array(str_array):
-    if isinstance(str_array, str):
-        return np.array(ast.literal_eval(str_array), dtype=float)
-    return str_array
-
-def getWaveScopeByCode_iterative(x, y):
-    """
-    浣跨敤骞垮害浼樺厛鎼滅储锛圔FS锛夋潵浠f浛閫掑綊锛屼互閬垮厤閫掑綊娣卞害杩囧ぇ鐨勯棶棰樸��
-    """
-    includeList = []
-    existNodes = set()
-    queue = deque()
-
-    originNode = {"x": x, "y": y}
-    currNode = {"x": x, "y": y}
-    queue.append(currNode)
-    existNodes.add((x, y))
-
-    while queue:
-        node = queue.popleft()
-        node_x, node_y = node['x'], node['y']
-        neighbors = [
-            (node_x + 1, node_y),
-            (node_x - 1, node_y),
-            (node_x, node_y + 1),
-            (node_x, node_y - 1)
-        ]
-
-        for neighbor in neighbors:
-            nx, ny = neighbor
-            # 妫�鏌ヨ竟鐣屾潯浠�
-            if (nx < 0 or nx >= codeMatrix.shape[0] or ny < 0 or ny >= codeMatrix.shape[1]):
-                continue
-            if (nx, ny) in existNodes:
-                continue
-
-            existNodes.add((nx, ny))
-            neighbor_code = codeMatrix[nx, ny]
-
-            if neighbor_code == 'NONE':
-                queue.append({"x": nx, "y": ny})
-            else:
-                o1Cda = convert_to_float_array(cdaMatrix[x, y])
-                o2Cda = convert_to_float_array(cdaMatrix[nx, ny])
-
-                num1 = (o1Cda[0] - o2Cda[0]) ** 2
-                num2 = (o1Cda[1] - o2Cda[1]) ** 2
-                if num1 + num2 <= radiusLen ** 2:
-                    includeList.append({
-                        "x": int(nx),
-                        "y": int(ny),
-                        "code": str(codeMatrix[nx, ny])
-                    })
-                    queue.append({"x": nx, "y": ny})
-
-    return includeList
-
-def find_value_in_matrix(value):
-    indices = np.where(codeMatrix == value)
-    return list(zip(indices[0], indices[1]))
-
-def initWaveMatrix():
-    waveMatrix = np.empty_like(codeMatrix, dtype=object)
-
-    for x in range(codeMatrix.shape[0]):
-        for y in range(codeMatrix.shape[1]):
-            if codeMatrix[x][y] == 'NONE':
-                waveMatrix[x][y] = "-"
-            else:
-                waveMatrix[x][y] = '[]'
-
-    return waveMatrix
-
-# 浼樺寲鐗堟湰锛氫娇鐢ㄩ泦鍚堟潵鎻愰珮鎬ц兘
-def mergeWave(originWave, vehicle):
-    # 灏嗗瓧绗︿覆瑙f瀽涓洪泦鍚�
-    try:
-        set_data = set(ast.literal_eval(originWave))
-    except (ValueError, SyntaxError):
-        set_data = set()
-    # 濡傛灉 vehicle 涓嶅湪闆嗗悎涓紝鍒欐坊鍔�
-    set_data.add(vehicle)
-    # 杩斿洖搴忓垪鍖栧悗鐨勫瓧绗︿覆
-    return json.dumps(list(set_data))
-
-# 灏� dynamicMatrix 杞崲涓� numpy 缁撴瀯鍖栨暟缁�
-def convert_to_structured_array(dynamicMatrix):
-    # 瀹氫箟缁撴瀯鍖栨暟缁勭殑 dtype
-    dtype = [('serial', int), ('vehicle', 'U2'), ('time', int)]
-
-    # 纭繚姣忎釜瀛楀吀鍖呭惈鎵�鏈夊瓧娈�
-    structured_list = []
-    for row in dynamicMatrix:
-       for d in row:
-           # 鎻愬彇瀛楁锛岀‘淇� 'time' 瀛樺湪锛屽惁鍒欒缃负榛樿鍊硷紙渚嬪 0.0锛�
-           serial = d.get('serial', 0)
-           vehicle = d.get('vehicle', '0')
-           time_val = d.get('time', 0)
-           structured_list.append((serial, vehicle, time_val))
-
-    # 灏嗗祵濂楃殑鍒楄〃杞崲涓虹粨鏋勫寲鏁扮粍
-    structured_array = np.array(structured_list, dtype=dtype)
-    # 閲嶅涓哄師濮嬬殑浜岀淮褰㈢姸
-    return structured_array.reshape(len(dynamicMatrix), -1)
-
-# 浣跨敤 numpy 鍔犻�熺殑浠g爜
-def process_dynamic_matrix(dynamicMatrix, codeMatrix):
-    global waveMatrix  # 纭繚 waveMatrix 鏄叏灞�鍙橀噺
-
-    # 灏� dynamicMatrix 杞崲涓虹粨鏋勫寲鏁扮粍
-    dynamicMatrix = convert_to_structured_array(dynamicMatrix)
-
-    # 鑾峰彇 dynamicMatrix 鐨勫舰鐘�
-    rows, cols = dynamicMatrix.shape
-
-    # 鍒涘缓涓�涓竷灏旀帺鐮侊紝鐢ㄤ簬绛涢�夊嚭 vehicle 涓嶄负 '0' 鍜� '-1' 鐨勫厓绱�
-    mask = (dynamicMatrix['vehicle'] != '0') & (dynamicMatrix['vehicle'] != '-1')
-
-    # 鑾峰彇婊¤冻鏉′欢鐨� x 鍜� y 鍧愭爣
-    x_indices, y_indices = np.where(mask)
-
-    # 閬嶅巻婊¤冻鏉′欢鐨勫潗鏍�
-    for x, y in zip(x_indices, y_indices):
-        vehicle = dynamicMatrix[x][y]['vehicle']
-        includeList = getWaveScopeByCode_iterative(x, y)
-        for include in includeList:
-            originWave = waveMatrix[include['x']][include['y']]
-            waveMatrix[include['x']][include['y']] = mergeWave(originWave, vehicle)
-
-def main():
-    global radiusLen, codeMatrix, cdaMatrix, waveMatrix  # 澹版槑涓哄叏灞�鍙橀噺
-
-    if len(sys.argv) != 6:
-        print("Usage: python script.py <radiusLen> <redisHost> <redisPwd> <redisPort> <redisIdx>")
-        sys.exit(1)
-
-    radiusLenStr = sys.argv[1]
-    radiusLen = float(radiusLenStr)
-
-    redisHost = sys.argv[2]
-    redisPwd = sys.argv[3]
-    redisPort = sys.argv[4]
-    redisIdx = sys.argv[5]
-
-    startTime = time.perf_counter()
-
-    # 鍒涘缓涓�涓繛鎺ユ睜
-    pool = redis.ConnectionPool(host=redisHost, port=int(redisPort), password=redisPwd, db=int(redisIdx))
-    r = redis.Redis(connection_pool=pool)
-
-    # 鑾峰彇骞跺姞杞� codeMatrix
-    codeMatrixStr = r.get('KV.AGV_MAP_ASTAR_CODE_FLAG.1')
-    if codeMatrixStr is None:
-        print("Error: 'KV.AGV_MAP_ASTAR_CODE_FLAG.1' not found in Redis.")
-        sys.exit(1)
-    codeMatrix = np.array(json.loads(codeMatrixStr))
-
-    # 鑾峰彇骞跺姞杞� cdaMatrix
-    cdaMatrixStr = r.get('KV.AGV_MAP_ASTAR_CDA_FLAG.1')
-    if cdaMatrixStr is None:
-        print("Error: 'KV.AGV_MAP_ASTAR_CDA_FLAG.1' not found in Redis.")
-        sys.exit(1)
-    cdaMatrix = np.array(json.loads(cdaMatrixStr))
-
-    # 鑾峰彇骞跺姞杞� dynamicMatrix
-    dynamicMatrixStr = r.get('KV.AGV_MAP_ASTAR_DYNAMIC_FLAG.1')
-    if dynamicMatrixStr is None:
-        print("Error: 'KV.AGV_MAP_ASTAR_DYNAMIC_FLAG.1' not found in Redis.")
-        sys.exit(1)
-    dynamicMatrix = np.array(json.loads(dynamicMatrixStr))
-
-    # 鍒濆鍖� waveMatrix
-    waveMatrix = initWaveMatrix()
-
-    # 澶勭悊 dynamicMatrix
-    process_dynamic_matrix(dynamicMatrix, codeMatrix)
-
-    # 灏� numpy.ndarray 杞崲涓哄祵濂楀垪琛�
-    waveMatrixList = waveMatrix.tolist()
-    # 灏嗗祵濂楀垪琛ㄨ浆鎹负 JSON 瀛楃涓�
-    waveMatrixJsonStr = json.dumps(waveMatrixList)
-
-    # 灏嗙粨鏋滀繚瀛樺洖 Redis
-    r.set("KV.AGV_MAP_ASTAR_WAVE_FLAG.1", waveMatrixJsonStr)
-
-    end = time.perf_counter()
-    # 鎵撳嵃绋嬪簭杩愯鏃堕棿
-#     print(f"绋嬪簭杩愯鏃堕棿涓�: {end - startTime} Seconds")
-    print("1")
-
-if __name__ == "__main__":
-    main()
\ No newline at end of file

--
Gitblit v1.9.1