| | |
| | | package com.zy.acs.manager.core.service; |
| | | |
| | | import com.zy.acs.common.utils.RedisSupport; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.common.utils.Utils; |
| | | import com.zy.acs.manager.common.utils.MapDataUtils; |
| | | import com.zy.acs.manager.core.constant.MapDataConstant; |
| | | import com.zy.acs.manager.core.domain.Lane; |
| | | import com.zy.acs.manager.core.service.astart.*; |
| | | import com.zy.acs.manager.core.service.astart.domain.DynamicNode; |
| | | import com.zy.acs.manager.manager.entity.Jam; |
| | | import com.zy.acs.manager.manager.entity.Route; |
| | | import com.zy.acs.manager.manager.service.AgvModelService; |
| | | import com.zy.acs.manager.manager.service.AgvService; |
| | | import com.zy.acs.manager.manager.service.CodeService; |
| | | import com.zy.acs.manager.manager.service.RouteService; |
| | | 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.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.PriorityQueue; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | @Slf4j |
| | | @Service |
| | | public class RetreatNavigateService { |
| | | |
| | | private final RedisSupport redis = RedisSupport.defaultRedisSupport; |
| | | |
| | | public static final int WEIGHT_CALC_COEFFICIENT = 1000; |
| | | |
| | | @Autowired |
| | | private CodeService codeService; |
| | |
| | | private AgvService agvService; |
| | | @Autowired |
| | | private AgvModelService agvModelService; |
| | | @Autowired |
| | | private LaneService laneService; |
| | | @Autowired |
| | | private ConfigService configService; |
| | | |
| | | /** |
| | | * avoidPathList ===>> [ minor vehicle ] [wave] [ curr vehicle ] [ code2 ] [ code3 ] ...... |
| | |
| | | return null; |
| | | } |
| | | Integer lev = null; |
| | | Integer maxAgvCountInLane = configService.getVal("maxAgvCountInLane", Integer.class); |
| | | |
| | | String breakPoint = avoidPathList.stream().findFirst().orElse(null); |
| | | List<String> blackList = Utils.singletonList(sponsor); |
| | |
| | | , MapDataConstant.IDLE_DISTANCE_COE); |
| | | List<String> avoidPathListWave = mapService.getWaveScopeByCodeList(lev, avoidPathList, avoidDistance); |
| | | |
| | | DynamicNode[][] dynamicMatrix = mapDataDispatcher.getDynamicMatrix(lev); |
| | | String[][] waveMatrix = mapDataDispatcher.getWaveMatrix(lev); |
| | | |
| | | |
| | | |
| | | RetreatNavigateNode finialNode = null; |
| | |
| | | List<RetreatNavigateNode> enableNodes = new ArrayList<>(); |
| | | |
| | | ArrayList<RetreatNavigateNode> neighborNodes = this.getNeighborNodes(currentNode, existNodes); |
| | | for (RetreatNavigateNode node : neighborNodes) { |
| | | label: for (RetreatNavigateNode node : neighborNodes) { |
| | | if (node.getCodeData().equals(breakPoint)) { continue; } |
| | | |
| | | int weight = 0; |
| | | |
| | | // wave |
| | | String waveNode = waveMatrix[node.getX()][node.getY()]; |
| | | assert !waveNode.equals(WaveNodeType.DISABLE.val); |
| | | if (!waveNode.equals(WaveNodeType.ENABLE.val)) { |
| | | List<String> waveNodeList = MapDataUtils.parseWaveNode(waveNode); |
| | | List<String> otherWaveList = MapDataUtils.hasOtherWave(waveNodeList, agvNo); |
| | | if (!Cools.isEmpty(otherWaveList)) { |
| | | |
| | | if (!Cools.isEmpty(blackList) && 0 < Cools.getIntersection(otherWaveList, blackList).size()) { |
| | | continue; |
| | | for (String otherWave : otherWaveList) { |
| | | if (!Cools.isEmpty(blackList) && blackList.contains(otherWave)) { |
| | | continue label; |
| | | } |
| | | if (1 < mapDataDispatcher.queryCodeListFromDynamicNode(lev, otherWave).size()) { |
| | | continue label; |
| | | } else { |
| | | weight += WEIGHT_CALC_COEFFICIENT; |
| | | } |
| | | } |
| | | } |
| | | |
| | | weight += otherWaveList.size(); |
| | | // lane |
| | | Lane lane = laneService.search(node.getCodeData()); |
| | | if (null != lane) { |
| | | Set<String> lanVehicleSet = new HashSet<>(); |
| | | |
| | | List<String> laneCodes = lane.getCodes(); |
| | | for (String laneCodeData : laneCodes) { |
| | | int[] laneCodeMatrixIdx = mapDataDispatcher.getCodeMatrixIdx(null, laneCodeData); |
| | | // scan dynamicMatrix or WaveMatrix |
| | | DynamicNode laneDynamicNode = dynamicMatrix[laneCodeMatrixIdx[0]][laneCodeMatrixIdx[1]]; |
| | | String laneVehicle = laneDynamicNode.getVehicle(); |
| | | assert !laneVehicle.equals(DynamicNodeType.BLOCK.val); |
| | | if (!laneVehicle.equals(DynamicNodeType.ACCESS.val)) { |
| | | if (!laneVehicle.equals(agvNo)) { |
| | | lanVehicleSet.add(laneVehicle); |
| | | // redis.setObject(RedisConstant.AGV_TO_STANDBY_FLAG, laneVehicle, true, 30); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (lanVehicleSet.size() + 1 > maxAgvCountInLane) { |
| | | continue; |
| | | } |
| | | } |
| | | |
| | |
| | | .stream().map(NavigateNode::getCodeData).distinct().collect(Collectors.toList()); |
| | | } |
| | | |
| | | for (RetreatNavigateNode node : neighborNodes) { |
| | | label: for (RetreatNavigateNode node : neighborNodes) { |
| | | |
| | | int weight = 0; |
| | | |
| | | // wave |
| | | String waveNode = waveMatrix[node.getX()][node.getY()]; |
| | | assert !waveNode.equals(WaveNodeType.DISABLE.val); |
| | | if (!waveNode.equals(WaveNodeType.ENABLE.val)) { |
| | | List<String> waveNodeList = MapDataUtils.parseWaveNode(waveNode); |
| | | List<String> otherWaveList = MapDataUtils.hasOtherWave(waveNodeList, agvNo); |
| | | if (!Cools.isEmpty(otherWaveList)) { |
| | | for (String otherWave : otherWaveList) { |
| | | if (!Cools.isEmpty(blackList) && blackList.contains(otherWave)) { |
| | | continue; |
| | | } |
| | | if (1 < mapDataDispatcher.queryCodeListFromDynamicNode(lev, otherWave).size()) { |
| | | continue label; |
| | | } else { |
| | | weight += WEIGHT_CALC_COEFFICIENT; |
| | | } |
| | | } |
| | | } |
| | | |
| | | weight += otherWaveList.size(); |
| | | // lane |
| | | Lane lane = laneService.search(node.getCodeData()); |
| | | if (null != lane) { |
| | | Set<String> lanVehicleSet = new HashSet<>(); |
| | | |
| | | List<String> laneCodes = lane.getCodes(); |
| | | for (String laneCodeData : laneCodes) { |
| | | int[] laneCodeMatrixIdx = mapDataDispatcher.getCodeMatrixIdx(null, laneCodeData); |
| | | // scan dynamicMatrix or WaveMatrix |
| | | DynamicNode laneDynamicNode = dynamicMatrix[laneCodeMatrixIdx[0]][laneCodeMatrixIdx[1]]; |
| | | String laneVehicle = laneDynamicNode.getVehicle(); |
| | | assert !laneVehicle.equals(DynamicNodeType.BLOCK.val); |
| | | if (!laneVehicle.equals(DynamicNodeType.ACCESS.val)) { |
| | | if (!laneVehicle.equals(agvNo)) { |
| | | lanVehicleSet.add(laneVehicle); |
| | | // redis.setObject(RedisConstant.AGV_TO_STANDBY_FLAG, laneVehicle, true, 30); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (lanVehicleSet.size() + 1 > maxAgvCountInLane) { |
| | | continue; |
| | | } |
| | | } |
| | | |