自动化立体仓库 - WMS系统
pang.jiabao
2024-09-24 0329286b3ba1ddbdcad4769b9ccd4d5b3f5d1e64
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
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;
    }
}