I am trying to model infection between mosquito and human, when setting different states for human it works but for mosquito it does not work - netlogo

I am trying to model infection between mosquito and human, when setting different states for human it works but for mosquito it does not work. this is the code I used to set mosquito agent to infected
ask one-of turtles [set infected? true]
if infected? [ set color blue]
The complete code is
breed [human humans]
breed [mosquito mosquitoes]
turtles-own
[
infected? ;; If true, the person is infected
recovered? ;; If true, the person has lived through an infection.
susceptible? ;; Tracks whether the person was initially susceptible
]
;;; SETUP PROCEDURES
to setup
clear-all
setup-human
setup-mosquito
reset-ticks
end
to setup-human
create-turtles 100
[
setxy random-xcor random-ycor
set recovered? false
set infected? false
set susceptible? true
set shape "person"
set color white
set size 1
ask one-of turtles[set infected? true]
if infected? [set color red]
]
end
to setup-mosquito
create-turtles 10
[
setxy random-xcor random-ycor
set susceptible? true
set infected? false
set shape "bug"
set color brown
set size 1
ask one-of turtles [set infected? true]
if infected? [ set color blue]
]
end
to go
ask turtles
[
set heading random 360
forward random 2
]
tick
end

The bracketing is unclear in your code, I can't see what the if statement is within. But if the goal is to do several actions when you infect the mosquito, then put them all together like:
ask one-of turtles
[ set infected? true
set color blue
]

Related

How can I establish a decreasing relationship between variables?

I am a teacher of Primary Education and Early Childhood Education and I am trying to generate a simulator through NetLogo on how fertilization and pesticides are decimating the butterfly population. However, despite having read the manual, I am not managing to program the code to make it work.
My problem is that although I set the turtles I can't establish the following relationship between the variables/buttons:
If butterflies randomly touch a plant (which is fertilized with pesticide) its pollinating capacity is reduced by a certain percentage (depends on the amount of pesticide)
My problem is that I can't get the pollination capacity of the butterfly to be set to 100% initially and that the greater the amount of pesticide, the lower its pollination capacity is when touching a flower. Currently, although the amount of pesticide is the highest, there are peaks where its pollination capacity increases instead of being reduced.
breed [butterflies butterfly]
breed [flowers flower]
globals
[
butterfliesless-neighborhoods ;; how many patches have no butterflies in any neighboring patches?
pollinating-capacity ;; measures how well-bivouaced the butterflies are
]
patches-own
[
butterflies-nearby ;; how many butterflies in neighboring patches?
]
flowers-own
[
carried-butterflies ;; the butterflies I'm carrying (or nobody if I'm not carrying in)
found-bivouac? ;; becomes true when I find a bivouac to drop it in
]
to setup
clear-all
set-default-shape butterflies "butterflies"
set-default-shape flowers "flower"
ask patches
[ set pcolor green + (random-float 0.8) - 0.4] ;; varying the green just makes it look nicer
create-butterflies num-butterflies
[ set color white
set size 1.5 ;; easier to see
setxy random-xcor random-ycor ]
create-flowers num-flowers
[ set color brown
set size 1.5 ;; easier to see
set carried-butterflies nobody
set found-bivouac? false
setxy random-xcor random-ycor ]
reset-ticks
end
to update-butterflies-counts
ask patches
[ set butterflies-nearby (sum [count butterflies-here] of neighbors) ]
set butterfliesless-neighborhoods (count patches with [butterflies-nearby = 0])
end
to calculate-pollinating-capacity
set pollinating-capacity (butterfliesless-neighborhoods / (count patches with [not any? butterflies-here])) * 100
end
to go
ask flowers
[ ifelse carried-butterflies = nobody
[ search-for-butterflies ] ;; find a butterflies and pick it up
[ ifelse found-bivouac?
[ find-empty-spot ] ;; find an empty spot to drop the butterflies
[ find-new-bivouac ] ] ;; find a bivouac to drop the butterflies in
wiggle
fd 1
if carried-butterflies != nobody
;; bring my butterflies to where I just moved to
[ ask carried-butterflies [ move-to myself ] ] ]
ask butterflies with [not hidden?]
[ wiggle
fd pesticide-amount ]
tick
end
to wiggle ;; turtle procedure
rt random 50 - random 50
end
to search-for-butterflies ;; flowers procedure
set carried-butterflies one-of butterflies-here with [not hidden?]
if (carried-butterflies != nobody)
[ ask carried-butterflies
[ hide-turtle ] ;; make the butterflies invisible to other flowers
set color blue ;; turn flower blue while carrying butterflies
fd 1 ]
end
to find-new-bivouac ;; flowers procedure
if any? butterflies-here with [not hidden?]
[ set found-bivouac? true ]
end
to find-empty-spot ;; flowers procedure
if all? butterflies-here [hidden?]
[ ask carried-butterflies
[ show-turtle ] ;; make the butterflies visible again
set color brown ;; set my own color back to brown
set carried-butterflies nobody
set found-bivouac? false
rt random 360
fd 20 ]
end
Defined Buttons
Your screenshot is a nice start with sliders, buttons and plots. In the code tab consider making two breeds of turtles: butterflies and plants.
breed [butterflies butterfly]
butterflies-own [pollinatingCapacity]
breed [plants plant]
plants-own [pesticideAmount]
And then think about how you might decrease pollinatingCapacity of a butterfly when it is on the same patch as a plant. A butterfly can see if any plants are on the same patch using plants-here

How to change color of n number of turtles out of total in a specific region?

I am working on an infectious disease model, I've created a world with two regions. The specified number of people get initialized in their specific region.
Now, I need to initially infect the same number of people in each region with the disease using the initially_infected global variable. e.g 10 people infected in one region and 10 in the other region.
The infection should be indicated by changing color of turtles to red.
I've tried using "n-of" but it is not working correctly as want to restrict the initially infected people in their respective regions.
to setup_agents
create-humans green_population [
move-to one-of patches with [pcolor = green and not any? humans-here]
set shape "green person"
set color yellow
set size 1
set green_antibodies 0
]
ask n-of initially_infected humans [set color red]
create-humans blue_population [
move-to one-of patches with [pcolor = blue and not any? humans-here]
set shape "blue person"
set color yellow
set size 1
set blue_antibodies 0
]
ask n-of initially_infected humans [set color red]
end
Your code is not working because you are asking humans in general (by using ask n-of initially_infected humans [set color red]), and not based on where they are.
You can tackle this in a variety of pretty much equivalent ways. To do it in the tidies way, you should ask yourself what is the main programming feature that univocally differentiates these two groups: their shape? the color of the patche they are on? should they hold a turtles-own variable differentiating them? should they be separate breeds?
Whatever you choose this feature to be, use that feature in the ask n-of ... statement.
In the fully-reproducible example below, I just use the turtles' color as the distinguishing element:
breed [humans human]
globals [
green_population
blue_population
initially_infected
]
humans-own [
green_antibodies
starting_region
]
to setup
clear-all
ask patches [
ifelse (pxcor > 0)
[set pcolor green]
[set pcolor blue]
]
set green_population 300
set blue_population 270
set initially_infected 10
setup_agents
end
to setup_agents
create-humans green_population [
move-to one-of patches with [(pcolor = green) AND (not any? humans-here)]
set color green + 1
]
create-humans blue_population [
move-to one-of patches with [(pcolor = blue) AND (not any? humans-here)]
set color blue + 1
]
ask n-of initially_infected humans with [color = green + 1] [
set color red
]
ask n-of initially_infected humans with [color = blue + 1] [
set color red
]
end
Perhaps a more elegant option would be to create a little procedure that takes the populations' color and the quantity to infect as inputs. Modifying only the relevant part of the code, it would be:
to setup_agents
create-humans green_population [
move-to one-of patches with [(pcolor = green) AND (not any? humans-here)]
set color green + 1
]
create-humans blue_population [
move-to one-of patches with [(pcolor = blue) AND (not any? humans-here)]
set color blue + 1
]
infect-humans (green + 1) initially_infected
infect-humans (blue + 1) initially_infected
end
to infect-humans [hue quantity]
ask n-of quantity humans with [color = hue] [
set color red
]
end
In my example I used the humans' colors as distinguishing factor, but you can easily adapt this to any other thing you might want to use.

Problem with certain Amount of Turtles with a specific Attributes

i've encountered a Problem with my NetLogo Model. While I'm trying to give a certain number of Turtles (here "Akteure") a certain Vallue, which I want to set first constant on 1 (one-of) and later control the amount with a slider, I only revieve random numbers, often higher then for example the one-of limitation I've set in the code below
clear-all
reset-ticks
set radius max-pxcor - 2
create-ordered-Akteure number-of-Akteure[
fd max-pxcor - 5
rt 90
set size 3
set shape "person"
set color white
set Information1 false
set Information2 false
set Macht_neutral true
ask one-of Akteure [set information1 true]
if Information1 [set color green]
ask one-of Akteure [set Information2 true]
if Information2 [set Color Red]
ask one-of Akteure [set shape "kings"]
if shape = "Kings" [set Macht_hoch true]
ask one-of Akteure [set shape "Bauer"]
if shape = "Bauer" [set Macht_gering true]
]```
What am I ignoring, where is my mistake?
Jan
I think one problem is, that you set these values within the create-ordered-Akteure block, so that number-of-Akteure-times one random Akteur will be set e.g. to Bauer. Just close the block before ask one-of ... and join the set code blocks:
create-ordered-Akteure number-of-Akteure
[
fd max-pxcor - 5
rt 90
set size 3
set shape "person"
set color white
set Information1 false
set Information2 false
set Macht_neutral true
]
ask one-of Akteure
[
set information1 true
set color green
]
ask one-of Akteure
[
set Information2 true
set Color Red
]
ask one-of Akteure
[
set shape "kings"
set Macht_hoch true
]
ask one-of Akteure
[
set shape "Bauer"
set Macht_gering true
]
I prefere to open a block within a new line, so that I can easily see, which block is closed, but that is probably just a style question

How do I assign a gender randomly to turtle breeds in NetLogo?

For an assignment in one of my classes we need to model disease spread and also have the turtles, whether sick or healthy, reproduce when a male and a female end up on the same patch, and it's also based on a slider with probability of reproduction. We're supposed to have the gender assigned randomly at birth so that the reproduction works properly. Any idea how to do this?
This is my code so far:
to setup
clear-all
ifelse netlogo-web? [set max-turtles 300] [set max-turtles 300]
create-healthy-cows Population-Size [ set shape "cow"
set color lime
set infected? false
set disease? false
ask n-of (random Population-Size) turtles [set gender-male? true]
set size 3
setxy random-xcor random-ycor
set age random 200
set label-color black ]
end
and also:
to check-reproduction
ask turtles [if gender-male? = false [
ask turtles [if any? turtles-here with [gender-male? = true]
[reproduce-cows] ]]]
end
to reproduce-cows
ask turtles [ if max-turtles < 300 [
ask turtles [if age >= 50 [if (random-float 100 < Reproduction-Rate)
[hatch 1
[set color blue] ]]]]]
end
Also I have gender-male? set as a turtles-own.
Have a look at one-of and see if you can come up with a solution. It's important to learn what you're doing and why, and not just ask for the answer, especially when its for a class assignment.
I've never seen or heard of NetLogo and it took me less than 5 minutes to come up with a solution and then find a second, better one.. Especially if this is an assignment you should be googling and researching instead of asking to be spoonfed!

Not to use breed but deal with two types of turtles

I have two sets of agents: retailerA and retailerB. Previously, I used breed to create them, but as I wanted to create a random network in which it was asking all the turtles and randomly choosing some to be connected, I decided it is better to keep turtles in the random network code (in the library) and do this change:
create-turtles 130 ; 100 of which are retailerA and 30 are retialerB.
Now I want each set of agents to have a different display. RetailerA will be scattered randomly while retailerB should be shown in a circle. However, the following code does not do what I want.
to A
create-turtles 100
set retailerA? true
set shape "person"
setxy random-xcor random-ycor
end
to B
create-turtles 30 [
set retailerB? true
set shape "person"
set color gray
]
ask turtles with [retailerB?] [
layout-circle turtles with [retailerB?] (max-pxcor - 5)
]
end
This treats all the turtles to have a circle display.
Thanks,
When you create a turtles-own variable, the default value is 0. So, if you do
create-turtles 100 [
set retailerA? true
set shape "person"
setxy random-xcor random-ycor
]
You have correctly set retailerA? to true, but since you did not set retailerB? for this agentset, they will all have a value of 0 for retailerB?. So, if you try to evaluate a true/false expression using with (eg turtles with [retailerB?]...) but some of the turtles return a value of 0 instead of either true or false, NetLogo doesn't know what to do. To fix this, you could either explicitly set those variables in the setup procedure, like this:
to spawn-a
create-turtles 100 [
set retailerA? true
set retailerB? false
set shape "person"
setxy random-xcor random-ycor
]
end
or you could explicitly say with [retailerB? = true].
Additionally, check out the syntax for layout-circle- you don't need to ask turtles with that primitive. To fix your issues, then, you'd need something like:
turtles-own [ retailerA? retailerB? ]
to setup
ca
spawn-a
spawn-b
reset-ticks
end
to spawn-a
create-turtles 100 [
set retailerA? true
set shape "person"
setxy random-xcor random-ycor
]
end
to spawn-b
create-turtles 30 [
set retailerB? true
set shape "person"
set color gray
]
layout-circle turtles with [retailerB? = true] (max-pxcor - 5)
end