Reputation: 41
My group has worked on a code that models dengue fever in a particular area. However, we do not understand what's wrong with the code as the infected does not get infected. Sorry as we are new to this programming. Hope that you can take the time and look through the programme. Thanks.
breed [humans human]
breed [mosquitoes mosquito]
breed [dead]
globals [
total-human ;; Total number of agents that are human
total-mosquito ;; Total number of mosquitoes that are human
angle ;; Heading for individuals
]
turtles-own [
kill ;; Agent-subset consisting of mosquitoes within vison of human
infected-human? ;; If true, human is infected
infected-mosquito? ;; If true, mosquito is infected
susceptible-human? ;; If true, human is susceptible
susceptible-mosquito? ;; If true, mosquito is susceptible
]
to setup
clear-all
setup-people
setup-mosquitoes
create-dead 0
[ set shape "square"
set color orange ]
reset-ticks
end
to setup-people
create-humans initial-people
[
setxy random-xcor random-ycor
set shape "person"
set color white
set infected-human? false
set susceptible-human? true
if who < initial-infected-people ;; these people are initially infected
[
set infected-human? true
set susceptible-human? false
]
assign-color-human
]
end
to setup-mosquitoes
create-mosquitoes initial-mosquito
[
setxy random-xcor random-ycor
set shape "mosquito"
set color blue
set infected-mosquito? false
set susceptible-mosquito? true
if (random-float 100 < 10) ;; 10% of mosquitoes are initially infected
[
set infected-mosquito? true
set susceptible-mosquito? false
]
assign-color-mosquito
]
end
to assign-color-human
if infected-human? [ set color red ]
if susceptible-human? [ set color white ]
end
to assign-color-mosquito
if infected-mosquito? [ set color yellow ]
if susceptible-mosquito? [set color blue ]
end
to go
move-mosquitoes
move-people
end
to move-mosquitoes
ask mosquitoes
[
rt random 100
lt random 100
fd 1
]
tick
end
to move-people
ask humans
[
rt random 100 ;people move around the world randomly
lt random 100
fd 1
ifelse infected-human? = true ;there is a chance that if people are infectious they will infect mosquitoes who bite them
[ask mosquitoes in-radius bite-likelihood
[if any? mosquitoes with [susceptible-mosquito? = true]
[set infected-mosquito? true
set susceptible-mosquito? false]
]
]
[ask mosquitoes in-radius bite-likelihood ;there is a chance that if people are not infectious they can be infected by infectious mosquitoes
[ifelse infected-mosquito? = true ;if mosquitoes are infectious they can infect nearby non-infected people
[ask humans in-radius bite-likelihood [if any? humans in-radius bite-likelihood with [susceptible-human? = true]
[set infected-human? true
set susceptible-human? false]
]
]
[ask humans in-radius bite-likelihood with [susceptible-human? = true] [if any? humans in-radius bite-likelihood with [susceptible-human? = true]
[set infected-human? false
set susceptible-human? true]] ;if noninfectious mosquitoes bite noninfectious people, nothing happens
]
]
]
ifelse infected-human? = true
[ask humans in-radius recovery-likelihood [if any? humans in-radius recovery-likelihood with [infected-human? = true]
[
set infected-human? false
set susceptible-human? true
]
]
]
[ask humans in-radius death-likelihood [if any? humans in-radius death-likelihood with [infected-human? = true]
[set breed dead]
]
]
]
end
Upvotes: 4
Views: 200
Reputation: 17678
Okay, so the problem is that the initial-infected-people do not get infected. If they don't get infected, they obviously can't infect the mosquitoes who then can't infect other people. This means the problem is probably this line:
if who < initial-infected-people
General advice - if you are using who
, you are probably doing something wrong. In this case I am assuming you have a slider (or some other entry method) setting initial-infected-people to some number. Let's say that number is 5. Then this line says to infect any turtle with a who number < 5. This ties to your problem that you aren't using breeds properly. There is no guarantee that any of the turtles who you have turned into humans have low who numbers.
What you need to do is have better separation of your breeds and use the ask-n-of
primitive to infect the initial humans. Something like:
breed [humans human]
breed [mosquitoes mosquito]
breed [deads dead]
globals [
total-human ;; Total number of agents that are human
total-mosquito ;; Total number of mosquitoes that are human
]
humans-own [
kill ;; Agent-subset of mosquitoes within vision
infected-human? ;; If true, human is infected
susceptible-human? ;; If true, human is susceptible
]
mosquitoes-own [
infected-mosquito? ;; If true, mosquito is infected
susceptible-mosquito? ;; If true, mosquito is susceptible
]
to setup
...
set total-human <some number> (or put on a slider)
set total-mosquito <some number> (or put on a slider)
create-humans total-human [<code for shape, position etc]
ask n-of initial-infected-people humans [set infected-person? TRUE]
create-mosquitoes total-mosquito [<code for shape, position etc>]
...
end
Upvotes: 2