Measuring distance covered in netlogo - netlogo

Does anyone have code to report how much a turtle travels during an experiment?
or to plot patches travelled?

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.

Calculating distance and determining units of measure in Netlogo using GIS extension

I'm using GIS extension in Netlogo to import shapefiles, then creating turtles from attributes of the shapefile. I'm using the distance primitive to calculate the distance between turtles. I know Netlogo does converts the shapefile to netlogo space, so the distances wouldn't be reported the same b/w GIS and Netlogo. For example, in GIS distance between turtle A and B is 49550 meters. In Netlogo, it's 0.2038. Is there a way to determine what the units of measure are in Netlogo? Is the conversion always the same or does it depend on the projection? Thanks for any assistance.
The distance in a NetLogo model is entirely arbitrary. You are deciding the unit of distance implicitly when you import a GIS real-world structure into whatever number of patches there are in the NetLogo world. In your case, the easiest way to work out the conversion factor is likely to be to find a few points on your GIS and get their xcor and ycor. From your question, haven't you already done this? You have said that 0.2038 is 49550m.
There will also be problems coming out of the projection - if your model covers a large real world area, then the mismatch between the surface of a sphere and a flat model will mean the distance conversion is different at different locations.
Maybe this helps. I found a model here, which is also trying to work with space.
I quote: "Grid cell size does not represent an absolute spatial unit (e.g. meters); instead, the size of grid cells is only meaningful with respect to the step size of individuals which can vary with user input."

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)

NetLogo: Measure total area covered by turtles

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

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.