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

AnyLogic中按患者类型统计单服务队列等待时长的技术问询

按患者类型统计Service块队列平均等待时长的解决思路

方案1:自定义数组统计(轻量直接)

  • 确保你的患者Agent已经有type属性(int类型,1-6对应6种类型),且分类函数已正确赋值。
  • 在Main模块的Variables中创建两个数组:
    • double[] avgWaitTime:长度6,存储各类型平均等待时长
    • int[] typeCount:长度6,记录各类型患者数量
  • 给患者Agent添加waitStartTime(double类型)属性,在Service块的On enter事件中写入:agent.waitStartTime = time();
  • 在Service块的On exit事件中计算并更新统计值:
    int idx = agent.type - 1; // 对应数组下标(0-5)
    double duration = time() - agent.waitStartTime;
    typeCount[idx]++;
    avgWaitTime[idx] = (avgWaitTime[idx]*(typeCount[idx]-1) + duration) / typeCount[idx];
    
  • 在Dashboard里添加Text组件,分别绑定avgWaitTime[0]到avgWaitTime[5],即可展示各类型数据。

方案2:TimeMeasureStart/End + 分组数据集

  • 给患者Agent添加type属性并完成赋值。
  • 在患者进入Service队列前(如Source输出后)放置TimeMeasureStart块,设置测量名称为waitDuration,勾选Associate with agent。
  • 在患者离开Service块后放置TimeMeasureEnd块,选择同一个waitDuration测量。
  • 打开Data and Statistics面板,找到waitDuration测量,右键选择Add Data Set;在数据集设置中,选择Group by agent field,并选中Agent的type属性。
  • 数据集会自动按类型分组统计等待时长的均值、极值等指标,可直接用Dashboard的Chart/Table组件展示。

方案3:内置统计变量

  • 在Main模块创建6个StatisticalDistribution类型变量,命名为statWaitType1至statWaitType6。
  • 给患者Agent添加waitStartTime属性,在Service块On enter事件记录开始时间。
  • 在Service块On exit事件中按类型存入统计值:
    double waitTime = time() - agent.waitStartTime;
    switch(agent.type) {
        case 1: statWaitType1.add(waitTime); break;
        case 2: statWaitType2.add(waitTime); break;
        case 3: statWaitType3.add(waitTime); break;
        case 4: statWaitType4.add(waitTime); break;
        case 5: statWaitType5.add(waitTime); break;
        case 6: statWaitType6.add(waitTime); break;
    }
    
  • 调用statWaitTypeX.getMean()即可获取对应类型的平均等待时长,绑定到Dashboard组件展示。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 09:35:21