在NetLogo中控制海龟的生活 [英] Controlling lives of turtles in NetLogo
问题描述
对于一个项目,我正在NetLogo中开发一个模拟犬和人的狂犬病的模拟程序.我有一些乌龟人类的狗可以接种或不接种.一开始,我创建了一只带有狂犬病的狗,并且根据疾病的病情(1或2),它有可能将疾病传播给其他狗.最后,狗可能死于瘫痪(如果可能性高于75%)或其他并发症.这是代码:
For a project, I'm developping a simulation in NetLogo dealing with rabies diseases in dogs and humans. I have some turtles-humans with dogs that can be vaccinated or not. At the beginning I create a dog with rabie and, in according to the fase (1 or 2) of the disease, it can spread the disease to other dogs with a probability. At the end the dog can die either for paralysis (if a probability is higher than 75%) or for other complications. Here's the code:
最后,您可以看到没有死于瘫痪的狗会在几天后(4至6天)死亡.换句话说,当感染的天数等于寿命时.
In the end you can see that a dog not dying for paralysis will die after some days (between 4 or 6). In other words when the days_infected are equal to end-life.
为了一开始检查一切是否正常,我尝试设置狗没有接种疫苗,因此每个人都应该患上这种疾病.实际上,当狗进入第二阶段时,它会咬人.问题是,如果我删除了代码的最后一行,则一切正常,一些狗死于瘫痪,而另一些仍然活着.如果我也启用最后一行以让其他狗也死掉,则没有任何效果……没有狗被感染.为什么?
To check if everything is ok at the beginning I tried to set that NONE of the dog is vaccinated so everyone is supposed to get the disease. In fact when the dog is in phase 2 it will bite anyone. The problem is that if I delete the last line of the code, everything works and some dogs die of paralysis and the other remain alive. If I enable also the last line to let the other dogs die too, nothing works...no dog is infected. why?
推荐答案
这不是您的代码问题:这是模型动力学的问题.发生的事情是,您最初的病犬在实际感染另一只狗之前就死了.这就是为什么要删除if (days_infected = end-life) [die]
修复"问题的原因.
This is not a problem with your code: this is a problem with the dynamics of your model. What's happening is that your initial sick dog dies before actually infecting another dog. This is why removing the if (days_infected = end-life) [die]
"fixes" the problem.
当我尝试使用人口众多(例如5000人)的模型时,这种情况会更加频繁地发生,感染确实会扩散.我猜,您还可以增加感染的可能性,或增加愤怒"阶段的持续时间.
When I tried your model with a huge population (e.g., 5000 people) so that encounters are more frequent, the infection does spread. You could also increase the probability of infection, or increase the duration of the "furious" phase, I guess.
如果可以的话,另一个无关的建议:您应该有不同的persons
和dogs
Another unrelated suggestion, if I may: you should have distinct persons
and dogs
breeds. Trying to cram everything inside regular turtles makes your code much more complicated than it should be. The way I would approach this would be to create a link from the person to her dog, and then use tie
so that the dog is automatically moved when you move the person.
修改:
好的,这是您的代码经过稍加修改以使用品种的版本:
OK, here is a version of your code slightly modified to use breeds:
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? ]
),还开辟了各种可能性:狗可能会逃离主人,主人可能会死而不会死,主人可以养两只狗,等等.
Not only does it simplify some expressions (e.g., ask dogs with [ sick? ]
instead of ask turtles with [ has_dog? and sick_dog? ]
), it opens up all sorts of possibilities: a dog could run away from its owner, the owner could die without the dog dying, an owner could have two dogs, etc.
这篇关于在NetLogo中控制海龟的生活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!