setting up turtles with preset distance between them (netlogo) - 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!!

Related

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

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

More patches per turtle according to its size Netlogo

I 'm new in Netlogo programming. I would like to make turtles with cloud shape and big size so if another turtle i.e. a person be at the same patch with the cloud to lose energy. The problem is that I can't have a turtle to be in more than one patches, netlogo "can see" that it's in only one patch.
Regardless of the size of an icon depicting a turtle, the turtle is located only at a single point (defined by the variables xcor and ycor). However, you can instead use distance to find if other turtles are close
As JenB said, the turtle only exists as a point, you'll have to come up with logic to make the clouds seem bigger than they are if you want them to be turtles.
Here is some code that demonstrates how to use size and in-radius to make the clouds breed affect the leaves breed color as they move past. It works best with shape = "circle" since then the radius of the cloud will match where the leaves are affected. You can add this code to a basic new NetLogo model to see it work:
breed [ clouds cloud ]
breed [ leaves leaf ]
to setup
clear-all
ask patches [
set pcolor blue + 2
]
create-clouds 10 [
set xcor random-xcor
set ycor random-ycor
set size 1 + random 4
set color white - 2
set shape "circle"
]
create-leaves 35 [
set xcor random-xcor
set ycor max-pycor
set shape "leaf"
set color green
set heading 180
]
end
to go
ask clouds [
ask leaves in-radius (size / 2) [
set color (color - 1)
]
]
ask leaves [
fd (1 + random 10) / 10
]
end
You can also reverse the logic a bit so it's the leaves that check if they are inside a cloud using distance. I find this option more confusing, but it might work better in your case:
to go-leaves
ask leaves [
if any? clouds with [distance myself < (size / 2)] [
set color (color - 1)
]
fd (1 + random 10) / 10
]
end
And finally, instead of using turtles to represent your large areas that turtles move through, you could use patches instead. It would simplify some things, but wouldn't work in every case.

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...

NetLogo Initializing Turtles at Specific Co-Ordinates

in a NetLogo model, I have some "plant" turtles in a space. The number of which is 5, and will always be 5.
set-default-shape plants "plant"
create-plants 10
[
set color green
set size 2
setxy random-xcor random-ycor
setxy random-xcor random-ycor
]
At the moment each of these plants randomly spawns in the world. I want to be able to set the point at which each of these plants is placed.
Something akin to:
setxy plant-1 25 25
setxy plant-2 25 25
Is there any way to achieve this?
Currently, the line setxy random-xcor random-ycor is setting the x-coordinate and y-coordinate of the plants to random values. Note that you seem to have that line in your code twice. The first instance of it gets overwritten by the second. Anyway, you can also use setxy to move plants to particularly coordinates, e.g. setxy 25 25. However, replacing setxy random-xcor random-ycor with setxy 25 25 would put all the plants at that location. I assume you want multiple plants in multiple specific locations. To do that, you can just ask the individual plants to move:
ask plant 0 [ setxy 25 25 ]
ask plant 1 [ setxy 10 40 ]
and so forth.

Move turtles around a patch

I am trying to move turtle around patch 0 0 starting from random position in world. But circle keeps on growing. What am I doing wrong here?.
Code:
to setup
clear-all
create-turtles 5
ask turtles [
setxy random-xcor random-ycor
]
ask patch 0 0 [ set pcolor green ]
reset-ticks
end
to go
move-turtles
tick
end
to move-turtles
ask turtles
[
face patch 0 0
right 90
fd 0.01
set pen-size 3
pen-down
]
end
Secondly I want a turtle to move around any patch I define when it reaches with in a certain range
Your approach is to take a small step along a tangent to the circle you want, but this takes you a little bit outside the circle. You do this repeatedly, so it accumulates over time.
For a better way, see the Turtles Circling example in the NetLogo Models Library.