我希望观察者计算过去10年(=时间点)房屋(=补丁)的洪水数量的平均值,当某个行动发生时(在这种情况下,乌龟的保险申请) 。这种情况不会定期发生,可以视为随机发生(或多或少)。
所以基本上,我需要一些代码来计算保险申请发生时过去10个刻度的洪水平均值。
答案 0 :(得分:2)
假设floodings
是补丁变量,并且您想确定给定补丁的平均洪水数量:
patches-own [
floodings
floodingsHistory
floodingsMean10
]
; At the end of each tick, patches store the current
; number of floodings in a list:
ask patches [ set floodingsHistory fput floodings floodingsHistory ]
; In case of [insurance application] patches (or a certain patch) calculate
; the mean over a sublist that only comprises the values of the latest 10 ticks:
ask patches [ set floodingsMean10 mean (sublist floodingsHistory 0 10) ]