/
nikolay470
/
algorithm_implementation
Обзор
Документация
Войти
/
nikolay470
/
algorithm_implementation
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/java/ru/gitflic/classes/Application.java
794 строки
25 KB
nikolay94
Коммит перед сменой ОС
21 июн 2026, 19:09
21 июн 2026, 19:09
24ae6bf
Код
Авторство
О чём код?
package ru.gitflic.classes; import ru.gitflic.comparators.ComparatorPrintedCellsByQuantityPallets; import ru.gitflic.enums.ZonesTypes; import ru.gitflic.exceptions.GoBack; import java.util.ArrayList; import java.util.HashMap; import java.util.Objects; public class Application { private static final HashMap<Pallet, Address> storageOfCellsForPlacement = new HashMap<>(); // Размещение паллет с приемки public static void placement( Zone acceptanceZone, Employee employee, PrintedRack printedRack, ArrayList<StandardRack> standardRacksHall3, ArrayList <StandardRack> standardRacksHall4) { while (acceptanceZone.quantPalletInZone() > 0) { try { int numberPalletSheet = ConsoleView .pickUpThePalletFromAcceptance(acceptanceZone.palletsOnAcceptance()); Pallet pallet = acceptanceZone.getPalletInZone(numberPalletSheet); pallet.take( employee.login ); employee.takeThePallet( pallet ); while ( true ) { Address addressForPlacement = Address.NULL(); boolean isContains = storageOfCellsForPlacement.containsKey(pallet); Address recommendedAddress = ( isContains ? storageOfCellsForPlacement.get(pallet) : null); addressForPlacement = getAddressCellForPlacement( recommendedAddress, printedRack, storageOfCellsForPlacement, pallet); memorizeCellForPlacement( recommendedAddress, addressForPlacement, pallet, storageOfCellsForPlacement); placementThePalletInCell( employee, pallet, addressForPlacement, printedRack, standardRacksHall3, standardRacksHall4); } } catch ( GoBack exception ) { return; } catch ( Exception exception ) { ConsoleView.console.println(exception.getMessage()); } } ConsoleView.console.println( "Все паллеты размещены!" ); } // Свободное перемещение паллет public static void moving ( Employee employee, PrintedRack printedRack, ArrayList <StandardRack> standardRacksHall3, ArrayList <StandardRack> standardRacksHall4, ArrayList <Pallet> allPallets, ArrayList <Integer> listPalletSheets, Zone bufferedZone) { while ( true ) { try { int numberPalletSheet = ConsoleView.pickUpPallet( listPalletSheets ); Pallet pallet = searchPallet( numberPalletSheet, allPallets ); Address addressOfPallet = Objects.requireNonNull(pallet).getAddress(); boolean isFindCellForWriteOffPallet = searchThePalletAndWriteOffFromCell( addressOfPallet, numberPalletSheet, printedRack, standardRacksHall3, standardRacksHall4); if (isFindCellForWriteOffPallet) { pallet.take(employee.login); employee.takeThePallet(pallet); } else { throw new RuntimeException("Паллет не найден по адресу"); } placementThePallet( employee, pallet, bufferedZone, printedRack, standardRacksHall3, standardRacksHall4); } catch ( GoBack exception ) { return; } catch ( Exception exception ) { ConsoleView.console.println( exception.getMessage() ); } } } // Отбор паллет из ЗПХ public static void selectionPalletsFromZonePalletStorage( Employee employee, HashMap<Integer,OrderOnShipment> listOrdersOnShipments) { if (!listOrdersOnShipments.isEmpty()) { try { OrderOnShipment targetOrderOnShipment = getOrderOnShipmentForSelectionFullPallets(listOrdersOnShipments); do { Pallet targetPallet = ConsoleView.printTaskOnSelectionFromZonePalletStorage( targetOrderOnShipment, targetOrderOnShipment.currentAddress_FullPallets); try { targetPallet.take(employee.login); employee.takeThePallet(targetPallet); targetOrderOnShipment.fullPallets .get(targetOrderOnShipment.currentAddress_FullPallets).remove(targetPallet); Address addressShipment = ConsoleView.placementThePalletInCellShipment(); placementThePalletInCellShipment( employee, targetPallet, addressShipment); } catch (Exception e) { ConsoleView.console.println(e.getMessage()); } } while (checkAvailabilityOfTasksOnSelectionFullPallets(targetOrderOnShipment)); ConsoleView.console.println("Паллеты по заказу отобраны."); } catch (GoBack e) { return; } } else { ConsoleView.console.println("Список заказов пуст."); return; } } // Отбор остатков из зоны отбора public static void selectionRemnantsFromSelectionZone( Employee employee, HashMap<Integer, OrderOnShipment> listOrdersOnShipments) throws GoBack { if (!listOrdersOnShipments.isEmpty()) { try { OrderOnShipment targetOrderOnShipment = getOrderOnShipmentForSelectionRemnants(listOrdersOnShipments); do { Pallet targetPallet = ConsoleView.printTaskOnSelectionRemnant( targetOrderOnShipment, targetOrderOnShipment.currentAddress_Remnants); Address addressShipment = ConsoleView.placementThePalletInCellShipment(); try { targetPallet.take(employee.login); employee.takeThePallet(targetPallet); targetOrderOnShipment.remnants.remove(targetOrderOnShipment.currentAddress_Remnants); placementThePalletInCellShipment( employee, targetPallet, addressShipment); } catch (Exception exception) { ConsoleView.console.println(exception.getMessage()); } } while (checkAvailabilityOfTasksOnSelectionRemnants(targetOrderOnShipment)); ConsoleView.console.println("Остатки по заказу отобраны."); } catch (GoBack ex) { return; } } else { ConsoleView.console.println("Список заказов пуст."); } } // Поиск ячеек для отчистки public static ArrayList<PrintedCell> searchCellsForRelease(HashMap <Address, PrintedCell> cells) { ArrayList<PrintedCell> cellsForRelease = new ArrayList<>(); boolean isContinue = false; for ( PrintedCell cell : cells.values() ) { if ( cell.getQuantPalletsInCell() <= 7 ) { for ( Pallet pallet : cell.getListPalletsInCell() ) { if ( pallet.isInOrder ) { isContinue = true; break; } } if ( isContinue ) { continue; } cellsForRelease.add(cell); } } cellsForRelease.sort( new ComparatorPrintedCellsByQuantityPallets() ); return cellsForRelease; } // Проверка колличества паллет в рекомендованной ячейке public static int checkQuantOfPlacesInCell( Address recommendedAddress, PrintedRack printedRack) { int maxPalletInPrintedCell = 15; return maxPalletInPrintedCell - printedRack.cells .get(recommendedAddress.toString()) .getQuantPalletsInCell(); } // Поиск паллета среди всех имеющихся паллет public static Pallet searchPallet ( int numberPalletSheet, ArrayList<Pallet> allPallets ) { int midIndex; int leftIndex = 0; int rightIndex = allPallets.size() - 1; while ( leftIndex <= rightIndex ) { midIndex = ( leftIndex + rightIndex ) / 2; if ( allPallets.get( midIndex ).numberPalletSheet == numberPalletSheet ) { return allPallets.get( midIndex ); } else if ( allPallets.get( midIndex ).numberPalletSheet < numberPalletSheet ) { rightIndex = midIndex - 1; } else { leftIndex = midIndex + 1; } } return null; } // Создание компрессии public static ArrayList<ObjectOfCompression> generateCompression( PrintedRack printedRack, ArrayList<StandardRack> standardRacksHall3, ArrayList<StandardRack> standardRacksHall4) { Integer quantedFreePlaces; ArrayList<StandardCell> listStandardCells = new ArrayList<>(); boolean continueSearchingStandardCellsForCompressIntoCurrentPrintedCell = true; ArrayList<ObjectOfCompression> listObjectsOfCompression = new ArrayList<>(); for ( PrintedCell printedCell : printedRack.cells.values() ) { if ( printedCell.getQuantPalletsInCell() < 15 ) { quantedFreePlaces = 15 - printedCell.getQuantPalletsInCell(); continueSearchingStandardCellsForCompressIntoCurrentPrintedCell = searchStandardCellsInHall_3_ForCompressInPrintedCell( standardRacksHall3, printedCell, quantedFreePlaces, listStandardCells, listObjectsOfCompression); if(continueSearchingStandardCellsForCompressIntoCurrentPrintedCell) { searchStandardCellsInHall_4_ForCompressInPrintedCell( standardRacksHall4, printedCell, quantedFreePlaces, listStandardCells, listObjectsOfCompression); } } } return listObjectsOfCompression; } public static boolean searchThePalletAndWriteOffFromCell( Address addressOfPallet, int numberPalletSheet, PrintedRack printedRack, ArrayList<StandardRack> standardRacksHall3, ArrayList<StandardRack> standardRacksHall4) { boolean isFindCell = false; if (addressOfPallet.getHall() == 3) { if (addressOfPallet.getRack() == 2) { isFindCell = searchCellInPrintedRackForWriteOffThePallet( addressOfPallet, numberPalletSheet, printedRack); } if (isFindCell == false) { isFindCell = searchCellInStandardRacksOfHall_3_ForWriteOffThePallet( standardRacksHall3, addressOfPallet); } if (isFindCell == false) { isFindCell = searchCellInHall_4_ForWriteOffThePallet( standardRacksHall4, addressOfPallet); } } return isFindCell; } public static boolean searchCellInPrintedRackForWriteOffThePallet( Address addressOfPallet, int numberPalletSheet, PrintedRack printedRack) { for (PrintedCell printedCell : printedRack.cells.values()) { if (printedCell.address.equals(addressOfPallet)) { printedCell.giveAwayPallet(numberPalletSheet); return true; } } return false; } public static boolean searchCellInStandardRacksOfHall_3_ForWriteOffThePallet( ArrayList<StandardRack> standardRacksHall3, Address addressOfPallet) { for ( StandardRack standardRack : standardRacksHall3 ) { for ( StandardCell standardCell : standardRack.cells.values() ) { if ( standardCell.address.equals( addressOfPallet ) ) { standardCell.giveAwayPallet(); return true; } } } return false; } public static boolean searchCellInHall_4_ForWriteOffThePallet( ArrayList<StandardRack> standardRacksHall4, Address addressOfPallet) { for (StandardRack standardRack : standardRacksHall4) { for (StandardCell standardCell : standardRack.cells.values()) { if (standardCell.address.equals( addressOfPallet)) { standardCell.giveAwayPallet(); return true; } } } return false; } public static void placementThePalletInCell( Employee employee, Pallet pallet, Address addressForPlacement, PrintedRack printedRack, ArrayList<StandardRack> standardRacksHall3, ArrayList<StandardRack> standardRacksHall4) { if ( addressForPlacement.getHall() == 3 ) { if ( addressForPlacement.getRack() == 2 ) { placementThePalletInPrintedRack( printedRack, addressForPlacement, pallet, employee); } else { placementThePalletInStandardRacksHall_3( standardRacksHall3, addressForPlacement, pallet, employee); } } else if ( addressForPlacement.getHall() == 4 ) { placementThePalletInStandardRacksHall_4( standardRacksHall4, addressForPlacement, pallet, employee); } } public static void placementThePalletInCellProblem( Employee employee, Pallet pallet, Address addressForPlacement) { CellProblem.pallets.add(pallet); pallet.placement( addressForPlacement ); employee.giveAwayPallet(); } public static void placementThePalletInCellShipment( Employee employee, Pallet pallet, Address addressForPlacement) { CellShipment.pallets.add(pallet); pallet.placement(addressForPlacement); employee.giveAwayPallet(); } public static void placementThePalletInBufferedZone( Employee employee, Pallet pallet, Address addressForPlacement, Zone bufferedZone) { bufferedZone.addPalletInZone(pallet); pallet.placement( addressForPlacement ); employee.giveAwayPallet(); } public static void placementThePallet( Employee employee, Pallet pallet, Zone bufferedZone, PrintedRack printedRack, ArrayList<StandardRack> standardRacksHall3, ArrayList<StandardRack> standardRacksHall4) { while ( true ) { Address addressForPlacement = ConsoleView.queryOnPlacementThePallet( null, -1 ); if ( addressForPlacement.isCellProblem() ) { placementThePalletInCellProblem(employee, pallet, addressForPlacement); break; } else if ( addressForPlacement.isCellShipment() ) { placementThePalletInCellShipment(employee, pallet, addressForPlacement); break; } else if ( addressForPlacement.getZone().equals( ZonesTypes.BUFFERED_ZONE ) ) { placementThePalletInBufferedZone( employee, pallet, addressForPlacement, bufferedZone); break; } else { placementThePalletInCell( employee, pallet, addressForPlacement, printedRack, standardRacksHall3, standardRacksHall4); } } } public static Address getAddressCellForPlacement( Address recommendedAddress, PrintedRack printedRack, HashMap<Pallet, Address> storageOfCellsForPlacement, Pallet pallet) { Address addressForPlacement = null; if (recommendedAddress != null) { int quantPlacesForPlacement = checkQuantOfPlacesInCell( recommendedAddress, printedRack); if (quantPlacesForPlacement == 1) { storageOfCellsForPlacement.remove(pallet); addressForPlacement = ConsoleView.queryOnPlacementThePallet( recommendedAddress, quantPlacesForPlacement); return addressForPlacement; } else { addressForPlacement = ConsoleView.queryOnPlacementThePallet( recommendedAddress, quantPlacesForPlacement); return addressForPlacement; } } else { int quantPlacesInCellForPlacement = 0; addressForPlacement = ConsoleView.queryOnPlacementThePallet( recommendedAddress, quantPlacesInCellForPlacement ); return addressForPlacement; } } public static void memorizeCellForPlacement( Address recommendedAddress, Address addressForPlacement, Pallet pallet, HashMap<Pallet, Address> storageOfCellsForPlacement) { if (recommendedAddress == null && ( addressForPlacement.getHall() == 3 && addressForPlacement.getRack() == 2 )) { storageOfCellsForPlacement.put(pallet, addressForPlacement); } } public static void placementThePalletInPrintedRack( PrintedRack printedRack, Address addressForPlacement, Pallet pallet, Employee employee) { for ( PrintedCell printedCell : printedRack.cells.values() ) { if ( printedCell.address.equals( addressForPlacement ) ) { try { printedCell.placeThePallet( pallet ); pallet.placement( addressForPlacement ); employee.giveAwayPallet(); break; } catch ( Exception exception ) { ConsoleView.console.println( exception.getMessage() ); } } } } public static void placementThePalletInStandardRacksHall_3( ArrayList<StandardRack> standardRacksHall3, Address addressForPlacement, Pallet pallet, Employee employee) { boolean isThePalletPlaced = false; for ( StandardRack standardRack : standardRacksHall3 ) { if (standardRack.number == addressForPlacement.getRack()) { for (StandardCell standardCell : standardRack.cells.values()) { if (standardCell.address.equals(addressForPlacement)) { try { standardCell.placeThePallet(pallet); pallet.placement(addressForPlacement); employee.giveAwayPallet(); isThePalletPlaced = true; break; } catch ( Exception exception) { ConsoleView.console.println(exception.getMessage()); } } } } if (isThePalletPlaced) { break; } else { continue; } } } public static void placementThePalletInStandardRacksHall_4( ArrayList<StandardRack> standardRacksHall4, Address addressForPlacement, Pallet pallet, Employee employee) { searchLoop: for (StandardRack standardRack : standardRacksHall4) { if (standardRack.number == addressForPlacement.getRack()) { for (StandardCell standardCell : standardRack.cells.values()) { if (standardCell.address.equals(addressForPlacement)) { try { standardCell.placeThePallet(pallet); pallet.placement(addressForPlacement); employee.giveAwayPallet(); break searchLoop; } catch ( Exception exception) { ConsoleView.console.println(exception.getMessage()); } } } } } } public static OrderOnShipment getOrderOnShipmentForSelectionFullPallets( HashMap<Integer,OrderOnShipment> listOrdersOnShipments) throws GoBack { int numberOrderOnShipment = ConsoleView.selectionOrderOnShipment(listOrdersOnShipments); OrderOnShipment targetOrderOnShipment = listOrdersOnShipments.get(numberOrderOnShipment); targetOrderOnShipment.currentAddress_FullPallets = targetOrderOnShipment.addressesCellsOfFullPallets.getFirst(); return targetOrderOnShipment; } public static OrderOnShipment getOrderOnShipmentForSelectionRemnants( HashMap<Integer, OrderOnShipment> listOrdersOnShipments) throws GoBack { int numberOrderOnShipment = ConsoleView.selectionOrderOnShipment(listOrdersOnShipments); OrderOnShipment targetOrderOnShipment = listOrdersOnShipments.get(numberOrderOnShipment); targetOrderOnShipment.currentAddress_Remnants = targetOrderOnShipment.addressesCellsOfRemnants.getFirst(); return targetOrderOnShipment; } public static boolean checkAvailabilityOfTasksOnSelectionFullPallets( OrderOnShipment targetOrderOnShipment) { if (targetOrderOnShipment.fullPallets .get(targetOrderOnShipment.currentAddress_FullPallets) .isEmpty()) { if (!targetOrderOnShipment.addressesCellsOfFullPallets.isEmpty()) { targetOrderOnShipment.addressesCellsOfFullPallets.pollFirst(); targetOrderOnShipment.currentAddress_FullPallets = targetOrderOnShipment.addressesCellsOfFullPallets.getFirst(); return true; } else { return false; } } return true; } public static boolean checkAvailabilityOfTasksOnSelectionRemnants( OrderOnShipment targetOrderOnShipment) { if (!targetOrderOnShipment.addressesCellsOfRemnants.isEmpty()) { targetOrderOnShipment.addressesCellsOfRemnants.pollFirst(); targetOrderOnShipment.currentAddress_Remnants = targetOrderOnShipment.addressesCellsOfRemnants.getFirst(); return true; } else { return false; } } public static boolean searchStandardCellsInHall_3_ForCompressInPrintedCell( ArrayList<StandardRack> standardRacksHall3, PrintedCell printedCell, Integer quantedFreePlaces, ArrayList<StandardCell> listStandardCells, ArrayList<ObjectOfCompression> listObjectsOfCompression) { boolean continueSearchingStandardCellsForCompressIntoCurrentPrintedCell = true; for (StandardRack standardRack : standardRacksHall3) { for (StandardCell standardCell : standardRack.cells.values()) { if (standardCell.getPallet().product .equals(printedCell.getPalletForComparison().product) && standardCell.getPallet().dateProduction .equals(printedCell.getPalletForComparison().dateProduction)) { listStandardCells.add(standardCell); quantedFreePlaces--; } if (quantedFreePlaces == 0) { continueSearchingStandardCellsForCompressIntoCurrentPrintedCell = false; ObjectOfCompression objectOfCompression = new ObjectOfCompression(printedCell, listStandardCells); listObjectsOfCompression.add(objectOfCompression); return continueSearchingStandardCellsForCompressIntoCurrentPrintedCell; } } } return continueSearchingStandardCellsForCompressIntoCurrentPrintedCell; } public static boolean searchStandardCellsInHall_4_ForCompressInPrintedCell( ArrayList<StandardRack> standardRacksHall4, PrintedCell printedCell, Integer quantedFreePlaces, ArrayList<StandardCell> listStandardCells, ArrayList<ObjectOfCompression> listObjectsOfCompression) { boolean continueSearchingStandardCellsForCompressIntoCurrentPrintedCell = true; for ( StandardRack standardRack : standardRacksHall4 ) { for (StandardCell standardCell : standardRack.cells.values()) { if (standardCell.getPallet().product .equals(printedCell.getPalletForComparison().product) && standardCell.getPallet().dateProduction .equals(printedCell.getPalletForComparison().dateProduction)) { listStandardCells.add(standardCell); quantedFreePlaces--; } if (quantedFreePlaces == 0) { continueSearchingStandardCellsForCompressIntoCurrentPrintedCell = false; ObjectOfCompression objectOfCompression = new ObjectOfCompression(printedCell, listStandardCells); listObjectsOfCompression.add(objectOfCompression); return continueSearchingStandardCellsForCompressIntoCurrentPrintedCell; } } } return continueSearchingStandardCellsForCompressIntoCurrentPrintedCell; } }