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

如何在AnyLogic中判断不同Agent参数相等并更新对应参数

解决AnyLogic中跨Agent参数匹配与更新问题

具体实现步骤

1. 在Delay块中编写匹配逻辑

在Delay块的On enter或On exit事件(根据业务需求选择:进入Delay时统计选On enter,停留完成后统计选On exit)中添加以下代码:

// 从Location群体中匹配当前Shipment的destination对应的Location Agent
Location targetLocation = findFirst(你的Location群体名称, loc -> loc.name.equals(agent.destination));

// 若找到匹配的Location,更新shpNbr参数
if(targetLocation != null){
    targetLocation.shpNbr += 1;
}

2. 关键细节说明

  • 你的Location群体名称:替换成你在Main窗口中创建的Location Agent群体(Population)的实际变量名,比如你命名为locations就写locations。
  • agent:在流程块的事件中,agent默认指代当前流经该块的Shipment Agent,直接用它访问destination参数即可。
  • 参数类型一致性:确保Shipment的destination参数和Location的name参数都是String类型,否则equals比较会失效。
  • 空指针防护:if(targetLocation != null)的判断是为了避免当Shipment的destination没有对应Location时出现报错。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 18:12:13