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
相关产品推荐
相关产品推荐

