NetLogo: Measure total area covered by turtles - netlogo

After my NetLogo simulation, I would like to measure the total area covered by only the turtles. Is there a simple way to implement this in NetLogo, or will I have to do this in another program?
My simulation has clusters that form and I would eventually like to calculate the cluster agent density. 1

NetLogo is not aware of where the edge of the turtles’ shapes are. So, if you are trying to work out what proportion of the screen has shapes on it, you need to do some complicated programming to calculate where the edges of the shapes are, how they overlap and so on. However, if all you care about is where the turtles are, then it's much easier. For example, to work out the proportion of patches where there are at least one turtle, you could do:
count patches with [any? turtles-here] / count patches

Related

why are my results from behaviorspace (netlogo) so inconsistent?

I am somewhat new to Netlogo, and have been scratching my head over some of the results I get from behaviorspace. I have been playing with the wolf-sheep predation model, and changing their movement based on what color patch they are in. There is a single wolf and a single sheep, and what I want to measure is the number of time steps it takes for the wolf to eat the sheep. The patches are colored randomly, based on some proportion from 0-100, as below:
to color-patches
let total 100
let p-red slider1 / total
let p-green total - p-red
ask patches [
let x random-float 1.0
if x <= p-red + p-green [set pcolor green]
if x <= p-red [set pcolor red]
]
end
The issue I am having is when I set the movement of the wolf and the sheep to move independently of the patch color:
ask sheep [
set heading random 360
fd 1
]
ask wolves[
set heading random 360
fd 1
eat-sheep
]
My expectation is that the mean and standard error for the number of time steps until the wolf eats the sheep should be pretty similar regardless of how many red patches and how many green patches there are, since their movement is not affected by it. I ran it in behaviorspace, with 1000 iterations per 10% increase in proportion of red patches (from 0 - 100%). However, I keep getting results that look kind of like this:
enter image description here
Basically the means+se are all over the place. Every time I run it, they are distributed differently (but same grand mean). This is particularly odd since when I introduce any sort of patchcolor-specific behavior for either the wolf or the sheep, I get very clear patterns with less variation.
Any ideas what might be going on here? The only thing I could think of is that relative starting position of each is pretty important (but each is placed at random xy coords). I assumed that in behaviorspace for each iteration for a given set of parameters, it would run through all the code (thus generating a new random landscape and new random starting points for the wolf and the sheep for each of the 1000 runs per parameter combination). Does behaviorspace maybe take the first landscape and starting coordinates for each turtle and use them for each of the 1000 iterations per parameter combination?
Thanks!
Now I think you may not have a mistake but instead are just misinterpreting your graph. The Y axis on the graph you posted ranges only from 2000 to 2200; if you set the Y axis scale to 0 to 2500, the results from each experiment would look very similar to each other.
The difference in mean between your results (~2100) and my results (~3100) is probably just due to different world sizes. I presented standard deviation while you graphed standard error.
If you histogram the results, they seem to follow an exponential distribution.

How to code turtles avoiding pop. densities at certain patches

I am trying to create a sub-model in NetLogo in which my turtle agents avoid/flee urban patches that have a human density greater than the agents' tolerance threshold. The objective of this model is to experiment with the human-density variable to see how/if my turtles move in response to higher or lower human populations.
I am having extreme difficulty in conceptualizing how I can implement the human-population variable into the individual urban patches and have the patch calculate its own human-density. I would like to have the option of changing the human population variable so that I can see how the turtle responds to the changing human density at the urban patches.
To give a hypothetical example: There are two urban patches (cities) in a state county, Urban_1 has an area of 600m while Urban_2 has an area of 200m. The human population at both urban patches are 100 people, and thus the human density at Urban_1 is 0.16 people/m2 and the human density at Urban_2 is 0.5people/m2. The turtle tolerance threshold is <0.4 humans/m2.
How can I code the human population variable so the population densities can increase/decrease? Is the human population variable a global variable? Or is it an agentset of the urban patches?
To see the human population density or growth you to plot in the GUI more or less like this: plot count human. Nice things to do is to differentiate the types of agent with different turtles-own group. In order to avoid some turtles to go above a particular kind of patches you need to create a patches-own variables and then do like this: patches-own [ ... feromone-killer ] ... to wiggle if (feromone-killer >= 0.01)
(To wiggle is a method that determinate the movements of my agents)

How do you make a turtle grow exponentially in NetLogo?

so I am trying to model the spread of cancer throughout human tissue and I am wondering how to make the turtles grow and divide like actual cancer cells do?
More specific:
I am starting with one turtle in the center of the interface and i want that turtle to divide into two turtles then those turtles do the same as the first one, one splits into two two split into four and four split into 8. How do i code this?

NetLogo - Create functions that affect landscape equally

I have a NetLogo model for which I'd like to create different human disturbance scenarios impacting carnivore "prey" across the landscape. Here is my NetLogo landscape of a real protected area. Lighter colored pixels have higher prey values than darker colored pixels.
I'd like to create functions that simulate human disturbance from the edge of the protected area. I'd like to try different functions, such as sigmoidal and exponential decay (i.e., areas closer to edge of protected area have prey pixel values reduced more so than prey pixels farther from the edge).
I can implement some simple functions with the following:
ask patches with [is-park?] ; patches inside the protected area
[
set dist-boundary distance (min-one-of patches with [is-park? = FALSE][distance myself]) ; calculate distance of patch from edge of park
set prey (prey - e ^ (- dist-boundary / 10)) ; scenario 1 human disturbance
set prey (prey - (-0.1 * dist-boundary ^ 2 + 0.9 * dist-boundary)) ; scenario 2 human disturbance
]
However, I'd ideally like to create a set of scenarios such that the total prey reduction across the landscape is equal for each scenario (but distributed across the landscape differently). That would allow me to assess the impact of spatial distribution of human disturbance independent of total magnitude of impact. Any ideas on how to do that would help me a bunch. I've been stuck on this a while now.
It sounds like you are looking for the "diffuse" function.
diffuse "patch-variable" "number"
When you have a human (possibly a turtle) in a patch they can diffuse "negative-influence" a patch variable double I just invented that would remove prey and decrease as it does so.
ask patches with [human?] ;patches with a human create negative influence
[
set negative-influence 8.8; can be any number
]
So you've created negative-influence now we implement the diffusion:
ask patches with [negative-influence>1]
[
set prey prey-(factor*negative-influence); removes some prey
set negative-influence negative-influence*(1-factor); reduce negative-influence
diffuse negative-influence 0.5 ; half gets diffused into neighboring patches
]

Node degree in a network

I have a landscape that includes a road network as in the below figure.
I would like to calculate an average number of roads (or white line in the figure) that link each color polygon (for example a black polygon) between them.
In a network, a link corresponds to a road, a node corresponds to a color polygon and I think that to calculate an average number of roads between color polygons means to calculate the average node degree of the network. For example, in the figure, the two black polygons are linked by two roads. So, the degree of a black polygon is 2. Is it possible to calculate a node degree with the extension Network of Netlogo ?
Thanks in advance for your help.
Normal NetLogo contains link agents that link turtles even without an extension. Calculating degree is usually just a matter of doing [ count my-links ] of node where node is the turtle you want to know the degree of. However, in NetLogo, turtles can't be connected by more than one link. The typical workaround for this is create a links-own variable (just like turtles-own or patches-own variable) . This variable is often called weight, but you can call it whatever you want. In that case, you would do [ sum [ weight ] of my-links ] of node to calculate the degree.
This is all assuming you have a network representation of your roadways, which it doesn't sound like you do. Furthermore, I'm not sure what you're trying to represent is a network, since (as shown in your picture) roads branch at intersections. Thus more than two polygons could be connected by a single (for some definition of "single") road. This is often called a hypernetwork or hypergraph. However, this is probably a heavier weight concept than what you want.
Now, I'm not entirely sure what you're really trying to calculate. Is it:
...the number of roads connected to a polygon? The lower polygon has 4 roads connected to it, the upper has 3 (visible).
...the number of polygons directly connected to the polygon? Both polygons are connected to 1 other (visible) polygon, though I assume in the larger picture there are more.
The number of roads connected to a polygon would be pretty easy to calculate, assuming each road is 1 pixel wide. You could just do:
count (patch-set [ neighbors4 with [ is-road? ] ] of polygon)
where polygon is a patch set containing the patches of the polygon and is-road? is a reporter that returns true for road patches and false for non-road patches (this could be something pcolor = white). Note that this will break if roads are wider than 1 patch or if the same road can touch a polygon in other places. Let me know if that's the case and I'll expand this into something that can that into account.
The number of polygons directly connected to the polygon is more difficult. The basic idea would be to follow the roads out until you hit other polygons and count the number that you hit. Code for this is somewhat tricky. I think the best way to go about it would be to have two patch-sets, frontier and explored and list of found polygons. frontier should initialize to every road patch touch the polygon. Each iteration, get the polygons touching the frontier and add them to the list of found polygons if they're not already in there. Add the frontier to explored. Get all the road patches touching the frontier that are not in explored. Set the frontier to this new set of patches. Keep going until frontier is empty. This is a version of breadth-first search. There could be a better way to do this.