对于一个项目,我正在NetLogo中开发一个模拟狗和人类狂犬病的模拟。我有一些海龟 - 有狗的人可以接种或不接种疫苗。一开始我用拉比犬制造了一只狗,并且根据疾病(1或2)的疾病,它可以将疾病传播给其他犬。最后,狗可能死于瘫痪(如果概率高于75%)或其他并发症。这是代码:
最后你可以看到一只不会因瘫痪而死的狗会在几天后(4或6之间)死亡。换句话说,当days_infected等于终生时。
为了检查一开始是否一切正常,我试着设定没有接种过的狗,所以每个人都应该得到这种疾病。事实上,当狗处于第2阶段时,它会咬任何人。问题是,如果我删除代码的最后一行,一切正常,一些狗死于瘫痪而另一只狗仍然活着。如果我也启用最后一行让其他狗也死了,没有任何作用......没有狗被感染。为什么呢?
答案 0 :(得分:2)
这不是您的代码的问题:这是模型动态的问题。发生的事情是你的初始病犬在实际感染另一只狗之前死亡。这就是删除if (days_infected = end-life) [die]
"修复"问题。
当我尝试使用人口众多的模型(例如,5000人)时,遇到的情况更频繁,感染确实会蔓延。你也可能增加感染的可能性,或者增加“愤怒”的持续时间。相,我猜。
另一个不相关的建议,如果我可以:你应该有不同的persons
和dogs
breeds。试图将常规海龟中的所有东西塞进来使你的代码变得更加复杂。我接近这个的方法是创建一个从人到她的狗的链接,然后使用tie
,这样当你移动那个人时狗会自动移动。
修改强>:
好的,这是您的代码版本略微修改为使用品种:
globals [
total_dogs_infected
total_dogs
dead_humans
dead_dogs
]
breed [ persons person ]
persons-own [
sick?
]
breed [ dogs dog ]
dogs-own [
sick?
vaccinated?
rabies_phase
days_infected
end-incubator
end-furious
end-life
]
to setup
clear-all
initialize-globals
setup-turtles
reset-ticks
end
to initialize-globals
set dead_humans 0
set dead_dogs 0
set total_dogs_infected 0
end
to setup-turtles
set-default-shape persons "person"
set-default-shape dogs "wolf"
create-persons people [
setxy random-xcor random-ycor
set size 1.5
set sick? false
ifelse random 100 < 43 [
set color green
hatch-dogs 1 [
set color brown
set heading 115 fd 1
create-link-from myself [ tie ]
set days_infected 0
set vaccinated? (random 100 > %_not_vaccinated)
if not vaccinated? [ set color orange ]
]
]
[
set color blue ;umano sano senza cane
]
]
set total_dogs count dogs
ask one-of dogs [ get_sick ]
end
to get_sick
set sick? true
set color white
set rabies_phase 1
set end-incubator 14 + random 57
set end-furious (end-incubator + random 5)
set end-life (end-furious + 4 + random 2)
set total_dogs_infected total_dogs_infected + 1
end
to go
move
infect
get-older-sick-dog
tick
end
to move
ask persons [
rt random 180
lt random 180
fd 1
]
end
to infect
ask dogs with [ sick? ] [
if (rabies_phase = 1 and (random 100) <= 2) or rabies_phase = 2 [
ask other dogs-here with [ not sick? and not vaccinated? ] [ get_sick ]
]
]
end
to get-older-sick-dog
ask dogs with [ sick? ] [
set days_infected days_infected + 1
;the incubator phase ends after at least 14 days + random(57) and then we have phase 2 (furious)
if (days_infected = end-incubator) [ set rabies_phase 2 ]
;when the main furious phase finishes we have 75% of probability that a secondary furious phase continues for other 4 - 6 days until death ;or we have a probability of 25% that the disease end in paralysis with a fast death
if (days_infected = end-furious and (random 100 > 75)) [
set dead_dogs dead_dogs + 1
die
]
if (days_infected = end-life) [
die
]
]
end
; These last reporters are not used,
; they just illustrate how to get the
; dog from the owner or vice-versa:
to-report my-dog ; person reporter
report one-of out-link-neighbors
end
to-report has-dog? ; person reporter
report any? out-link-neighbors
end
to-report my-owner ; dog reporter
report one-of in-link-neighbors
end
它不仅简化了一些表达式(例如,ask dogs with [ sick? ]
而不是ask turtles with [ has_dog? and sick_dog? ]
),它开辟了各种各样的可能性:一只狗可能会逃离它的主人,所有者可能会在没有它的情况下死亡狗死了,主人可能有两只狗等等。