| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * Created by vincent on 8/12/2024 |
| | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * it can break the limit of the number of agv backpack |
| | | */ |
| | | public synchronized Agv execute(Task task) { |
| | | List<Agv> availableAgvList = getAvailableAgv(); |
| | | if (Cools.isEmpty(availableAgvList)) { |
| | | log.warn("No available agv to assign the task[{}]", task.getSeqNum()); |
| | | return null; |
| | | } |
| | | List<String> availableAgvNos = availableAgvList.stream().map(Agv::getUuid).distinct().collect(Collectors.toList()); |
| | | |
| | | Integer maxAgvCountInLane = configService.getVal("maxAgvCountInLane", Integer.class); |
| | | |
| | |
| | | Lane originLane = taskService.checkoutOriginLane(task); |
| | | Lane destinationLane = taskService.checkoutDestinationLane(task); |
| | | |
| | | |
| | | // allocate about origin |
| | | taskService.findTasksByLaneHash(originLane.getHashCode()); |
| | | List<String> availableAgvNosByOriLane = new ArrayList<>(availableAgvNos); |
| | | if (null != originLane) { |
| | | List<String> agvNosByOriLane = findAgvNosByLane(originLane); // the agv list that had tasks in this lane |
| | | if (!Cools.isEmpty(agvNosByOriLane) && agvNosByOriLane.size() >= maxAgvCountInLane) { |
| | | |
| | | availableAgvNosByOriLane = Cools.getIntersection(agvNosByOriLane, availableAgvNos); |
| | | availableAgvNosByOriLane = availableAgvNosByOriLane.stream().filter(agvNo -> { |
| | | Agv agv = agvService.selectByUuid(agvNo); |
| | | |
| | | return agv.getStatus() == 1; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | } |
| | | |
| | | |
| | | // allocate about destination |
| | | taskService.findTasksByLaneHash(destinationLane.getHashCode()); |
| | | List<String> availableAgvNosByDestLane = new ArrayList<>(availableAgvNos); |
| | | if (null != destinationLane) { |
| | | List<String> agvNosByDestLane = findAgvNosByLane(destinationLane); |
| | | if (!Cools.isEmpty(agvNosByDestLane) && agvNosByDestLane.size() >= maxAgvCountInLane) { |
| | | |
| | | availableAgvNosByDestLane = Cools.getIntersection(agvNosByDestLane, availableAgvNos); |
| | | availableAgvNosByDestLane = availableAgvNosByDestLane.stream().filter(agvNo -> { |
| | | Agv agv = agvService.selectByUuid(agvNo); |
| | | |
| | | return agv.getStatus() == 1; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | } |
| | | |
| | | // valid |
| | | if (Cools.isEmpty(availableAgvNosByOriLane)) { |
| | | log.warn("No available agv to assign the task origin[{}]", task.getSeqNum()); |
| | | return null; |
| | | } |
| | | if (Cools.isEmpty(availableAgvNosByDestLane)) { |
| | | log.warn("No available agv to assign the task destination[{}]", task.getSeqNum()); |
| | | return null; |
| | | } |
| | | |
| | | List<String> actualAvailableAgvNos = Cools.getIntersection(availableAgvNosByOriLane, availableAgvNosByDestLane); |
| | | if (Cools.isEmpty(actualAvailableAgvNos)) { |
| | | log.warn("No available agv to assign the task[{}]", task.getSeqNum()); |
| | | return null; |
| | | } |
| | | |
| | | actualAvailableAgvNos.sort(new Comparator<String>() { |
| | | @Override |
| | | public int compare(String o1, String o2) { |
| | | return 0; |
| | | } |
| | | }); |
| | | |
| | | String s = actualAvailableAgvNos.stream().findFirst().orElse(null); |
| | | |
| | | |
| | | /** |
| | | * 1. 判断task的起始点和目的点所在的巷道承载任务数量, |
| | |
| | | * 判断逻辑:背篓数量最少的小车轮询的时候,优先级最高 |
| | | */ |
| | | |
| | | |
| | | task.setOriLaneHash(originLane.getHashCode()); |
| | | task.setDestLaneHash(destinationLane.getHashCode()); |
| | | |
| | | return null; |
| | | } |
| | | |
| | | private List<String> findAgvNosByLane(Lane lane) { |
| | | if (null == lane) { |
| | | return null; |
| | | } |
| | | List<Task> taskList = taskService.findRunningTasksByLaneHash(lane.getHashCode()); |
| | | if (Cools.isEmpty(taskList)) { |
| | | return null; |
| | | } |
| | | return taskList.stream().map(task -> { |
| | | return agvService.getById(task.getAgvId()).getUuid(); |
| | | }).distinct().collect(Collectors.toList()); |
| | | } |
| | | |
| | | public synchronized Agv execute(Task task, Map<String, List<Long>> taskAllot, List<Long> taskIds) { |
| | | String oriLocNo = task.getOriLoc$(); |
| | | int oriLocRow = LocUtils.getRow(oriLocNo); |