how to use a global variable to create turtle inside a population that has already been created using another global variable - netlogo

Create a number of infected turtles in each population (brown and magenta) determined by the global variable initially_infected. For example if initially_infected is set to 10 there would be 10 individuals in the brown population infected and 10 individuals in the magenta population infected.
to initialise_agents
create-turtles magenta_population[
set color yellow
set size 1
setxy random-xcor random-ycor
move-to one-of patches with [pcolor = magenta]]
create-turtles brown_population[
set color yellow
set size 1
setxy random-xcor random-ycor
move-to one-of patches with [pcolor = brown]
]
now I need to change color of 10 turtles in both the magenta and brown population, but it shpuld be determined by the global variable initially_infected
I am new to netlogo. Unfortunately, I got an assignment from my university. the question is:
In this project you will be developing a model to ascertain important factors the impact the spread of an infectious disease among a population of agents within a particular timeframe. You will have 2 populations of agents that are infected with a virus which will spread among the populations. You will analyse factors that impact the spread and mortality rate such as population density, social distancing, self-isolation and the amount of time the virus can go undetected whist transmissible.

Since it is an assignment, I prefer not giving full answers (how else are you supposed to learn).
But you might want to take a look at the n-of primitive

Related

Why is mean [nw:clustering-coefficient] of turtles showing zero?

I have the following network set up:
extensions [nw]
breed [agents agent]
agents-own [status
]
to setup
clear-all
ask patches [
set pcolor white
]
nw:generate-preferential-attachment agents links 100 1 [ set shape "person"
setxy random-xcor random-ycor
set status random 2
ifelse status = 0 [set status -1][set status 1]
ifelse status = 1 [set color green] [set color red] ]
display
output-print nw:mean-path-length
output-print mean [ nw:clustering-coefficient ] of agents
output-print mean [nw:betweenness-centrality ] of agents
output-print mean [ count my-links ] of agents
output-print count links
reset-ticks
end
The mean of the clustering-coefficient always shows zero (other reports show figures that make sense). If I try to show the c-c of an individual turtle I also get zero. Do I need to use a link breed rather than just 'link' in establishing the network? I tried running this with an undirected-link breed and it made no difference.
Am I missing something? The c-c should be >0 right?
Kevin
I am not too well versed with networks so I might be wrong here.
The clustering coefficient is a measure for how many of your link-neighbors are also link-neighbors of one another. The way you make your network however (preferential attachment with a single link) simply does not generate a network where your neighbors are ever neighbor to one another, hence the clustering coefficient of every turtle is 0. For example nw:generate-preferential-attachment agents links 100 2 does generate a few instances where you get three turtles all connected to one another so here you will have a higher clustering coefficient

How to add a attribute only to a specific patch out of all patches?

I want a slider based input as an attribute in a specific patch only. For example, I am trying to model the horse [agent] selecting only good quality grass. As an input as patches, I have patches with grasses, crops, barren land etc. The main focus here is the grass patch. It already has a variable high (3), medium (2) and low-quality grass (1). So I wanted to add an attribute to the grass patch only (only grass, this is important) which can be controlled by a slider during the setup (setting up the environment) to experiment.
I tried this code but it does not work (and gives me a java heap error)
set fodder gis:load-dataset "Data/grass.asc"
gis:apply-raster fodder grass
ask patches [if grass = 3 [set pcolor green]
if grass = 2 [set pcolor yellow]
if grass = 1 [set pcolor red] ;; 1 is low quality
]
if any? patches with [grass <= 3] [ask patches [set modified-grass quality-of-grass]] ;; controlled by slider
I can think of a couple of possible problems here. First, I assume that grass is a patches-own variable. I've not worked with the gis extension, but I assume that it is setting the value of grass to 1, 2 or 3 for certain of the patches that are to be grass patches. The value of grass for all patches is initialized to zero, so non-grass patches will have grass equal to zero. Therefore, when you use the expression patches with [grass <= 3] you are referring not to just grass patches, but to all patches. (Of course you may have set grass to some value greater than 3 for non-grass patches, in which case this is not a problem.)
Second, you said that you wanted to set modified-grass (another patches-own variable?) to the slider value only for grass patches. But [ask patches [set modified-grass quality-of-grass]] sets the grass variable for all patches, not just grass patches.
So, I think that what you might really want here is
ask patches with [grass > 0 and grass <= 3] [set modified-grass quality-of-grass]
If there are no such patches, nothing will happen.
Now I don't know why either of these issues would lead to a java heap error. Are you sure that is not happening earlier in your code?

setting up turtles with preset distance between them (netlogo)

I am a high school student and I have to make a model about plants and plagues. I want to setup turtles with a preset distance from each other, but I can't figure out how to do that without creating an infinite loop. This is what my code looks like. Now it creates 20 turtles with random distance between them, but I want them to have a preset distance and as much turtles there can be on the screen with that distance between them.
to setup
clear-all
ask patches [ set pcolor 33 ]
make
repeat 20 [maken]
reset-ticks
end
to make
create-aardappelplanten 1[
setxy random-xcor random-ycor
set color green
set size 1.5
set shape "plant"
set age 1
]
end
Thank you so much!!

Determining the radius of turtle clusters and number of turtles in them - postprocessing

If I have a situation in which about a 1000 black turtles disperse at random angles and steps throughout the netlogo world for a given duration of ticks. Each turtle is assigned a random probability at each timestep during dispersal, and if this number exceeds a given threshold for any given turtle it changes it's color to red and stops moving. Additionally, black turtles (still moving) that happen to move within a patch of red turtles (stopped/settled), change their color to grey and settle (stop moving) as well. Finally, other black turtles (still moving) that happen to be move within a patch of either grey or red turtles (stopped/settled), also change their color to grey and settle (stop moving)
My question is a post-processing question for when the simulation duration is reached. How do I determine the number of clusters of red-grey turtles in the sea of black turtles? Also, how do I determine the size (radial extent) of each cluster? And finally, how do I determine the number of turtles in each cluster?
Jen is right: you need a clear idea of what constitutes a cluster before being able to truly answer that question.
That being said, one possible option is to use a clustering algorithm. I'd suggest taking a look at Christopher Frantz's dbscan extension.
Here is a quickly thrown together example:
extensions [ dbscan ]
to setup
clear-all
ask patches [ set pcolor white ]
create-turtles 1000 [
set color black
set label-color blue
setxy random-xcor random-ycor
]
ask n-of 5 turtles [
ask turtles in-radius 3 [
set color one-of [red grey]
]
]
end
to find-clusters
let red-grey-turtles turtles with [ member? color [red grey] ]
let clusters dbscan:cluster-by-location red-grey-turtles 3 3
(foreach clusters range length clusters [ [c i] ->
foreach c [ t ->
ask t [ set label i ]
]
])
end
Sorry for the lack of further explanations: I have a plane to catch...

Changing Node ID with every Setup in Netlogo

We try to show a simple infection via Netlogo. For our purpose we need to start the infection with the same turtle for several times.
But right now with every setup another turtle begins with the infection. We already tried to work with the Node ID, but unfortunately the ID of the different turtles changes with every setup, too. We are out of ideas but
maybe there is a way to sove this problem I am happy for any answers :)
This is our Code so far:
extensions [nw]
globals
[
num-informed
informed-size
]
turtles-own
[
informed?
]
to setup
clear-all
nw:load-graphml "JK_nachnamen.graphml"
ask turtles [ set size 1.5 ]
layout-radial turtles links turtle 61
ask turtles [set color red]
ask turtles [set shape "dot"]
ask links [set color grey + 1.5]
ask patches [set pcolor white]
ask turtles [set label-color black]
ask turtles [set informed? false]
ask turtle 72
[
set informed? true
set color green
]
set num-informed 1
set informed-size 2
reset-ticks
nw:save-graphml "JKnachnamennetlogo.graphml"
end
to spread
if (count turtles with [informed? = true] > .7 * count turtles) [stop]
ask turtles with [ informed? = true ]
[
ask link-neighbors with [not informed?]
[
if (random-float 1 <= 0.01)
[
set informed? true
show-turtle
set color green
]
]
]
set num-informed count turtles with [informed? = true]
tick
end
Thank you a lot.
I am a little unclear so am giving bits of different answers for different situations.
If the turtles are different each time, what do you mean by 'the same turtle'. For example, do you mean the turtle in a particular position? If so, you could select the turtle on the appropriate patch.
If it doesn't matter which particular turtle it is (just that it's the same turtle), then the simplest approach is to set the random-seed. Then every time you run any random process (including choosing one-of the turtles to select the starting infection, or ask turtles to do something), NetLogo will use the same chain of random numbers. Of course, if you are still building your model, then adding new pieces of code that change how many calls are made to the random number generator will lead to a different chain, but rerunning with the same code will give the identical run.
You may need to use with-local-randomness and random-seed new-seed if you want to have some parts actually change.
The problem is that nw does not store the WHO variable this is to avoid conflict with already existing turtles in a model.
A work-around would be assigning each turtle a separate id variable and setting that to who.
turtles-own [informed? id]
in turtles creation asign them each the id thus
set id who
you may want to write a conversion procedure like this
to convert
nw:load-graphml "JK_nachnamen.graphml"
ask turtles [set id who]
nw:save-graphml file-name "JK_nachnamen(id).graphml"
end
and use the copy. Of course you would not use
turtle 74
but
one-of turtles with [id = 74]