All of my turtles have a turtles-own 'distance-travelled variable' and I want to plot how this changes for each turtle on the same graph. I know I could state which turtle ie
ask turtle 0 [plot distance-travelled]
But the nature of my model means that the user can change the number of turtles so I can't pre-emptively write in which ones to plot.
Related
I want to create a model which stimulates cell replication in human tissues. To do this I will only be working with patches and not turtles.
A key concept to cell replication is fitness. Fitness in simplified terms is how 'strong' a cell is to replace the cell next to it.
Initially I created a tissue like stimulation where each color is a cell type with a fixed fitness 100. Then I introduced a mutated cell whose fitness ranges from 90 to 110. What I want to do now is introduce probabilities for cell replication based on different fitness values.
So if we have 2 cells next to each other, one with fitness 95 and the other with fitness 100, I want to have a code that says the cell with fitness 100 has a 75% to replace the cell with fitness 95. Of course this should go across the ranges from 90-110 and this probability will depend on what the fitness values of cells next to each other have.
patches-own [ fitness ]
to setup
clear-all
setup-patches
reset-ticks
end
to setup-patches
ask patches ;; randomly set the patches' colors
[ set fitness 100
set pcolor (random colors) * 10 + 5
if pcolor = 75 ;; 75 is too close to another color so change it to 125
[ set pcolor 125 ] ]
end
to go
if (variance [pcolor] of patches) = 0
[ stop ]
ask patches [
;; each patch randomly picks a neighboring patch
;; to copy a color from
set pcolor [pcolor] of one-of neighbors
set fitness [fitness] of one-of neighbors
if fitness > 100
[set pcolor 65]
]
tick
end
to mutate
;let mutateSet [patches with [ pcolor = 125]]
ask patches
[
if ( (random-float 1) < 0.05 ) [
set pcolor 65
set fitness ((random 20) + 90)
]
]
end
This is what I have so far, and I cannot figure out how to introduce this probability parameter accordingly inside the go section. I saw somewhere the rnd function helps with probabilities, but it was using turtles and not patches.
One very important tip I want to give you is to think about the stochasticity and scheduling in your model. Currently your agents take their action one at a time, with the order within each tick being randomised. This means that the order in which the patches change their pcolor has an influence on the outcome.
A way to circumvent this is to ask turtles twice. The first one lets each patch choose whether or not they want to change, the second ask actually does the changing. That way they all choose before any of them change.
The segregation model is a good example of that (it uses turtles but that doesn't make any important difference).
This choosing part (probably a separate procedure that you write) is where the magic happens. You can have each patch check their own fitness and the fitness of all nearby patches ([fitness] of neighbors). When you have these fitness values, you can use them to calculate the probabilities that you want (which depends completely on what you are trying to model).
When you have all your probabilities, you can use one of various methods to determine which one is randomly picked. I'm not going to write this out as there are already numerous examples of this exact thing on stackoverflow:
Multiple mutually exclusive events and probabilities in netlogo
In NetLogo how do use random-float with known percentage chances?
Netlogo - selecting a value from a weighted list based on a randomly drawn number
I made two simple models; one System Dynamics Model and one Agent Based Model in NetLogo. The SDM has a stock 'tourists' and its value depends on the in- and outflow. The value is re-calculated each tick. The tourists are sprouted in the ABM each tick. Now, I would like to use the value of the touristsStock as an input for the turtles that are sprouted each tick in the Agent Based Model. What is the best way to do this? I have already checked the example codes in the Model Library (Like the Tabonuco Yagrumo model) but it doesn't make any sense to me. What is the best way to integrate these models with each other? Thanks in advance!
The relevant piece of code of the ABM is as given below:
to go
clear-turtles
;sprouts turtles only on patches with value beach AND patches that are close to the lagoon (calculated in ArcMap)
;the initial number of tourists is multiplied by the percentage of tourists that were satisfied in the previous tick.
;percentage of tourists that were not satisfied is subtracted from 100 and divided by 100 to make it a factor between 0-1.
ask n-of (initial-number-tourists * ((100 - percent-dissatisfied) / 100)) (patches with [ beach_close_to_lagoon = 1])
[
sprout 1 [
set color black
set size 10
]
]
ask turtles [
set neighbor min-one-of other turtles [distance myself] ;; choose my nearest tourist based on distance
set distance-tourist distance neighbor ; measure/calculate distance of closest neighboring tourist
]
ask turtles
[ ifelse distance-tourist > 5
[ set satisfied? True]
[ set satisfied? False ] ]
update-turtles ;before the end of each tick, the satisfaction of each turtle is updated
update-globals ;before the end of each tick, the percentage of satisfied tourists is updated in globals
;clear-turtles ;because each tick represents one day, the tourists will leave the beach after one tick so the turtles will die
tick
end
I have a NetLogo model. each turtle has two attributes, "closeness" and "deviation_from_oracle". Now let's say there are 1000 agents in the model. The question is, how can I plot the "closeness" against "deviation_from_oracle" ?
It would also be helpful if I can get a csv file from NetLogo that has the value of closeness and deviaiton_from_oracle of all turtles after for example 1500 steps.
I definitely agree with Hugh_Kelley regarding using Behaviorspace to output your values (or custom export functions that might make for easier data cleanup if you're looking to report values for a large dynamic number of turtles- depends on your comfort with your statistical software of choice).
If you do need to plot something on the interface to show your users or something, you may find the plotxy function does what you need. For example, you'll need a plot on the interface called "plot 1" and a single blank pen in that plot called "pen-0".
You can control that plot either by manually setting up its x and y extent or by using the set-plot-... commands as in this setup:
to setup
ca
crt 10
set-current-plot "plot 1"
set-current-plot-pen "pen-0"
set-plot-pen-mode 2
set-plot-x-range 0 17
set-plot-y-range 0 25
reset-ticks
end
If you need to have a value plotted for each of your turtles, you can get the turtles to call plotxy for whatever values you're looking to plot- here I just use their absolute x coordinate and distance to the center as an example:
to go
ask turtles [
rt random 61 - 30
fd 1
set-plot-pen-color color
plotxy ( abs xcor ) distance patch 0 0
]
tick
end
This gives output like:
Where each point was plotted by an individual turtle.
If you want instead some reported mean value, have the observer call plotxy instead- another example that plots the average distance to other turtles and the average distance to center:
to go
plotxy mean-closeness-to-others mean-distance-center
ask turtles [
rt random 61 - 30
fd 1
]
tick
end
to-report mean-closeness-to-others
report mean [ mean map distance sort other turtles ] of turtles
end
to-report mean-distance-center
report mean [ distancexy 0 0 ] of turtles
end
For an output like:
I'm trying to build a multi-species model in netlogo. All turtles will have the same movement protocol but their decisions are based off of conspecific densities (number of their breed in a patch), not the full turtle count. Is there a way to get them to recognize members of their own breed without specifically saying
count breeda-here
I'm thinking it would be something like
count breed(self?)-here
but that's not netlogo syntax. I want them to:
1) count the number of their breed at the current patch
2) count the number of their breed at patches in-radus x
The ultimate goal is to have a single movement protocol for all breeds to reference (instead of an individual movement protocol for each).
Thanks in advance!
I imagine it should work something like this if you just want the agentset returned, as opposed to the count:
to-report breed-in-radius [x]
report other breed in-radius x ;breed is *this* turtle's breed
end
Note that because in-radius is turtle/patch only (and because we reference turtle variables directly), this would need to be called in turtle context.
I'm currently trying to implement a model in Netlogo where the turtles’ behaviors depend on all of their neighbors.
My point of departure is the coordination game code provided by:
http://modelingcommons.org/browse/one_model/2549#model_tabs_browse_info
According to this model the payoff of for the turtle is determined by introducing a variable which takes the color of neighbor as its value.
ask turtles [
let his-color [color] of one-of turtles-on neighbors
if color = yellow and his-color = yellow [set payoff A-yellow-yellow set alt-payoff B-red-yellow]
However, I need to my turtles to gain their payoff by comparing their color with all of their neighbors simultaneously. The last part is problematic due to Netlogo's default synchronic update
Can anyone guide me in how to make the update simultaneously and depending on all of the neighbors, or does someone have a reference to a place where this is discussed?
Just collect all colors before changing any of them. E.g.,
turtles-own [nbr-colors]
to go
ask turtles [
set nbr-colors [color] of neighbors ;get list of current colors
]
ask turtles [
set payoff compute-payoff nbr-colors
set color anything-you-want
]
end