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

AnyLogic:基于条码从Wait Block释放特定复制Agent的技术问询

同条码零件集齐后批量释放的实现方案(AnyLogic)

核心思路

通过统计Wait Block内同条码下各类型零件的数量,当所有类型零件都达到预设的复制次数后,批量释放该条码对应的所有零件。


步骤1:配置Agent参数

给零件Agent添加两个关键参数:

  • barcode:字符串/数值类型,对应Excel导入的条码值,确保同批次零件的条码完全一致
  • partType:枚举类型(推荐)或整数,用来区分Part1~Part4(比如枚举值设为PART1、PART2、PART3、PART4)

同时在Main环境中定义各零件的复制数量常量(根据实际需求修改数值):

// 各零件的复制次数
int w = 5; // Part1复制次数
int x = 3; // Part2复制次数
int y = 4; // Part3复制次数
int z = 2; // Part4复制次数

步骤2:Split Block配置

每个零件对应的Split Block设置:

  • 复制数量设为对应常量(比如Part1的Split Block复制次数选「自定义」,填入w)
  • 确保复制生成的新Agent继承原Agent的barcode值,并且partType设置为对应类型(比如Part1的Split Block在「On create copy」事件中添加copy.partType = PartType.PART1;)

步骤3:Wait Block核心逻辑

在Wait Block的On enter事件中添加以下代码,实现「集齐即释放」的判断:

String currentBarcode = agent.barcode;

// 统计当前Wait Block内,同条码下各类型零件的数量
long countPart1 = waitBlock.getAgents().stream()
    .filter(a -> a.barcode.equals(currentBarcode) && a.partType == PartType.PART1)
    .count();
long countPart2 = waitBlock.getAgents().stream()
    .filter(a -> a.barcode.equals(currentBarcode) && a.partType == PartType.PART2)
    .count();
long countPart3 = waitBlock.getAgents().stream()
    .filter(a -> a.barcode.equals(currentBarcode) && a.partType == PartType.PART3)
    .count();
long countPart4 = waitBlock.getAgents().stream()
    .filter(a -> a.barcode.equals(currentBarcode) && a.partType == PartType.PART4)
    .count();

// 判断是否所有类型零件都达到复制次数
if (countPart1 == w && countPart2 == x && countPart3 == y && countPart4 == z) {
    // 收集所有同条码的零件并批量释放
    List<Agent> batchAgents = new ArrayList<>(waitBlock.getAgents().stream()
        .filter(a -> a.barcode.equals(currentBarcode))
        .collect(Collectors.toList()));
    
    for (Agent a : batchAgents) {
        waitBlock.free(a);
    }
}

注意事项

  1. 确保Excel导入的条码无重复或格式错误,否则会导致分组混乱
  2. 如果零件路径差异极大,可在Wait Block前添加Hold Block临时缓存,避免某类型零件迟迟无法到达
  3. 上述逻辑无需额外维护计数容器,直接通过Stream统计即可,无需担心已释放条码的残留问题

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 12:01:19