| | |
| | | return result; |
| | | } |
| | | |
| | | public synchronized Agv execute(Task task) { |
| | | public synchronized String execute(Task task, AllocateSupport inbound, AllocateSupport normal) { |
| | | // inbound roller station |
| | | Sta rollerOriSta = getInboundRollerSta(task); |
| | | if (rollerOriSta != null) { |
| | | List<String> availableAgvNos = this.getAvailableAgvNos(agvAreaDispatcher.getAgvNosByTask(task), true); |
| | | FilterLaneDto filterLaneDto = this.filterThroughLane(task, availableAgvNos); |
| | | if (null != filterLaneDto) { |
| | | String agvNo = this.checkoutAgvForInboundRoller(task, rollerOriSta, filterLaneDto.getActualAvailableAgvNos()); |
| | | if (!Cools.isEmpty(agvNo)) { |
| | | task.setOriLaneHash(filterLaneDto.getOriginLane().getHashCode()); |
| | | task.setDestLaneHash(filterLaneDto.getDestinationLane().getHashCode()); |
| | | return agvService.selectByUuid(agvNo); |
| | | } |
| | | } |
| | | String inboundAgv = tryAllocateForRoller(task, rollerOriSta, true); |
| | | if (!Cools.isEmpty(inboundAgv)) { |
| | | inbound.success(task, inboundAgv); |
| | | return inboundAgv; |
| | | } |
| | | |
| | | // outbound roller station |
| | | Sta rollerDestSta = getOutboundRollerSta(task); |
| | | if (rollerDestSta != null) { |
| | | List<String> availableAgvNos = this.getAvailableAgvNos(agvAreaDispatcher.getAgvNosByTask(task), true); |
| | | FilterLaneDto filterLaneDto = this.filterThroughLane(task, availableAgvNos); |
| | | if (null != filterLaneDto) { |
| | | String agvNo = this.checkoutAgvForOutboundRoller(task, rollerDestSta, filterLaneDto.getActualAvailableAgvNos()); |
| | | if (!Cools.isEmpty(agvNo)) { |
| | | task.setOriLaneHash(filterLaneDto.getOriginLane().getHashCode()); |
| | | task.setDestLaneHash(filterLaneDto.getDestinationLane().getHashCode()); |
| | | return agvService.selectByUuid(agvNo); |
| | | } |
| | | } |
| | | String outboundAgv = tryAllocateForRoller(task, rollerDestSta, false); |
| | | if (!Cools.isEmpty(outboundAgv)) { |
| | | normal.success(task, outboundAgv); |
| | | return outboundAgv; |
| | | } |
| | | |
| | | return this.normalExecute(task); |
| | | String normalAgv = this.normalExecute(task); |
| | | if (!Cools.isEmpty(normalAgv)) { |
| | | normal.success(task, normalAgv); |
| | | return normalAgv; |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | private String tryAllocateForRoller(Task task, Sta rollerSta, boolean inbound) { |
| | | if (rollerSta == null) { |
| | | return null; |
| | | } |
| | | |
| | | List<String> availableAgvNos = this.getAvailableAgvNos(agvAreaDispatcher.getAgvNosByTask(task), true); |
| | | FilterLaneDto filterLaneDto = this.filterThroughLane(task, availableAgvNos); |
| | | if (filterLaneDto == null) { |
| | | return null; |
| | | } |
| | | |
| | | String agvNo = inbound |
| | | ? this.checkoutAgvForInboundRoller(task, rollerSta, filterLaneDto.getActualAvailableAgvNos()) |
| | | : this.checkoutAgvForOutboundRoller(task, rollerSta, filterLaneDto.getActualAvailableAgvNos()); |
| | | if (Cools.isEmpty(agvNo)) { |
| | | return null; |
| | | } |
| | | |
| | | // record lane hash for later dispatch/traffic-control logic |
| | | if (filterLaneDto.getOriginLane() != null) { |
| | | task.setOriLaneHash(filterLaneDto.getOriginLane().getHashCode()); |
| | | } |
| | | if (filterLaneDto.getDestinationLane() != null) { |
| | | task.setDestLaneHash(filterLaneDto.getDestinationLane().getHashCode()); |
| | | } |
| | | |
| | | return agvNo; |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * it can break the limit of the number of agv backpack |
| | | */ |
| | | public synchronized Agv normalExecute(Task task) { |
| | | public synchronized String normalExecute(Task task) { |
| | | List<String> availableAgvNos = this.getAvailableAgvNos(agvAreaDispatcher.getAgvNosByTask(task), false); |
| | | // List<String> availableAgvNos = this.getAvailableAgvNos(null); |
| | | if (Cools.isEmpty(availableAgvNos)) { |
| | |
| | | Lane originLane = filterLaneDto.getOriginLane(); |
| | | Lane destinationLane = filterLaneDto.getDestinationLane(); |
| | | List<String> actualAvailableAgvNos = filterLaneDto.getActualAvailableAgvNos(); |
| | | if (Cools.isEmpty(actualAvailableAgvNos)) { |
| | | return null; |
| | | } |
| | | |
| | | // choose min number of running task |
| | | actualAvailableAgvNos.sort(new Comparator<String>() { |
| | | @Override |
| | | public int compare(String agvNo1, String agvNo2) { |
| | | return calcAllocateWeight(agvNo1, task) - calcAllocateWeight(agvNo2, task); |
| | | } |
| | | }); |
| | | actualAvailableAgvNos.sort(Comparator.comparingInt(agvNo -> calcAllocateWeight(agvNo, task))); |
| | | |
| | | if (null != originLane) { |
| | | task.setOriLaneHash(originLane.getHashCode()); |
| | |
| | | task.setDestLaneHash(destinationLane.getHashCode()); |
| | | } |
| | | |
| | | return agvService.selectByUuid(actualAvailableAgvNos.stream().findFirst().orElse(null)); |
| | | return actualAvailableAgvNos.get(0); |
| | | } |
| | | |
| | | private String checkoutAgvForInboundRoller(Task task, Sta sta, List<String> availableAgvNos) { |
| | |
| | | ) |
| | | ); |
| | | if (taskCnt == 0) { |
| | | break; |
| | | continue; |
| | | } |
| | | |
| | | // has enough backpack space to load |
| | | Integer backpack = agvService.getBackpack(agvId); |
| | | int countRemainingBackpack = segmentService.countRemainingBackpack(null, agvId); |
| | | if (countRemainingBackpack >= backpack) { |
| | | break; |
| | | continue; |
| | | } |
| | | |
| | | return agvNo; |