| | |
| | | package com.zy.acs.manager.core.service.astart; |
| | | |
| | | import com.zy.acs.common.constant.RedisConstant; |
| | | import com.zy.acs.common.utils.GsonUtils; |
| | | import com.zy.acs.common.utils.RedisSupport; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.manager.common.utils.MapDataUtils; |
| | |
| | | import com.zy.acs.manager.manager.entity.Segment; |
| | | import com.zy.acs.manager.manager.service.JamService; |
| | | import com.zy.acs.manager.system.service.ConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.*; |
| | | import java.util.concurrent.CopyOnWriteArrayList; |
| | | |
| | | /** |
| | | * Created by vincent on 6/12/2024 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class AStarNavigateService { |
| | | |
| | |
| | | // 取优先队列顶部元素并且把这个元素从Open表中删除,取F值最小的节点 |
| | | NavigateNode currentNode = openQueue.poll(); |
| | | |
| | | ArrayList<NavigateNode> neighbourNodes = this.getNeighborNodes(currentNode, mapMatrix, existNodes); |
| | | List<NavigateNode> neighbourNodes = this.getNeighborNodes(currentNode, mapMatrix, existNodes); |
| | | for (NavigateNode node : neighbourNodes) { |
| | | node.setCodeData(codeMatrix[node.getX()][node.getY()]); |
| | | |
| | | boolean isEndNode = node.getX() == end.getX() && node.getY() == end.getY(); |
| | | |
| | | int weight = 0; |
| | |
| | | } |
| | | |
| | | // 获取四周节点 |
| | | private ArrayList<NavigateNode> getNeighborNodes(NavigateNode currentNode, int[][] mapMatrix, Set<NavigateNode> existNodes) { |
| | | private List<NavigateNode> getNeighborNodes(NavigateNode currentNode, int[][] mapMatrix, Set<NavigateNode> existNodes) { |
| | | int x = currentNode.getX(); |
| | | int y = currentNode.getY(); |
| | | |
| | | ArrayList<NavigateNode> neighbourNodes = new ArrayList<>(); |
| | | List<NavigateNode> neighbourNodes = new CopyOnWriteArrayList<>(); |
| | | |
| | | List<NavigateNode> possibleNodes = Arrays.asList( |
| | | new NavigateNode(x, y + 1), // right |