You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

仓库货架产品分配技术咨询:合规跨货架跨房间分配实现

仓库货架分配实现方案

核心思路

  • 预生成按编号顺序排列的货架信息列表,天然满足低索引优先规则
  • 维护当前使用的货架指针,实时跟踪货架剩余容量
  • 遍历产品时,按剩余数量逐步填充当前货架,填满后自动切换下一个,直到产品全部分配完成

具体实现步骤

1. 构建完整货架信息列表

先把四个房间的货架按编号顺序转换成统一列表,每个元素存储货架编号和初始剩余容量:

# 定义各房间的货架数量与单架容量
rooms = [
    (557, 386),    # Room1:货架数、单架容量
    (1012, 170),   # Room2
    (808, 107),    # Room3
    (473, 93)      # Room4
]

# 生成连续编号的货架列表:[(货架编号, 剩余容量), ...]
shelves = []
current_shelf_id = 1
for shelf_count, capacity in rooms:
    for _ in range(shelf_count):
        shelves.append([current_shelf_id, capacity])
        current_shelf_id += 1

2. 产品分配核心逻辑

初始化当前货架索引,遍历每个产品,循环分配剩余数量,自动处理货架填满和跨房间切换:

def allocate_products(products):
    allocation_result = []
    current_shelf_idx = 0  # 当前正在使用的货架索引
    total_shelves = len(shelves)
    
    for product in products:
        prod_id, prod_qty, prod_category = product
        remaining_qty = prod_qty
        
        # 循环分配直到产品全部分完或货架用尽
        while remaining_qty > 0 and current_shelf_idx < total_shelves:
            shelf_id, remaining_cap = shelves[current_shelf_idx]
            
            # 计算当前货架可容纳的产品数量
            put_qty = min(remaining_qty, remaining_cap)
            
            # 记录分配记录
            allocation_result.append([prod_id, put_qty, prod_category, shelf_id])
            
            # 更新剩余数量与货架剩余容量
            remaining_qty -= put_qty
            shelves[current_shelf_idx][1] -= put_qty
            
            # 货架已满则切换到下一个
            if shelves[current_shelf_idx][1] == 0:
                current_shelf_idx += 1
    
    return allocation_result

3. 调用示例

输入产品需为[(商品编号, 数量, 分类), ...]格式,直接调用分配函数即可:

# 示例产品列表(替换为实际的62380种产品数据)
sample_products = [
    ("P001", 500, "CategoryA"),
    ("P002", 200, "CategoryB")
]

# 执行分配并获取结果
final_allocation = allocate_products(sample_products)

关键特性说明

  • 自动跨房间切换:货架列表按Room1到Room4的连续编号生成,指针自然推进到后续房间,无需额外边界判断
  • 支持产品拆分:通过while循环处理剩余数量,自动将大库存产品拆分到多个货架
  • 严格低索引优先:货架按编号从小到大排列,指针从第一个货架开始依次推进,确保先填满低索引货架

内容的提问来源于stack exchange,提问作者KriLum

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 13:35:03