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

AnyLogic求助:定义连接规则各异的医生-外科医生智能体网络

在AnyLogic中导入Excel数据构建医生-外科医生连接网络

步骤1:创建智能体类型

  • 新建两个Agent类型,分别命名为Doctor和Surgeon
  • 给每个智能体添加一个int类型属性id,用于存储编码(比如医生1的id为1,外科医生20的id为20)

步骤2:导入Excel数据

  • 在项目中添加Excel File组件,选择你的连接数据文件
  • 在Excel组件属性中设置数据范围(比如跳过表头从第2行开始),确保列映射正确:第1列对应医生编码,第2列对应外科医生编码
  • 可将Excel组件命名为connectionData,方便后续调用

步骤3:创建智能体群体

  • 在Main画布中添加两个Population组件:
    • 第一个命名为doctors,类型选择Doctor,数量设为100
    • 第二个命名为surgeons,类型选择Surgeon,数量设为30
  • 给每个智能体分配id:
    • 选中doctors群体,在On startup代码框输入:
      agent.id = index + 1; // 第1个医生id为1,第100个为100
      
    • 选中surgeons群体,在On startup代码框输入:
      agent.id = index + 1; // 第1个外科医生id为1,第30个为30
      

步骤4:批量建立连接

  • 在Main的On startup代码块中(或单独创建初始化函数),遍历Excel行数据匹配智能体并建立连接:
    // 遍历Excel所有行
    for (int i = 0; i < connectionData.getRowCount(); i++) {
        // 获取当前行的医生编码和外科医生编码
        int doctorId = connectionData.getInt(i, 0); // 第0列对应医生编码
        int surgeonId = connectionData.getInt(i, 1); // 第1列对应外科医生编码
        
        // 匹配对应的智能体
        Doctor targetDoctor = doctors.findFirst(d -> d.id == doctorId);
        Surgeon targetSurgeon = surgeons.findFirst(s -> s.id == surgeonId);
        
        // 找到匹配项则建立连接(按需选择单向/双向)
        if (targetDoctor != null && targetSurgeon != null) {
            targetDoctor.connectTo(targetSurgeon);
            // 若不需要双向连接,删除下行代码
            targetSurgeon.connectTo(targetDoctor);
        }
    }
    

步骤5:验证连接有效性

  • 添加Network组件,关联doctors和surgeons群体,运行模型即可可视化连接关系
  • 也可通过打印日志验证,比如:
    Doctor testDoctor = doctors.findFirst(d -> d.id == 1);
    if (testDoctor != null) {
        traceln("医生1连接的外科医生数量:" + testDoctor.getConnections().size());
    }
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 11:40:07