From 6182cc11c3e93610df7fda87611d2ca807c6354c Mon Sep 17 00:00:00 2001
From: qlsxk <qlsxk@qq.com>
Date: 星期四, 16 十月 2025 14:28:30 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/common/utils/NavigateSolution.java | 75 +++++++++++++++++++------------------
1 files changed, 38 insertions(+), 37 deletions(-)
diff --git a/src/main/java/com/zy/common/utils/NavigateSolution.java b/src/main/java/com/zy/common/utils/NavigateSolution.java
index 13df2e2..681c54d 100644
--- a/src/main/java/com/zy/common/utils/NavigateSolution.java
+++ b/src/main/java/com/zy/common/utils/NavigateSolution.java
@@ -5,6 +5,7 @@
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
import com.zy.common.model.NavigateNode;
+import com.zy.common.model.enums.NavigationMapType;
import com.zy.core.enums.MapNodeType;
import com.zy.core.model.PythonResult;
import com.zy.system.entity.Config;
@@ -25,10 +26,10 @@
int[][] map = {{}};
- public NavigateSolution(Integer mapType, Integer lev, List<int[]> whitePoints, List<int[]> shuttlePoints) {
+ public NavigateSolution(List<NavigationMapType> mapTypes, Integer lev, List<int[]> whitePoints, List<int[]> shuttlePoints) {
//杞藉叆鍦板浘鎸囧畾灞傞珮鍦板浘
NavigateMapData mapData = SpringUtils.getBean(NavigateMapData.class);
- int[][] data = mapData.getDataFromRedis(lev, mapType, whitePoints, shuttlePoints);
+ int[][] data = mapData.getDataFromRedis(lev, mapTypes, whitePoints, shuttlePoints);
if (data == null) {
throw new CoolException("鍦板浘鏈浇鍏ワ紒");
}
@@ -103,6 +104,18 @@
}
public NavigateNode astarSearchJava(NavigateNode start, NavigateNode end) {
+ //榛樿鍦板浘姣嶈建鏂瑰悜x
+ String mapDirection = "x";
+ ConfigService configService = SpringUtils.getBean(ConfigService.class);
+ if (configService != null) {
+ Config config = configService.selectOne(new EntityWrapper<Config>()
+ .eq("code", "direction_map")
+ .eq("status", 1));
+ if (config != null) {
+ mapDirection = config.getValue();
+ }
+ }
+
//鎶婄涓�涓紑濮嬬殑缁撶偣鍔犲叆鍒癘pen琛ㄤ腑
this.Open.add(start);
//涓诲惊鐜�
@@ -117,7 +130,7 @@
//灏嗚繖涓粨鐐瑰姞鍏ュ埌Close琛ㄤ腑
Close.add(current_node);
//瀵瑰綋鍓嶇粨鐐硅繘琛屾墿灞曪紝寰楀埌涓�涓洓鍛ㄧ粨鐐圭殑鏁扮粍
- ArrayList<NavigateNode> neighbour_node = extend_current_node(current_node);
+ ArrayList<NavigateNode> neighbour_node = extend_current_node(current_node, mapDirection);
//瀵硅繖涓粨鐐归亶鍘嗭紝鐪嬫槸鍚︽湁鐩爣缁撶偣鍑虹幇
for (NavigateNode node : neighbour_node) {
// G + H + E (瀵瑰惎鍙戝嚱鏁板鍔犲幓鎷愮偣鏂规calcNodeExtraCost)
@@ -143,19 +156,7 @@
}
- public ArrayList<NavigateNode> extend_current_node(NavigateNode current_node) {
- //榛樿鍦板浘姣嶈建鏂瑰悜x
- String mapDirection = "x";
- ConfigService configService = SpringUtils.getBean(ConfigService.class);
- if (configService != null) {
- Config config = configService.selectOne(new EntityWrapper<Config>()
- .eq("code", "direction_map")
- .eq("status", 1));
- if (config != null) {
- mapDirection = config.getValue();
- }
- }
-
+ public ArrayList<NavigateNode> extend_current_node(NavigateNode current_node, String mapDirection) {
//鑾峰彇褰撳墠缁撶偣鐨剎, y
int x = current_node.getX();
int y = current_node.getY();
@@ -192,56 +193,56 @@
if (mapDirection.equals("x")) {//姣嶈建x鏂瑰悜
if (map[x][y] == MapNodeType.MAIN_PATH.id) {
//姣嶈建鎵嶈兘杩涜涓婁笅绉诲姩
- if (is_valid(x + 1, y))
- {
+ if (is_valid(x + 1, y)) {
NavigateNode node = new NavigateNode(x + 1, y);
+ node.setNodeValue(map[x + 1][y]);
neighbour_node.add(node);
}
- if (is_valid(x - 1, y))
- {
- NavigateNode node = new NavigateNode(x -1, y);
+ if (is_valid(x - 1, y)) {
+ NavigateNode node = new NavigateNode(x - 1, y);
+ node.setNodeValue(map[x - 1][y]);
neighbour_node.add(node);
}
}
- if (map[x][y] == MapNodeType.NORMAL_PATH.id || map[x][y] == MapNodeType.MAIN_PATH.id || map[x][y] == MapNodeType.CONVEYOR_CAR_GO.id || map[x][y] == MapNodeType.CHARGE.id || map[x][y] == MapNodeType.LIFT.id) {
+ if (map[x][y] == MapNodeType.NORMAL_PATH.id || map[x][y] == MapNodeType.MAIN_PATH.id || map[x][y] == MapNodeType.CONVEYOR_CAR_GO.id || map[x][y] == MapNodeType.CONVEYOR.id || map[x][y] == MapNodeType.CHARGE.id || map[x][y] == MapNodeType.LIFT.id) {
//瀛愯建鍜屾瘝杞ㄣ�佸皬杞﹀彲璧拌緭閫佺嚎銆佸厖鐢垫々銆佹彁鍗囨満鎵嶈兘杩涜宸﹀彸绉诲姩
- if (is_valid(x, y + 1))
- {
+ if (is_valid(x, y + 1)) {
NavigateNode node = new NavigateNode(x, y + 1);
+ node.setNodeValue(map[x][y + 1]);
neighbour_node.add(node);
}
- if (is_valid(x, y - 1))
- {
+ if (is_valid(x, y - 1)) {
NavigateNode node = new NavigateNode(x, y - 1);
+ node.setNodeValue(map[x][y - 1]);
neighbour_node.add(node);
}
}
- }else if (mapDirection.equals("y")) {//姣嶈建y鏂瑰悜
+ } else if (mapDirection.equals("y")) {//姣嶈建y鏂瑰悜
if (map[x][y] == MapNodeType.MAIN_PATH.id) {
//姣嶈建鎵嶈兘杩涜宸﹀彸绉诲姩
- if (is_valid(x, y + 1))
- {
+ if (is_valid(x, y + 1)) {
NavigateNode node = new NavigateNode(x, y + 1);
+ node.setNodeValue(map[x][y + 1]);
neighbour_node.add(node);
}
- if (is_valid(x, y - 1))
- {
+ if (is_valid(x, y - 1)) {
NavigateNode node = new NavigateNode(x, y - 1);
+ node.setNodeValue(map[x][y - 1]);
neighbour_node.add(node);
}
}
- if (map[x][y] == MapNodeType.NORMAL_PATH.id || map[x][y] == MapNodeType.MAIN_PATH.id || map[x][y] == MapNodeType.CONVEYOR_CAR_GO.id || map[x][y] == MapNodeType.CHARGE.id || map[x][y] == MapNodeType.LIFT.id) {
+ if (map[x][y] == MapNodeType.NORMAL_PATH.id || map[x][y] == MapNodeType.MAIN_PATH.id || map[x][y] == MapNodeType.CONVEYOR_CAR_GO.id || map[x][y] == MapNodeType.CONVEYOR.id || map[x][y] == MapNodeType.CHARGE.id || map[x][y] == MapNodeType.LIFT.id) {
//瀛愯建鍜屾瘝杞ㄣ�佸皬杞﹀彲璧拌緭閫佺嚎銆佸厖鐢垫々銆佹彁鍗囨満鎵嶈兘杩涜涓婁笅绉诲姩
- if (is_valid(x + 1, y))
- {
+ if (is_valid(x + 1, y)) {
NavigateNode node = new NavigateNode(x + 1, y);
+ node.setNodeValue(map[x + 1][y]);
neighbour_node.add(node);
}
- if (is_valid(x - 1, y))
- {
- NavigateNode node = new NavigateNode(x -1, y);
+ if (is_valid(x - 1, y)) {
+ NavigateNode node = new NavigateNode(x - 1, y);
+ node.setNodeValue(map[x - 1][y]);
neighbour_node.add(node);
}
}
--
Gitblit v1.9.1