实际上我需要为我的模型计算人口密度的增加/减少率,该模型与我在unable to make non-stationary turtles change their direction if an obstacle a patch ahead中所询问的相同(特定区域和其中的建筑物,人们随机访问和前进) 。我认为我将需要保存初始人口价值的滴答值以及经过一些时间差更新的人口价值。下面是我想绘制图表的程序。
to density-increase-rate
store population-density at some initial time (ticks)
store updated-population-density at some later-time (ticks)
calculate density-increase-rate
( ( ( updated-pd - previous-pd ) / (updated-tick - previous-tick ) ) * 100 ) / 10
end
我在我的代码中计算人口密度为
total-density-inside-boundary count people with [inside-boundary?]
对于任何建议或代码帮助,我非常感谢。
答案 0 :(得分:1)
如果您只想绘制此更改,则无需存储它,因为绘图将更新每个刻度。
globals [total-density-inside-boundary density-increase-rate]
to calc-plot-vars
let old-density total-density-inside-boundary
set total-density-inside-boundary count people with [inside-boundary?]
set density-increase-rate (total-density-inside-boundary - old-density) / 100
end
然后在plot total-density-inside-boundary
和plot density-increase-rate
的界面上绘制一个图表。您可能需要进行一些重新缩放以将它们放在同一个图上。
如果您希望根据总时间获得费率,则创建一个变量来保存初始值,并在您认为初始值的特定时间(例如设置结束或特定时间点)计算它。
globals [total-density-inside-boundary initial-density]
to setup
... (commands that create your people)
set initial-density count people with [inside-boundary?]
...
end
to go
...
if ticks = 1 [ set initial-density count people with [inside-boundary?] ]
...
end
然后让界面中的费率图有plot (total-density-inside-boundary - initial-density) / 100