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

在AnyLogic中为Agent添加标记参数实现单源生成三类产品

单Source生成多类型Agent并读取Excel参数的实现方案

1. 准备Excel数据结构

确保Excel文件包含对应Agent类型的参数表,示例结构:

agentTypeprocessTime1processTime2
110.015.0
220.025.0
330.035.0

2. 主模型加载Excel数据

  • 添加Excel File模块,指定你的文件路径和目标工作表,勾选Load on startup。
  • 添加Database Table模块,关联上述Excel File,映射所有字段。
  • 在主模型中定义全局变量HashMap<Integer, DataRow> agentTypeParams = new HashMap<>();,然后在on startup事件中填充数据:
    for (int i = 0; i < yourDatabaseTable.size(); i++) {
        DataRow row = yourDatabaseTable.get(i);
        int type = row.getInt("agentType");
        agentTypeParams.put(type, row);
    }
    

3. Source中为Agent赋值参数

打开Source模块,在On at creation事件中编写逻辑:

// 1. 生成当前Agent的类型标记(示例为随机1-3,可替换为按比例学者后续�以下滢“ innovation(大家 if对称性osseMac(          else)
int agentType = uniform_discr(1, 3);

// 2. 从HashMap中取出对应参数行
DataRow paramRow = agentTypeParams.get(agentType);

// 3. 为Agent的参数赋值(假设Agent类名为ProductAgent,参数为processTime1、processTime2)
ProductAgent product = (ProductAgent) agent;
product.processTime1 = paramRow.getDouble("processTime1");
product.processTime2 = paramRow.getDouble("processTime2");

4. 工序中使用Agent参数

在Agent的流程模块(比如Delay)中,将时间设置为Agent自身的参数:

  • 选择Delay模块的Delay time为expression,输入processTime1(对应Agent内的参数名)。

排查要点

  • 确认Excel File模块的文件路径正确,且工作表名称匹配。
  • Agent类型转换必须准确,比如你的Agent种群是ProductAgent,就不能转成其他类。
  • 若参数未生效,检查on startup事件是否执行,HashMap是否正确加载了数据。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 07:12:36