In Netlogo, I have turtles-own lists, which means I set a turtle's variable to be a list. Each tick, another value is added to the list. After a few thousand ticks, these lists are quite long... and the problem arises that I can't open the agent monitor in the GUI any more because it takes too long to load the list.
reproducible code:
breed [persons person]
turtles-own [examplelist]
to setup
clear-all
reset-ticks
create-persons 1 [setxy 0 0]
ask turtles [set examplelist []]
end
to go
ask turtles [set examplelist lput ticks examplelist]
tick
end
I would need the agent monitor to watch another turtle-own variable; I don't need to watch the lists (they are just used to do a calculation every 8760 ticks).
Is there maybe a possibility, to e.g. hide the list from the agent monitor? Or do I need to handle the lists as global variables instead? Being quite unhandy as I would need to create and name separate lists for every turtle...
I can see three options:
1/ If you are creating a modelling framework, I assume that your user cannot actually code in NetLogo. This means that you have to predefine the scenarios for them anyway (for example, they could choose the calculation), so you only need to have the possible calculations stored instead of all the input values to those calculations.
2/ It is not clear from your question why any user would open an inspect window or otherwise access the individual turtle. If the user doesn't need it directly, instead of adding all this information to the turtles, you could export it to a file, adding a line each tick. The user would do the analysis of the simulation in R or Excel or whatever.
3/ You could create a shadow turtle for every turtle. This is not something I would recommend, but the idea is that the shadow turtle has a subset of variables (not the lists) and the variable values it does have are identical to the turtle it is shadowing. The limited set of variables version of the turtle is the one that would accessible to monitor.
Related
I am modifying lammps source code for my specific purpose. I have created a new atom style which has a molecule id, bonds, angles, a dipole, and a new custom value lets call activity. Currently it is set up so that it reads a data file which has all of these things as inputs. Some different number of atoms are part of the same molecule and have the same molecule id are bonded together, and have an input activity (for each atom) which is different for each molecule but the same for all atoms which are part of the same molecule. I want to be able to modify the value of this activity at different times for different molecules during the simulation. I tried to have each atom use the activity of a specific "leader" atom that is part of it's molecule but this didn't work because atoms that are on different threads will have different indices so I can't see how to get it to take the activity of a specific atom from a different thread. I think maybe I need to define a variable that is a vector of the activity for each molecule, and the atoms can read the activity from this variable whenever they need to use it. Is this a thing that variables can do? If so how can I go about implementing this? Do I need to create the variable using the variable command in my input script? And then I can use it within the code to modify it's values mid simulation?
I'm trying to measure the mean value of agents that are performing a certain acitivity. To calculate this value, I tried to use: set mean-powerdemand mean [ powerdemand ] of agents with [ powerdemand > 0 ]
To give some contexT: My model concerns charging electric cars. I want to measure the powerdemand of agents that are actually charging their car and thus have a powerdemand > 0. I want to exclude the non-charging agents for this mean calculation, as this would bring down the mean value. However, as there are moments in time (specifically at the start of the run) where no cars are charging, I am getting the error: Can't find mean of a list with no numbers: []
Does someone know a way to work around calculations with agent-own variables and/or lists that are sometimes empty?
I started of by calculating this value in a plot by using the same code. By doing so, it does not prohibit me from running the model, but since I want to use it as a reporter in the BehaviourSpace set-up, I want to make a global value of it.
Thanks.
I'm trying to simulate a car production factory and trying to keep separate lists of turtles who are on jobs and who are not on jobs.
I have a turtles-own variable: is-on-job?
I want to have a agent set of turtles not on jobs not-working-turtles
I want to have a agent set of turtles on jobs working-turtles
Whenever a turtle is on a job, is there a way to remove that specific turtle from the not-working-turtles agentset and add it to the working-turtles agentset?
Also on a different topic, is there a way to sort turtles based on distance to a specific patch and then if the closest turtle is on a job then go to the second turtle and so on?
You can create your two agentsets as:
let not-working-turtles turtles with [not is-on-job?]
let working-turtles turtles with [is-on-job?]
To move a turtle from one to the other, you will need code along the lines of:
to make-me-work
let free one-of not-working-turtles
ask free
[ set is-on-job? true
set not-working-turtles other not-working-turtles
]
set working-turtles (turtle-set working-turtles free)
end
Here I used the very convenient other primitive to remove the turtle doing the asking. You are more likely to want to do this as a procedure that takes arguments and pass the turtle to the procedure rather than randomly select one within the procedure, but the code would be similar.
On your question about choosing the closest, you don't need to sort. Instead, look at min-one-of in the NetLogo dictionary. If you can't work it out, please do a new question (StackOverflow should be only one question per question) with the relevant code.
I am trying to write a code in which the probability of a collaboration being successful increases the more similar the agents are. on each run, a local variable computes the difference between agents and creates a link between agents if that difference doesn't exceed a threshold. the agents are subsequently stored in 2 separate lists based on whether a link was created or not. now, i would like to create another list that contains a successful vs unsuccessful value for each agent with whom a link was created. the probability of that value being 'successful' increases the more similar agents are (the more their difference value approaches 0).
the closest i've come to implementing this is the rnd extension. however, it seems to me that rnd:weighted-one-of only takes agent sets or lists as input and i do not have a predefined list for the similarities of agents. it is the whole range of 0 (complete similarity) and 1 (dissimilarity) that i would like the local variable to be compared to. is this possible in the way i'm currently thinking about it?
let difference 0
let initiator one-of turtles
ask initiator [
let potential one-of other turtles
if random-float 1.0 <= [my-activation] of self [ ;; different probability
set difference [my-profile] of self - [my-profile] of potential] ;; of initiating
;; collab
ifelse difference <= threshold [ ;; if threshold is met
create-link-with potential ;; link is initiated
set collaborators fput potential collaborators][ ;; the initiator adds the
set failures fput potential failures] ;; potential to their list of
;; either collaborators
I recommend considering logistic functions as a way to relate similarity to probability. A logistic function is a "s"-shaped function that ranges from 0 to 1 as some X value (e.g., similarity) varies over a wide range. You can define the logistic function by assuming, for example, what values of similarity produce probabilities of 10% and 90%.
There is a complete discussion of using and programming logistic functions in NetLogo models in chapter 16 of: Railsback and Grimm 2019, "Agent-based and Individual-based Modeling".
I am running a NetLogo model in BehaviorSpace each time varying number of runs. I have turtle-breed pigs, and they accumulate a table with patch-types as keys and number of visits to each patch-type as values.
In the end I calculate a list of mean number of visits from all pigs. The list has the same length as long as the original table has the same number of keys (number of patch-types). I would like to export this mean number of visits to each patch-type with BehaviorSpace.
Perhaps I could write a separate csv file (tried - creates many files, so lots of work later on putting them together). But I would rather have everything in the same file output after a run.
I could make a global variable for each patch-type but this seems crude and wrong. Especially if I upload a different patch configuration.
I tried just exporting the list, but then in Excel I see it with brackets e.g. [49 0 31.5 76 7 0].
So my question Q1: is there a proper way to export a list of values so that in BehaviorSpace table output csv there is a column for each value?
Q2: Or perhaps there is an example of how to output a single csv that looks exactly as I want it from BehaviorSpace?
PS: In my case the patch types are costs. And I might change those in the future and rerun everything. Ideally I would like to have as output: a graph of costs vs frequency of visits.
Thanks
If the lists are a fixed length that doesn't vary from run to run, you can get the items into separate columns by using one metric for each item. So in your BehaviorSpace experiment definition, instead of putting mylist, put item 0 mylist and item 1 mylist and so on.
If the lists aren't always the same length, you're out of luck. BehaviorSpace isn't flexible that way. You would have to write a separate program (in the programming language of your choice, perhaps NetLogo itself, perhaps an Excel macro, perhaps something else) to postprocess the BehaviorSpace output and make it look how you want.