| | |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.manager.common.utils.MapDataUtils; |
| | | import com.zy.acs.manager.core.domain.Lane; |
| | | import com.zy.acs.manager.core.domain.type.BlockSeverityType; |
| | | import com.zy.acs.manager.core.service.LaneService; |
| | | import com.zy.acs.manager.core.service.astart.domain.DynamicNode; |
| | | import com.zy.acs.manager.manager.entity.Route; |
| | |
| | | |
| | | private final RedisSupport redis = RedisSupport.defaultRedisSupport; |
| | | |
| | | public static final boolean OPEN_TURN_COST_WEIGHT = Boolean.FALSE; |
| | | public static final boolean OPEN_TURN_COST_WEIGHT = Boolean.TRUE; |
| | | |
| | | public static final int WEIGHT_CALC_FACTOR = 1; |
| | | |
| | |
| | | private ConfigService configService; |
| | | |
| | | public synchronized NavigateNode execute(String agvNo, NavigateNode start, NavigateNode end |
| | | , Boolean lock, List<String> blackList, Segment segment, BlockSeverityType blockSeverity) { |
| | | , Boolean lock, List<String> blackList, Segment segment) { |
| | | if (start.getX() == end.getX() && start.getY() == end.getY()) { |
| | | return end; |
| | | } |
| | | Integer maxAgvCountInLane = configService.getVal("maxAgvCountInLane", Integer.class); |
| | | |
| | | PriorityQueue<NavigateNode> openQueue = new PriorityQueue<>(); |
| | | ArrayList<NavigateNode> existNodes = new ArrayList<>(); |
| | | Set<NavigateNode> existNodes = new HashSet<>(); |
| | | |
| | | openQueue.add(start); |
| | | existNodes.add(start); |
| | |
| | | DynamicNode[][] dynamicMatrix = mapDataDispatcher.getDynamicMatrix(null); |
| | | String[][] waveMatrix = mapDataDispatcher.getWaveMatrix(null); |
| | | |
| | | while (openQueue.size() > 0) { |
| | | while (!openQueue.isEmpty()) { |
| | | // 取优先队列顶部元素并且把这个元素从Open表中删除,取F值最小的节点 |
| | | NavigateNode currentNode = openQueue.poll(); |
| | | |
| | |
| | | if (!Cools.isEmpty(blackList) && blackList.contains(node.getCodeData())) { |
| | | continue; |
| | | } |
| | | // 特殊情况,当blackList有且只有一个元素且为startNode时 |
| | | // 说明blackList已经知道当前导航起始点和目标点为相邻节点 |
| | | // 但是当前blackList的任务是不让系统走相邻的最短路径,所以才会有下面的判断和continue |
| | | if (blackList.size() == 1 && blackList.get(0).equals(start.getCodeData())) { |
| | | if (isEndNode && currentNode.getCodeData().equals(start.getCodeData())) { |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | // 节点被占用 |
| | | DynamicNode dynamicNode = dynamicMatrix[node.getX()][node.getY()]; |
| | |
| | | if (!vehicle.equals(DynamicNodeType.ACCESS.val)) { |
| | | if (!vehicle.equals(agvNo)) { |
| | | |
| | | // 存在车辆,且为已经避让的车,则权重值增加 |
| | | // 如果存在车辆,则增加权重 2 或者 3,因为拐点会增加权重 1 |
| | | // vehicle已经为当前segment做过了避让,且避让任务已完成,则权重值增加 |
| | | if (null != segment) { |
| | | if (!Cools.isEmpty(jamService.getJamFromSegmentByAvo(segment, vehicle))) { |
| | | weight += WEIGHT_CALC_FACTOR; |
| | | weight += (WEIGHT_CALC_FACTOR * 3); |
| | | } else { |
| | | weight += (WEIGHT_CALC_FACTOR * 2); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | // G + H + T (对启发函数增加去拐点方案calcNodeTurnCost) |
| | | int gCost = calcNodeCost(currentNode, node) * (OPEN_TURN_COST_WEIGHT ? calcNodeTurnCost(currentNode, node, end) : 1); |
| | | int gCost = calcNodeCost(currentNode, node); |
| | | |
| | | if (OPEN_TURN_COST_WEIGHT) { |
| | | gCost += calcNodeTurnCost(currentNode, node, end); |
| | | } |
| | | |
| | | //进行计算对 G, F, H 等值 |
| | | node.setWeight(weight); |
| | |
| | | } |
| | | |
| | | // 获取四周节点 |
| | | private ArrayList<NavigateNode> getNeighborNodes(NavigateNode currentNode, int[][] mapMatrix, List<NavigateNode> existNodes) { |
| | | private ArrayList<NavigateNode> getNeighborNodes(NavigateNode currentNode, int[][] mapMatrix, Set<NavigateNode> existNodes) { |
| | | //获取当前结点的x, y |
| | | int x = currentNode.getX(); |
| | | int y = currentNode.getY(); |
| | |
| | | ArrayList<NavigateNode> neighbourNodes = new ArrayList<>(); |
| | | |
| | | NavigateNode rightNode = extendNeighborNodes(currentNode, new NavigateNode(x, y + 1), mapMatrix, existNodes, null, null); |
| | | if (is_valid(currentNode, rightNode, mapMatrix, existNodes)) { |
| | | if (is_valid(currentNode, rightNode)) { |
| | | neighbourNodes.add(rightNode); |
| | | } |
| | | |
| | | NavigateNode leftNode = extendNeighborNodes(currentNode, new NavigateNode(x, y - 1), mapMatrix, existNodes, null, null); |
| | | if (is_valid(currentNode, leftNode, mapMatrix, existNodes)) { |
| | | if (is_valid(currentNode, leftNode)) { |
| | | neighbourNodes.add(leftNode); |
| | | } |
| | | |
| | | NavigateNode topNode = extendNeighborNodes(currentNode, new NavigateNode(x - 1, y), mapMatrix, existNodes, null, null); |
| | | if (is_valid(currentNode, topNode, mapMatrix, existNodes)) { |
| | | if (is_valid(currentNode, topNode)) { |
| | | neighbourNodes.add(topNode); |
| | | } |
| | | |
| | | NavigateNode bottomNode = extendNeighborNodes(currentNode, new NavigateNode(x + 1, y), mapMatrix, existNodes, null, null); |
| | | if (is_valid(currentNode, bottomNode, mapMatrix, existNodes)) { |
| | | if (is_valid(currentNode, bottomNode)) { |
| | | neighbourNodes.add(bottomNode); |
| | | } |
| | | |
| | | return neighbourNodes; |
| | | } |
| | | |
| | | private NavigateNode extendNeighborNodes(NavigateNode currentNode, NavigateNode extendNode, int[][] mapMatrix, List<NavigateNode> existNodes, Integer dx, Integer dy) { |
| | | private NavigateNode extendNeighborNodes(NavigateNode currentNode, NavigateNode extendNode, int[][] mapMatrix, Set<NavigateNode> existNodes, Integer dx, Integer dy) { |
| | | NavigateNode nextNode = null; |
| | | |
| | | if (null == dx || null == dy) { |
| | |
| | | |
| | | } else { |
| | | |
| | | if (isExist(nextNode, existNodes)) { |
| | | if (existNodes.contains(nextNode)) { |
| | | return null; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | private boolean is_valid(NavigateNode currentNode, NavigateNode node, int[][] mapMatrix, List<NavigateNode> existNodes) { |
| | | private boolean is_valid(NavigateNode currentNode, NavigateNode node) { |
| | | if (null == node) { |
| | | return false; |
| | | } |
| | | // int x = node.getX(); |
| | | // int y = node.getY(); |
| | | // if (x < 0 || x >= mapMatrix.length |
| | | // || y < 0 || y >= mapMatrix[0].length) { |
| | | // return false; |
| | | // } |
| | | // |
| | | // // 如果结点的位置小于0,则不合法 |
| | | // if (mapMatrix[x][y] < 0) return false; |
| | | // |
| | | // if (is_exist(node, existNodes)) { |
| | | // return false; |
| | | // } |
| | | // |
| | | // // 判断通过性 |
| | | // String[][] codeMatrix = mapDataDispatcher.getCodeMatrix(null); |
| | | // String currentNodeCodeData = codeMatrix[currentNode.getX()][currentNode.getY()]; |
| | | // String nextNodeCodeData = codeMatrix[node.getX()][node.getY()]; |
| | | // node.setCodeData(nextNodeCodeData); |
| | | // |
| | | // Route route = routeService.findByCodeOfBoth( |
| | | // codeService.selectByData(currentNodeCodeData).getId(), |
| | | // codeService.selectByData(nextNodeCodeData).getId() |
| | | // ); |
| | | // if (null == route) { |
| | | // return false; |
| | | // } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | // private boolean is_exist(NavigateNode node, List<NavigateNode> existNodes) { |
| | | // for (NavigateNode exist_node : existNodes) { |
| | | // if (node.getX() == exist_node.getX() && node.getY() == exist_node.getY()) { |
| | | // return true; |
| | | // } |
| | | // } |
| | | // return false; |
| | | // } |
| | | |
| | | private boolean isExist(NavigateNode node, List<NavigateNode> existNodes) { |
| | | for (NavigateNode existNode : existNodes) { |
| | |
| | | // Code code1 = codeService.selectByData(node1.getCodeData()); |
| | | // Code code2 = codeService.selectByData(node2.getCodeData()); |
| | | // return (int) (Math.abs(code2.getX() - code1.getX()) + Math.abs(code2.getY() - code1.getY())); |
| | | |
| | | return Math.abs(node2.getX() - node1.getX()) + Math.abs(node2.getY() - node1.getY()); |
| | | } |
| | | |
| | |
| | | || nextNode.getX() == currNode.getParent().getX() |
| | | || nextNode.getY() == currNode.getParent().getY() |
| | | ) { |
| | | return 1; |
| | | return 0; |
| | | } |
| | | |
| | | // 拐向终点的点 |
| | | if (nextNode.getX() == endNode.getX() || nextNode.getY() == endNode.getY()) { |
| | | return 2; |
| | | return 1; |
| | | } |
| | | |
| | | // 普通拐点 |
| | | /* |
| | | 拐点判断逻辑 |
| | | 拿到父节点和下一节点 |
| | | 通过判断父节点和下一节点的x数据和y数据都不相同时,则表明当前坐标是一个拐点 |
| | | */ |
| | | return 3; |
| | | return 1; |
| | | } |
| | | |
| | | } |