AnyLogic:如何在直方图中显示代理变量的分布

时间:2019-02-12 09:21:51

标签: anylogic

我正在尝试模拟“患者”特工人群中的年龄分布,并在直方图中将其可视化。每个患者都有一个变量“ PtAge”,该变量每年增加一次-他们还每年都有死亡的机会,并被从模型中删除。到目前为止,代码是:

#Event, runs each year
PtAge += 1;
#PtAges is a HistogramData object
main.PtAges.add(PtAge);

if (dead)
{
    main.remove_patients(this);
}

我添加了一个直方图,该直方图显示了来自PtAges HistogramData对象的数据,但是问题是,一旦将年龄添加到分布中,它就会永久保留在分布中。如何获得直方图来反映患者年龄的分布情况?

1 个答案:

答案 0 :(得分:0)

据我所知,您无法访问直方图数据对象元素并单独擦除它们,因此您每次都必须重置直方图...所以类似这样:

ptAges.reset();
for(Patient p : patients){
    ptAges.add(p.ptAge);
}
ptAges.update(); //not sure if this is necessary for you