From 11da5829433e788d8f901ee5cd910d5923f0806a Mon Sep 17 00:00:00 2001 From: Junjie <540245094@qq.com> Date: 星期四, 13 六月 2024 09:51:37 +0800 Subject: [PATCH] #小车地图严格模式 --- zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateSolution.java | 59 +++++++++++++++++++++++------------------------------------ 1 files changed, 23 insertions(+), 36 deletions(-) diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateSolution.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateSolution.java index 9fc734c..4dbd761 100644 --- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateSolution.java +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateSolution.java @@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.zy.asrs.framework.common.SpringUtils; +import com.zy.asrs.framework.exception.CoolException; import com.zy.asrs.wcs.core.model.NavigateNode; import com.zy.asrs.wcs.system.entity.Dict; import com.zy.asrs.wcs.system.service.DictService; @@ -34,7 +35,7 @@ mapData.setLev(lev); int[][] data = mapData.getDataFromRedis(mapType, whitePoints, shuttlePoints); if (data == null) { - data = mapData.getData(mapType, whitePoints, shuttlePoints); + throw new CoolException("鍦板浘鏈浇鍏ワ紒"); } this.map = data; } @@ -70,28 +71,19 @@ if (node.getX() == end.getX() && node.getY() == end.getY()) {//鎵惧埌鐩爣缁撶偣灏辫繑鍥� //init_node鎿嶄綔鎶婅繖涓偦灞呯粨鐐圭殑鐖惰妭鐐硅缃负褰撳墠缁撶偣 //骞朵笖璁$畻鍑篏锛� F锛� H绛夊�� + node.setLastDistance(gCost); node.init_node(current_node, end); return node; } - //(瀵瑰惎鍙戝嚱鏁板鍔犲幓鎷愮偣鏂规calcNodeExtraCost) - if (is_exist(node)) { - if (gCost < node.getG()) { - node.setFather(current_node); - node.setG(gCost); - node.setF(node.getG() + node.getH()); - } - }else { - //娌″嚭鐜拌繃鐨勭粨鐐瑰姞鍏ュ埌Open琛ㄤ腑骞朵笖璁剧疆鐖惰妭鐐� - //杩涜璁$畻瀵笹, F, H 绛夊�� - node.init_node(current_node, end); - node.setG(gCost); - node.setH(calcNodeCost(node, end)); - node.setF(node.getG() + node.getH()); + //杩涜璁$畻瀵笹, F, H 绛夊�� + node.setLastDistance(gCost); + node.init_node(current_node, end); + node.setH(calcNodeCost(node, end)); + node.setF(node.getG() + node.getH()); - Open.add(node); - Exist.add(node); - } + Open.add(node); + Exist.add(node); } } //濡傛灉閬嶅巻瀹屾墍鏈夊嚭鐜扮殑缁撶偣閮芥病鏈夋壘鍒版渶缁堢殑缁撶偣锛岃繑鍥瀗ull @@ -207,23 +199,18 @@ } public boolean is_valid(int x, int y) { - try { - // 濡傛灉缁撶偣鐨勪綅缃皬浜�0锛屽垯涓嶅悎娉� - if (map[x][y] < 0) return false; - for (NavigateNode node : Exist) { - //濡傛灉缁撶偣鍑虹幇杩囷紝涓嶅悎娉� - if (node.getX() == x && node.getY() == y) { - return false; - } - if (is_exist(new NavigateNode(x, y))) { - return false; - } - } - //浠ヤ笂鎯呭喌閮芥病鏈夊垯鍚堟硶 - return true; - } catch (Exception e) { + if (x < 0 || x >= this.map.length + || y < 0 || y >= this.map[0].length) { return false; } + // 濡傛灉缁撶偣鐨勪綅缃皬浜�0锛屽垯涓嶅悎娉� + if (map[x][y] < 0) return false; + NavigateNode navigateNode = new NavigateNode(x, y); + if (is_exist(navigateNode)) { + return false; + } + //浠ヤ笂鎯呭喌閮芥病鏈夊垯鍚堟硶 + return true; } public boolean is_exist(NavigateNode node) @@ -248,12 +235,12 @@ // 绗竴涓偣鎴栫洿绾跨偣 if (currNode.getFather() == null || nextNode.getX() == currNode.getFather().getX() || nextNode.getY() == currNode.getFather().getY()) { - return 0; + return 1; } // 鎷愬悜缁堢偣鐨勭偣 if (nextNode.getX() == endNode.getX() || nextNode.getY() == endNode.getY()) { - return 1; + return 2; } // 鏅�氭嫄鐐� @@ -262,7 +249,7 @@ 鎷垮埌鐖惰妭鐐瑰拰涓嬩竴鑺傜偣 閫氳繃鍒ゆ柇鐖惰妭鐐瑰拰涓嬩竴鑺傜偣鐨剎鏁版嵁鍜寉鏁版嵁閮戒笉鐩稿悓鏃讹紝鍒欒〃鏄庡綋鍓嶅潗鏍囨槸涓�涓嫄鐐� */ - return 2; + return 3; } //------------------A*鍚彂鍑芥暟-end------------------// -- Gitblit v1.9.1