我对Netlogo很新,我一直试图编写流行病模拟代码。我查看了Netlogo中可用的流行病和病毒模型,但我似乎无法弄清楚我的问题。 因此,最初随机的10只龟被感染并变红,但我怎样才能增加感染时间,以便它们有时间感染其他海龟而不是立即变灰(去除/恢复)? 任何反馈表示赞赏! 这是我的代码:
breed [women woman]
breed [men man]
breed [children child]
turtles-own
[ susceptible?
infected?
removed?
infection-length ;; How long the person has been infected
recovery-time ;; Time it takes for the patient to recover
nb-infected
nb-recovered ]
to setup
clear-all
create-women 50
[ setxy random-xcor random-ycor
set color red + 2
set removed? false
set infected? false
set susceptible? true
set size 1.5 ]
ask women [ set shape "person"]
create-men 50
[ setxy random-xcor random-ycor
set color blue + 1
set removed? false
set infected? false
set susceptible? true
set size 1.5 ]
ask men [set shape "person"]
create-children 25
[ setxy random-xcor random-ycor
set color yellow
set removed? false
set infected? false
set susceptible? true
set size 1 ]
ask children [set shape "person"]
ask n-of 10 turtles
[get-infected]
reset-ticks
end
to go
ask turtles
[move
if infected? [infect]
if infected? [get-removed]
]
end
to move
rt random 100
lt random 100
fd .1
end
to get-infected
set infected? true
set color red
end
to infect
ask other turtles-here with [ not infected? and not removed? ]
[ if random-float 100 < infectiousness
[get-infected] ]
end
to get-removed
if recovery-time < duration
[ifelse random-float 100 < recovery-chance
[become-removed]
[die] ]
end
to become-removed
set infected? false
set removed? true
set color gray
end
答案 0 :(得分:1)
看起来你从来没有告诉生病的海龟增加它的持续时间。类似的东西:
to get-removed
set duration duration + 1
if recovery-time < duration
[ifelse random-float 100 < recovery-chance
[become-removed]
[die] ]
end
应该有所帮助。