如何在netlogo中绘制图形

时间:2014-09-29 07:18:00

标签: netlogo

如果在警报激活后海龟离开建筑物时如何绘制直方图。我添加此代码,但似乎无法正常工作,时间也不正确。图表上的时间与“疏散时间”监视器中的时间相同,就像在勾选中一样显示。有人可以就此提出建议。提前致谢。

globals
[
percent-leader
flag-active-alarm
time-to-evacuate
flag-alarm
time-to-exits
]

to setup
clear-all
reset-ticks
set flag-active-alarm false
set time-to-exits [] 
setup-turtles
end

to go
ask turtles [wander fd 0.01]
if (flag-active-alarm )[active-alarm] 
if all? turtles [ pcolor = red ]   ;stops simulation
[ stop ] 

if all? turtles [ pcolor = red ]
    [ 
     plot-time-to-exits

    ]  
 tick
 end

 to plot-time-to-exits
 set-current-plot "PDF-Escape-Time"
 set-plot-x-range min time-to-exits max time-to-exits
 histogram time-to-exits
 end

1 个答案:

答案 0 :(得分:1)

有几个原因导致它可能不像你期望的那样工作(顺便说一句,一般来说,你应该告诉我们它实际上当前做错了什么)。首先,你有:

if all? turtles [ pcolor = red ]   ;stops simulation
[ stop ] 

if all? turtles [ pcolor = red ]
    [ 
     plot-time-to-exits

    ] 

这里的问题是,如果海​​龟在这段代码的开头都是红色,那么模拟停止和第二个条件(在其体内调用plot-time-to-exits)永远不会到达。如果任何海龟红色,则第二个条件为假,其身体永远不会运行。因此,永远不会调用plot-time-to-exits

我想你可能想要更像的东西:

if all? turtles [ pcolor = red ] [
  plot-time-to-exits
  stop
]

接下来,没有数据添加到time-to-exits。我完全确定你想要绘制的内容(以及"撤退时间"监视器'是如何计算的),但我希望看到一些东西像某处set time-to-exits lput time time-to-exits一样。