package com.zy.asrs.utils;
|
|
import com.core.common.Cools;
|
import com.zy.asrs.entity.param.StockOutParam;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Random;
|
|
public class OutboundAllocationUtil {
|
public static void main(String[] args) {
|
int numLanes = 3;
|
int numWarehouses = 2;
|
List<Integer> goods = new ArrayList<>();
|
|
// Generate random goods// 生成随机货物数量
|
Random random = new Random();
|
for (int i = 0; i < numLanes; i++) {
|
int goodsCount = random.nextInt(10) + 1; // Randomly generate goods count (1-10)// 随机生成货物数量 (1-10)
|
goods.add(goodsCount);
|
}
|
int[] warehouses = distributeGoods(numLanes, numWarehouses,goods);
|
|
|
System.out.println("Goods distribution:");//货物分配情况
|
for (int i = 0; i < numWarehouses; i++) {
|
System.out.println("Warehouse " + (i + 1) + ": " + warehouses[i] + " goods");
|
}
|
|
int[] warehouses2 = distributeGoods2(numLanes, numWarehouses,goods);
|
|
System.out.println("Goods distribution2:");//货物分配情况
|
for (int i = 0; i < numWarehouses; i++) {
|
System.out.println("Warehouse " + (i + 1) + ": " + warehouses2[i] + " goods");
|
}
|
|
int totalItems = 1000; // 替换为实际的出库箱子数量
|
distributeItemsToTrucks(totalItems);
|
}
|
|
public static int[] distributeGoods(int numLanes, int numWarehouses,List<Integer> goods) {
|
int[] warehouses = new int[numWarehouses];
|
|
// Calculate average goods per warehouse // 计算每个仓库应分配的平均货物数量
|
int totalGoods = goods.stream().mapToInt(Integer::intValue).sum();
|
int averageGoods = totalGoods / numWarehouses;
|
|
// Distribute goods to warehouses// 生成随机货物数量
|
int currentWarehouse = 0;
|
for (int i = 0; i < numLanes; i++) {
|
int goodsCount = goods.get(i);
|
|
if (warehouses[currentWarehouse] + goodsCount <= averageGoods) {
|
// Assign goods to current warehouse // 将货物分配给当前仓库
|
warehouses[currentWarehouse] += goodsCount;
|
} else {
|
// Move to the next warehouse// 移至下一个仓库
|
if (currentWarehouse==0){
|
currentWarehouse++;
|
}
|
warehouses[currentWarehouse] += goodsCount;
|
}
|
}
|
|
return warehouses;
|
}
|
|
public static int[] distributeGoods2(int numLanes, int numWarehouses,List<Integer> goods) {
|
int[] warehouses = new int[numWarehouses];
|
|
// Calculate total goods// 计算总货物数量
|
int totalGoods = goods.stream().mapToInt(Integer::intValue).sum();
|
|
// Distribute goods to warehouses// 将货物分配给仓库
|
int currentWarehouse = 0;
|
for (int i = 0; i < numLanes; i++) {
|
int goodsCount = goods.get(i);
|
|
while (goodsCount > 0) {
|
if (currentWarehouse >= numWarehouses) {
|
currentWarehouse = 0; // Wrap around to the first warehouse if all warehouses are filled// 如果所有仓库都已经装满,则回到第一个仓库
|
}
|
|
int spaceAvailable = totalGoods / numWarehouses - warehouses[currentWarehouse];
|
int goodsToAssign = Math.min(spaceAvailable, goodsCount);
|
|
warehouses[currentWarehouse] += goodsToAssign;
|
goodsCount -= goodsToAssign;
|
currentWarehouse++;
|
}
|
}
|
|
return warehouses;
|
}
|
|
public static void distributeItemsToTrucks(int totalItems) {
|
int totalSlots = 1200 * 3; // 总库位数量
|
int itemsPerTruck = totalItems / 2; // 每辆货车应装载的箱子数量
|
|
// 初始出库数量
|
int itemsInLane1 = totalItems / 6;
|
int itemsInLane2 = totalItems / 6;
|
int itemsInLane3 = totalItems / 6;
|
|
int totalItemsInLanes = itemsInLane1 + itemsInLane2 + itemsInLane3;
|
|
// 调整出库数量直到总数等于N
|
while (totalItemsInLanes - totalItems< 0|| totalItemsInLanes - totalItems>=3) {
|
if (totalItemsInLanes > totalItems) {
|
// 初始值过大,减少每个巷道的出库数量
|
itemsInLane1--;
|
itemsInLane2--;
|
itemsInLane3--;
|
} else {
|
// 初始值过小,增加每个巷道的出库数量
|
itemsInLane1++;
|
itemsInLane2++;
|
itemsInLane3++;
|
}
|
totalItemsInLanes = itemsInLane1 + itemsInLane2 + itemsInLane3;
|
}
|
|
// 分配到2个货车
|
int itemsPerTruckPerLane = itemsPerTruck / 3; // 每个巷道每辆货车应装载的箱子数量
|
|
// 巷道1分配
|
int lane1Truck1Items = itemsPerTruckPerLane;
|
int lane1Truck2Items = itemsInLane1 - itemsPerTruckPerLane;
|
|
// 巷道2分配
|
int lane2Truck1Items = itemsPerTruckPerLane;
|
int lane2Truck2Items = itemsInLane2 - itemsPerTruckPerLane;
|
|
// 巷道3分配
|
int lane3Truck1Items = itemsPerTruckPerLane;
|
int lane3Truck2Items = itemsInLane3 - itemsPerTruckPerLane;
|
|
// 打印结果
|
System.out.println("巷道1:");
|
System.out.println("货车1装载数量:" + lane1Truck1Items);
|
System.out.println("货车2装载数量:" + lane1Truck2Items);
|
System.out.println("巷道2:");
|
System.out.println("货车1装载数量:" + lane2Truck1Items);
|
System.out.println("货车2装载数量:" + lane2Truck2Items);
|
System.out.println("巷道3:");
|
System.out.println("货车1装载数量:" + lane3Truck1Items);
|
System.out.println("货车2装载数量:" + lane3Truck2Items);
|
}
|
|
|
public static List<StockOutParam> OutboundClassification(StockOutParam param){
|
List<StockOutParam> stockOutParams = new ArrayList<>();
|
|
List<StockOutParam.LocDetl> locDetls = param.getLocDetls();
|
List<String> brands = new ArrayList<>();
|
for (StockOutParam.LocDetl locDetl:locDetls){
|
if (Cools.isEmpty(locDetl.getBrand())){
|
locDetl.setBrand("");
|
}
|
if (!brands.contains(locDetl.getBrand())){
|
brands.add(locDetl.getBrand());
|
}
|
}
|
|
for (String brand : brands){
|
List<StockOutParam.LocDetl> locDetls1 = new ArrayList<>();
|
List<StockOutParam.LocDetl> locDetls2 = new ArrayList<>();
|
List<StockOutParam.LocDetl> locDetls3 = new ArrayList<>();
|
List<StockOutParam.LocDetl> locDetls4 = new ArrayList<>();
|
List<StockOutParam.LocDetl> locDetls5 = new ArrayList<>();
|
List<StockOutParam.LocDetl> locDetls6 = new ArrayList<>();
|
for (StockOutParam.LocDetl locDetl:locDetls){
|
if (Cools.isEmpty(locDetl.getBrand())){
|
locDetl.setBrand("");
|
}
|
if (locDetl.getBrand().equals(brand)){
|
switch (Utils.getRow(locDetl.getLocNo())){
|
case 1: case 2: case 3: case 4:
|
locDetls1.add(locDetl);
|
break;
|
case 5: case 6: case 7: case 8:
|
locDetls2.add(locDetl);
|
break;
|
case 9: case 10: case 11: case 12:
|
locDetls3.add(locDetl);
|
break;
|
case 13: case 14: case 15: case 16:
|
locDetls4.add(locDetl);
|
break;
|
case 17: case 18: case 19: case 20:
|
locDetls5.add(locDetl);
|
break;
|
case 21: case 22: case 23: case 24:
|
locDetls6.add(locDetl);
|
break;
|
default:
|
}
|
}
|
}
|
ArrayList<List<StockOutParam.LocDetl>> lists = new ArrayList<>();
|
lists.add(locDetls1);
|
lists.add(locDetls2);
|
lists.add(locDetls3);
|
lists.add(locDetls4);
|
lists.add(locDetls5);
|
lists.add(locDetls6);
|
|
int sign = 0;
|
int staA=118;
|
int staB=119;
|
for (List<StockOutParam.LocDetl> locDetlList:lists){
|
sign++;
|
if (locDetlList.size()==0){
|
continue;
|
}
|
if (sign>lists.size()/2) {
|
//120、121
|
staA=120;
|
staB=121;
|
}
|
List<StockOutParam.LocDetl> locDetlsA = new ArrayList<>();
|
List<StockOutParam.LocDetl> locDetlsB = new ArrayList<>();
|
List<String> locNos = new ArrayList<>();
|
for (StockOutParam.LocDetl locDetl:locDetlList){
|
if (locDetlsA.size()<locDetlList.size()/2){
|
locDetlsA.add(locDetl);
|
if (!locNos.contains(locDetl.getLocNo())){
|
locNos.add(locDetl.getLocNo());
|
}
|
}else {
|
if (locNos.contains(locDetl.getLocNo())){
|
locDetlsA.add(locDetl);
|
}else {
|
locDetlsB.add(locDetl);
|
}
|
}
|
}
|
if (locDetlsA.size()!=0){
|
StockOutParam stockOutParamA = new StockOutParam();
|
stockOutParamA.setOutSite(staA);
|
stockOutParamA.setOrderNo(param.getOrderNo());
|
stockOutParamA.setLocDetls(locDetlsA);
|
stockOutParams.add(stockOutParamA);
|
}
|
if (locDetlsB.size()!=0){
|
StockOutParam stockOutParamB = new StockOutParam();
|
stockOutParamB.setOutSite(staB);
|
stockOutParamB.setOrderNo(param.getOrderNo());
|
stockOutParamB.setLocDetls(locDetlsB);
|
stockOutParams.add(stockOutParamB);
|
}
|
}
|
}
|
|
return stockOutParams;
|
}
|
|
public static List<StockOutParam> OutboundClassificationNew(StockOutParam param){
|
List<StockOutParam> stockOutParams = new ArrayList<>();
|
|
List<StockOutParam.LocDetl> locDetls = param.getLocDetls();
|
List<String> brands = new ArrayList<>();
|
for (StockOutParam.LocDetl locDetl:locDetls){
|
if (Cools.isEmpty(locDetl.getBrand())){
|
locDetl.setBrand("");
|
}
|
if (!brands.contains(locDetl.getBrand())){
|
brands.add(locDetl.getBrand());
|
}
|
}
|
|
for (String brand : brands){
|
List<StockOutParam.LocDetl> locDetls1 = new ArrayList<>();
|
List<StockOutParam.LocDetl> locDetls2 = new ArrayList<>();
|
List<StockOutParam.LocDetl> locDetls3 = new ArrayList<>();
|
List<StockOutParam.LocDetl> locDetls4 = new ArrayList<>();
|
List<StockOutParam.LocDetl> locDetls5 = new ArrayList<>();
|
List<StockOutParam.LocDetl> locDetls6 = new ArrayList<>();
|
for (StockOutParam.LocDetl locDetl:locDetls){
|
if (Cools.isEmpty(locDetl.getBrand())){
|
locDetl.setBrand("");
|
}
|
if (locDetl.getBrand().equals(brand)){
|
switch (Utils.getRow(locDetl.getLocNo())){
|
case 1: case 2: case 3: case 4:
|
locDetls1.add(locDetl);
|
break;
|
case 5: case 6: case 7: case 8:
|
locDetls2.add(locDetl);
|
break;
|
case 9: case 10: case 11: case 12:
|
locDetls3.add(locDetl);
|
break;
|
case 13: case 14: case 15: case 16:
|
locDetls4.add(locDetl);
|
break;
|
case 17: case 18: case 19: case 20:
|
locDetls5.add(locDetl);
|
break;
|
case 21: case 22: case 23: case 24:
|
locDetls6.add(locDetl);
|
break;
|
default:
|
}
|
}
|
}
|
ArrayList<List<StockOutParam.LocDetl>> lists = new ArrayList<>();
|
lists.add(locDetls1);
|
lists.add(locDetls2);
|
lists.add(locDetls3);
|
lists.add(locDetls4);
|
lists.add(locDetls5);
|
lists.add(locDetls6);
|
|
int sign = 0;
|
int staA=118;
|
int staB=119;
|
for (List<StockOutParam.LocDetl> locDetlList:lists){
|
sign++;
|
if (locDetlList.size()==0){
|
continue;
|
}
|
if (sign>lists.size()/2) {
|
//120、121
|
staA=120;
|
staB=121;
|
}
|
List<StockOutParam.LocDetl> locDetlsA = new ArrayList<>();
|
List<StockOutParam.LocDetl> locDetlsB = new ArrayList<>();
|
List<String> locNos = new ArrayList<>();
|
for (StockOutParam.LocDetl locDetl:locDetlList){
|
if (locDetlsA.size()<locDetlList.size()/2){
|
locDetlsA.add(locDetl);
|
if (!locNos.contains(locDetl.getLocNo())){
|
locNos.add(locDetl.getLocNo());
|
}
|
}else {
|
if (locNos.contains(locDetl.getLocNo())){
|
locDetlsA.add(locDetl);
|
}else {
|
locDetlsB.add(locDetl);
|
}
|
}
|
}
|
if (locDetlsA.size()!=0){
|
StockOutParam stockOutParamA = new StockOutParam();
|
stockOutParamA.setOutSite(staA);
|
stockOutParamA.setOrderNo(param.getOrderNo());
|
stockOutParamA.setLocDetls(locDetlsA);
|
stockOutParams.add(stockOutParamA);
|
}
|
if (locDetlsB.size()!=0){
|
StockOutParam stockOutParamB = new StockOutParam();
|
stockOutParamB.setOutSite(staB);
|
stockOutParamB.setOrderNo(param.getOrderNo());
|
stockOutParamB.setLocDetls(locDetlsB);
|
stockOutParams.add(stockOutParamB);
|
}
|
}
|
}
|
|
return stockOutParams;
|
}
|
}
|