How to code turtles avoiding pop. densities at certain patches - netlogo

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)

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.

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

Move agent based on probability/point attribute value and point distance, NetLogo

I have the set of points implemented in netlogo and agents are moving from one point to another. Each point has a weight (number approximately between 0 and 9, its not a probability). What I want to made is a simple rule.
I want to give all points probability of visit by the value of weight.
So the next point which will be visited by agent should be calculated by the probability based on point weight and the closeness point (more close point - bigger probability), but that closeness isn't so much big factor as the point weight. For example, I would like to set in formula that closeness is twice lower factor then point weight.
I investigated rnd extension, but I am not sure how to append probabilities to points which I am having a lot (approximately around 250 points).
You're on the right track with the rnd extension. From that extension you need the weighted-one-of primitive and you just put the formula into the reporter block.
I think this is something like what you want. It's a complete model so you can run it and see what it does. The reporter block uses the weight and the distance in the probability. Since you want the probability to be larger for closer, then I have used the inverse of the distance, but you could simply subtract the distance from something like the maximum distance in the model. You will also need an appropriate scaling factor (replacing the 10 in my example) so that the weight is worth twice an average value of closeness.
extensions [rnd]
turtles-own [weight]
to testme
clear-all
create-turtles 10
[ setxy random-xcor random-ycor
set weight 1 + random 3
set size weight
set color blue
]
ask one-of turtles
[ set color red
let target rnd:weighted-one-of other turtles [ 2 * weight + 10 / distance myself ]
ask target [ set color yellow ]
]
end

how to calculate the distance of moving vehicles is how much?

I want to determine the distance the vehicle traveled for comparison with other values, I should use the command / function what to calculate.
for example in the picture, I want to use the function to determine the distance d1, after one-time drive, the distance will be the last .... d2 distance riding is dn
I'm not sure if I understand your question. Perhaps JenB's comment is better for you. But here's a different kind of answer:
A simple way for a turtle to keep track of how far it has traveled is shown in this small example program:
turtles-own [traveled]
to example
clear-all
create-turtles 1
ask turtles [
repeat 5 [
let delta random-float 1.0
fd delta
set traveled traveled + delta
]
print traveled
]
end
Basically, every time the turtle moves, you add the amount it moved to a turtle variable.
This assumes you are using forward to move the turtle. If you are moving the turtle using some other method like setxy or move-to, then you will need different code.

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
]