| | |
| | | |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.manager.common.utils.MapDataUtils; |
| | | import com.zy.acs.manager.core.domain.VehicleDto; |
| | | import com.zy.acs.manager.core.domain.Lane; |
| | | 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; |
| | | 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 org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | @Service |
| | | public class AStarNavigateService { |
| | | |
| | | public static final boolean OPEN_TURN_COST_WEIGHT = Boolean.FALSE; |
| | | |
| | | @Autowired |
| | | private CodeService codeService; |
| | | @Autowired |
| | |
| | | private MapDataDispatcher mapDataDispatcher; |
| | | @Autowired |
| | | private AgvService agvService; |
| | | |
| | | public static final boolean OPEN_TURN_COST_WEIGHT = Boolean.FALSE; |
| | | @Autowired |
| | | private LaneService laneService; |
| | | @Autowired |
| | | private ConfigService configService; |
| | | |
| | | public synchronized NavigateNode execute(String agvNo, NavigateNode start, NavigateNode end |
| | | , Boolean lock, List<String> whiteList, List<String> blackList) { |
| | | , Boolean lock, List<String> blackList) { |
| | | 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<>(); |
| | |
| | | DynamicNode[][] dynamicMatrix = mapDataDispatcher.getDynamicMatrix(null); |
| | | String[][] waveMatrix = mapDataDispatcher.getWaveMatrix(null); |
| | | |
| | | List<String> included = new ArrayList<>(); |
| | | // List<String> included = new ArrayList<>(); |
| | | // if (!Cools.isEmpty(whiteList)) { |
| | | // included.addAll(whiteList); |
| | | // } |
| | | included.add(agvNo); |
| | | List<VehicleDto> vehicleDtoList = agvService.getVehicleDtoList(included); |
| | | // included.add(agvNo); |
| | | // List<VehicleDto> vehicleDtoList = agvService.getVehicleDtoList(included); |
| | | |
| | | while (openQueue.size() > 0) { |
| | | // 取优先队列顶部元素并且把这个元素从Open表中删除,取F值最小的节点 |
| | |
| | | label: for (NavigateNode node : neighbourNodes) { |
| | | |
| | | // 节点存在其他车辆 |
| | | for (VehicleDto vehicleDto : vehicleDtoList) { |
| | | if (node.getCodeData().equals(vehicleDto.getPosCode())) { |
| | | if (!Cools.isEmpty(blackList) && blackList.contains(vehicleDto.getVehicle())) { |
| | | continue label; |
| | | } |
| | | if (lock) { |
| | | continue label; |
| | | } |
| | | } |
| | | } |
| | | // for (VehicleDto vehicleDto : vehicleDtoList) { |
| | | // if (node.getCodeData().equals(vehicleDto.getPosCode())) { |
| | | // if (!Cools.isEmpty(blackList) && blackList.contains(vehicleDto.getVehicle())) { |
| | | // continue label; |
| | | // } |
| | | // if (lock) { |
| | | // continue label; |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | // 节点被占用 |
| | | DynamicNode dynamicNode = dynamicMatrix[node.getX()][node.getY()]; |
| | |
| | | List<String> otherWaveList = MapDataUtils.hasOtherWave(waveNodeList, agvNo); |
| | | |
| | | if (!Cools.isEmpty(otherWaveList)) { |
| | | if (!Cools.isEmpty(blackList) && !Cools.isEmpty(MapDataUtils.hasIntersection(otherWaveList, blackList))) { |
| | | if (!Cools.isEmpty(blackList) && 0 < Cools.getIntersection(otherWaveList, blackList).size()) { |
| | | continue; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | // 单巷道车辆容载数量 |
| | | Lane lane = laneService.search(node.getCodeData()); |
| | | if (null != lane) { |
| | | int otherVehicleCount = 0; |
| | | |
| | | 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)) { |
| | | otherVehicleCount++; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (otherVehicleCount + 1 > maxAgvCountInLane) { |
| | | if (lock) { |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | //找到目标结点就返回 |
| | | if (node.getX() == end.getX() && node.getY() == end.getY()) { |
| | | //并且计算出G, F, H等值 |