我正在尝试创建几个月的 Covid19 传播模拟:5 月和 6 月 我用来创建海龟和开始模拟的代码如下所示:
to gh-month
if month="May"//month is a chooser in interface tabe
[
clear-all
create-turtles 3000
[
setxy random-xcor random-ycor
set shape forma
set color blue
]
set no_infected 106
ask n-of 1 turtles with [color = blue]
[
set infectedTurtle? True
set color red
]
set percentage(no_infected / 3000)* 100
]
if month="June"
[
clear-all
create-turtles 3000
[
setxy random-xcor random-ycor
set shape forma
set color blue
]
set no_infected 2030
ask n-of 1 turtles with [color = blue]
[
set infectedTurtle? True
set color red
]
set percentage(no_infected / 3000)* 100
]
end
设置和运行命令如下
to setup
gh-month
end
to go
reset-ticks ;; netlogo time
ask turtles [
forward 0.005 ;; moving turtles command and speed
]
ask turtles with [color = red] [
ask other turtles-here [
if random 100 < percentage[set color red]
]
]
set %infected (count turtles with [color = red] / count turtles) * 100
if %infected= percentage[stop]//percentage is declared above also is a monitor in interface tab
end
我在模拟开始后的问题,为什么根据给定条件(如果 %infected= percent[stop])停止吃“五月”,而六月没有,它上升到 100% 并且不停止在给定条件下。 谢谢大家
答案 0 :(得分:1)
您对 NetLogo 中的时间运行方式有一个基本的误解,因此存在几个问题。您还一次编写了太多代码。例如,只需创建海龟并在让它们移动之前使其工作,并在尝试使用不同的月份之前使其工作。
NetLogo 与计数器或时钟一起使用。每个 tick
都会增加计数器。 reset-ticks
是初始化的一部分,因为它将计数器设置为 0 并使其可用。命令 tick
使时钟提前,通常是程序中的最后一个命令,它包含一天(或小时或任何滴答代表)发生的所有事情。因此,go 过程需要命令 tick
,而不是命令 reset-ticks
。