| | |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.manager.common.utils.MapDataUtils; |
| | | import com.zy.acs.manager.core.constant.MapDataConstant; |
| | | import com.zy.acs.manager.core.domain.UnlockPathTask; |
| | | import com.zy.acs.manager.core.service.astart.*; |
| | | import com.zy.acs.manager.core.service.astart.domain.DynamicNode; |
| | | import com.zy.acs.manager.core.service.astart.domain.AStarNavigateNode; |
| | | import com.zy.acs.manager.core.service.floyd.FloydNavigateService; |
| | | import com.zy.acs.manager.manager.entity.Code; |
| | | import com.zy.acs.manager.manager.entity.Loc; |
| | |
| | | import com.zy.acs.manager.manager.service.CodeService; |
| | | import com.zy.acs.manager.system.service.ConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.time.StopWatch; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.*; |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private ConfigService configService; |
| | | @Autowired |
| | | private ActionService actionService; |
| | | @Autowired |
| | | private LinkedBlockingQueue<UnlockPathTask> unlockTaskQueue; |
| | | |
| | | /** |
| | | * 寻址 ===>> A Star |
| | |
| | | int[] startMapIdx = mapDataDispatcher.getCodeMatrixIdx(null, startCode.getData()); |
| | | int[] endMapIdx = mapDataDispatcher.getCodeMatrixIdx(null, endCode.getData()); |
| | | |
| | | NavigateNode startNode = new NavigateNode(startMapIdx[0], startMapIdx[1], startCode.getData()); |
| | | NavigateNode endNode = new NavigateNode(endMapIdx[0], endMapIdx[1], endCode.getData()); |
| | | AStarNavigateNode startNode = new AStarNavigateNode(startMapIdx[0], startMapIdx[1], startCode.getData()); |
| | | AStarNavigateNode endNode = new AStarNavigateNode(endMapIdx[0], endMapIdx[1], endCode.getData()); |
| | | |
| | | NavigateNode finishNode = aStarNavigateService.execute(agvNo, startNode, endNode, lock, blackList, segment); |
| | | |
| | | // long startTime = System.currentTimeMillis(); |
| | | AStarNavigateNode finishNode = aStarNavigateService.execute(agvNo, startNode, endNode, lock, blackList, segment); |
| | | // System.out.println("A Star Spend time :" + (System.currentTimeMillis() - startTime)); |
| | | if (null == finishNode) { |
| | | log.warn("{} 号AGV检索[{}] ===>> [{}]路径失败......", agvNo, startCode.getData(), endCode.getData()); |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | ArrayList<NavigateNode> navigateNodes = new ArrayList<>(); |
| | | ArrayList<AStarNavigateNode> navigateNodes = new ArrayList<>(); |
| | | |
| | | // 渲染 |
| | | NavigateNode parentNode = null; // 当前循环上一节点,用于拐点计算 |
| | | while (finishNode != null) { |
| | | navigateNodes.add(finishNode); |
| | | |
| | | parentNode = finishNode; |
| | | finishNode = finishNode.getParent(); |
| | | } |
| | | |
| | | Collections.reverse(navigateNodes); |
| | | |
| | | // for (NavigateNode navigateNode : navigateNodes) { |
| | | // navigateNode.setParent(null); |
| | | // } |
| | | |
| | | List<String> navigatePath = navigateNodes.stream().map(NavigateNode::getCodeData).collect(Collectors.toList()); |
| | | List<String> navigatePath = navigateNodes.stream().map(AStarNavigateNode::getCodeData).collect(Collectors.toList()); |
| | | |
| | | // max count of steps |
| | | if (navigatePath.size() > MapDataConstant.MAX_STEPS_SINGLE) { |
| | |
| | | } |
| | | |
| | | public void lockPath(Integer lev, List<String> pathList, String agvNo) { |
| | | mapDataDispatcher.modifyDynamicMatrix(lev, pathList, agvNo); |
| | | List<int[]> codeMatrixIdxList = mapDataDispatcher.getCodeMatrixIdxList(lev, pathList); |
| | | mapDataDispatcher.modifyDynamicMatrix(lev, codeMatrixIdxList, agvNo); |
| | | } |
| | | |
| | | public synchronized void unlockPath(String agvNo, String codeData) { |
| | | public void unlockPath(String agvNo, String codeData) { |
| | | try { |
| | | StopWatch stopWatch = new StopWatch(); |
| | | stopWatch.start(); |
| | | |
| | | if (Cools.isEmpty(agvNo, codeData)) { |
| | | return; |
| | | } |
| | | |
| | | Integer lev = null; |
| | | |
| | | String[][] codeMatrix = mapDataDispatcher.getCodeMatrix(null); |
| | | int[] codeMatrixIdx = mapDataDispatcher.getCodeMatrixIdx(lev, codeData); |
| | | |
| | | |
| | | DynamicNode[][] dynamicMatrix = mapDataDispatcher.getDynamicMatrix(lev); |
| | | |
| | | DynamicNode dynamicNode = dynamicMatrix[codeMatrixIdx[0]][codeMatrixIdx[1]]; |
| | | |
| | | |
| | | Integer serial = dynamicNode.getSerial(); |
| | | |
| | | List<String> resetCodeList = new ArrayList<>(); |
| | | |
| | | for (int i = 0; i < dynamicMatrix.length; i++) { |
| | | for (int j = 0; j < dynamicMatrix[i].length; j++) { |
| | | DynamicNode node = dynamicMatrix[i][j]; |
| | | if (node.getVehicle().equals(agvNo) && node.getSerial() < serial) { |
| | | resetCodeList.add(codeMatrix[i][j]); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!Cools.isEmpty(resetCodeList)) { |
| | | |
| | | mapDataDispatcher.clearDynamicMatrixByCodeList(lev, resetCodeList); |
| | | } |
| | | |
| | | stopWatch.stop(); |
| | | if (stopWatch.getTime() > 50) { |
| | | log.info("解锁路径函数花费时间为:{}毫秒......", stopWatch.getTime()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("MapService.unlockPath", e); |
| | | unlockTaskQueue.offer(new UnlockPathTask(agvNo, codeData), 5, TimeUnit.SECONDS); |
| | | } catch (InterruptedException e) { |
| | | log.error("unlockTaskQueue", e); |
| | | } |
| | | |
| | | } |
| | | |
| | | public List<String> getWaveScopeByCodeList(Integer lev, List<String> codeList, Double radiusLen) { |
| | |
| | | NavigateNode originNode = new NavigateNode(codeMatrixIdx[0], codeMatrixIdx[1], code); |
| | | |
| | | List<NavigateNode> includeList = new ArrayList<>(); |
| | | List<NavigateNode> existNodes = new ArrayList<>(); |
| | | Set<NavigateNode> existNodes = new HashSet<>(); |
| | | |
| | | includeList.add(originNode); |
| | | existNodes.add(originNode); |
| | |
| | | |
| | | public void spreadWaveNode(NavigateNode originNode, NavigateNode currNode |
| | | , String[][] codeMatrix, String[][] cdaMatrix, Double radiusLen |
| | | , List<NavigateNode> includeList, List<NavigateNode> existNodes) { |
| | | , List<NavigateNode> includeList, Set<NavigateNode> existNodes) { |
| | | int x = currNode.getX(); |
| | | int y = currNode.getY(); |
| | | |
| | |
| | | |
| | | public void extendNeighborNodes(NavigateNode originNode, NavigateNode nextNode |
| | | , String[][] codeMatrix, String[][] cdaMatrix, Double radiusLen |
| | | , List<NavigateNode> includeList, List<NavigateNode> existNodes) { |
| | | , List<NavigateNode> includeList, Set<NavigateNode> existNodes) { |
| | | |
| | | int x = nextNode.getX(); |
| | | int y = nextNode.getY(); |
| | |
| | | return; |
| | | } |
| | | |
| | | if (this.isExist(nextNode, existNodes)) { |
| | | if (existNodes.contains(nextNode)) { |
| | | return; |
| | | } |
| | | |
| | | existNodes.add(nextNode); |
| | | |
| | | String nextNodeCodeData = codeMatrix[x][y]; |
| | | |
| | | if (nextNodeCodeData.equals(CodeNodeType.NONE.val)) { |
| | | List<Double> o1Cda = MapDataUtils.parseCdaNode(cdaMatrix[originNode.getX()][originNode.getY()]); |
| | | List<Double> o2Cda = MapDataUtils.parseCdaNode(cdaMatrix[x][y]); |
| | | |
| | | if (Math.pow(o1Cda.get(0) - o2Cda.get(0), 2) + Math.pow(o1Cda.get(1) - o2Cda.get(1), 2) <= Math.pow(radiusLen, 2)) { |
| | | nextNode.setCodeData(codeMatrix[x][y]); |
| | | |
| | | if (!nextNode.getCodeData().equals(CodeNodeType.NONE.val)) { |
| | | includeList.add(nextNode); |
| | | } |
| | | |
| | | this.spreadWaveNode(originNode, nextNode, codeMatrix, cdaMatrix, radiusLen, includeList, existNodes); |
| | | |
| | | } else { |
| | | |
| | | List<Double> o1Cda = MapDataUtils.parseCdaNode(cdaMatrix[originNode.getX()][originNode.getY()]); |
| | | List<Double> o2Cda = MapDataUtils.parseCdaNode(cdaMatrix[nextNode.getX()][nextNode.getY()]); |
| | | |
| | | // if (Math.pow(o1.getX() - o2.getX(), 2) + Math.pow(o1.getY() - o2.getY(), 2) <= Math.pow(radiusLen, 2)) { |
| | | if (Math.pow(o1Cda.get(0) - o2Cda.get(0), 2) + Math.pow(o1Cda.get(1) - o2Cda.get(1), 2) <= Math.pow(radiusLen, 2)) { |
| | | nextNode.setCodeData(nextNodeCodeData); |
| | | includeList.add(nextNode); |
| | | |
| | | this.spreadWaveNode(originNode, nextNode, codeMatrix, cdaMatrix, radiusLen, includeList, existNodes); |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | private boolean isExist(NavigateNode node, List<NavigateNode> existNodes) { |
| | | for (NavigateNode existNode : existNodes) { |
| | | if (this.isSame(node, existNode)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private boolean isSame(NavigateNode o1, NavigateNode o2) { |
| | | if (Cools.isEmpty(o1, o2)) { |
| | | return false; |
| | | } |
| | | return o1.getX() == o2.getX() && o1.getY() == o2.getY(); |
| | | } |
| | | |
| | | // v2 BFS ------------------------------------------------------------------------------ |
| | |
| | | } |
| | | |
| | | // If the node has already been visited, skip it |
| | | if (this.isExist0(nextNode, visited)) { |
| | | if (visited.contains(nextNode)) { |
| | | return; |
| | | } |
| | | |
| | |
| | | queue.offer(nextNode); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private boolean isExist0(NavigateNode node, Set<NavigateNode> existNodes) { |
| | | for (NavigateNode existNode : existNodes) { |
| | | if (this.isSame(node, existNode)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | |