In NetLogo, what is the most efficient way to copy the values of variables in an agentset to another agentset with the same number of agents - netlogo

In NetLogo, I have the same number of turtles on different patches. Now I want to copy the agent variable values of the agents on one patch to those agents on another patch. I know I can define a list of members for each patch, and then copy the values agent by agent according to the order of the list, but I have to define a list for each patch, which may take some memory and reduce the running speed.
In other words, I want the agents on one patch with their agent variable values the same as the agents on another patch.
Are there more efficient ways to do this?

I use something like this hatch makes exact duplicates of the original turtles same variables same color etc
targ is the patch you want them at
to dup-turtles-to [targ]
ask turtles-here
[
hatch 1 [move-to targ]
]
end
I hope that is helpful and I understood your question correctly.

Related

keeping variable results after turtle dies netlogo

Looking for a way to store a turtle length of stay in the model after they have left the model. My model runs for several months and a few thousand turtles enter, undergo process then leave the area. It's complicate model (it's a hybrid DES and ABM) so I've tried to reproduce the simple bit below.
Turtles will be created at every tick and given a random length of stay but will only be able to begin process when they move to the right area (area-name) and when their time is up they leave the area. Their time-in-system reflects the wait for the area and the length-of-stay which I want to save once they're complete. If I leave them in the model it starts to break down after a couple of months and I suspect this is because the model has too many turtles still in the system for calculation and is inefficient.
go
create turtles 2
[
set time-in-system 0
set length-of-stay ceiling ((random-normal 48 4) + ticks)]
set shape "person"
if any? area-name with [not any? turtles-here]
[move-to one-of area-name]
]
undergo-process
end
to-undergo-process
ask turtles with [shape = "person"]
[
set time-in-system time-in-system + 1
]
ask turtles-on area-name
[if ticks = length-of-stay
[set shape "dot"
move-to exit-door]
end
I can then plot and see in realtime to make sure it is working
histogram time-in-system of turtles with [shape = "dot"]
but can't seem to figure out how to store them as unique values for plotting after the model has run and I have a dataset of outcomes without keeping them alive in the model. The real-time plot isn't necessary as long as I can store the unique values after they have left
If I ask them to die then I lose the unique values in the histogram. I don't want a tally of all values but each turtle's unique value at the end of the process after they left - at the moment the only solution I have to storing them is as an agent-set that stays alive in the exit-door patch but this takes up a lot of calculation power as the model progresses for months...
There may be a really simple command for this but I've been going round in circles through the programming manual trying to find it. Any tips appreciated
You should create a list storing the values of turtles that left.
Isolating only the code that is relevant for this purpose, it would be something like:
globals [
times
]
to setup
set times (list)
end
to leave-simulation ; This being executed by turtles.
set times lput (time-in-system times)
die
end
If your program is going to run for actual months, I recommend you use the file-write command to store your data. This way the data is preserved if the program halts for any reason; it gives you much more freedom to do the analysis you want without running the full simulation again.
If you write to a .csv (comma separated value) file, you can use almost any program (excel, R, matlab, python, C# or back to netlogo) to plot a histogram.

Netlogo: is nobody still being treated as an agent?

I have a list of parcel agents. but I will kill the parcels periodically. However, the list is still recording someting like this: [nobody nobody nobody nobody nobody nobody nobody nobody], and overtime the running of the model is getting slower and eventually pop up message "your model is too large to run with available memory"
In this case, are the dead agents (i.e. nobody) still treated as an agents that consumes much of the memory? what if it is a pure list of numbers or strings? would it cause the same OOM issue? how big the list can be in Netlogo and any uppper limit?
From, the NetLogo dictionary for die: If you have a list of agents and the agent dies, then the agent is removed from any agentset and:
The agent will disappear from any agentsets it was in, reducing the size of those agentsets by one.
Any variable that was storing the agent will now instead have nobody in it
The dead agents are not consuming resources, but the list is (as you have found by printing out the list). You can see this with the following model:
globals [mylist myagentset]
to setup
clear-all
create-turtles 1
set mylist sort-on [who] turtles
set myagentset turtles
reset-ticks
end
to go
create-turtles 1
[ set myagentset (turtle-set myagentset self)
]
set mylist lput one-of turtles mylist
ask one-of turtles [die]
type "turtles: " print count turtles
type "list: " print length mylist
type "agentset: " print count myagentset
tick
end
If you want the dead turtle to be removed from the list, you need to explicitly do so with remove-item. The same is true of lists of numbers, strings etc.
Alternatively, if the list doesn't need to be maintained over ticks, but can be reconstructed (eg if it is a sorted list of the turtles agentset), you could create it each tick and that list would only contain turtles that are alive.

How to switch agents from one breed to another during a simulation?

I have a stock market simulation with two types of breeds, passive and active. They both have different formulas for investing. However, I would like the agents to switch between the two breed types. I have a condition they should follow to decide when to switch. However, I am not sure how to program the agents to switch.
You should be able to simply set the breed of an agent, just as would any other variable:
ask one-of passives [ set breed actives ]
Assuming you used passives and actives as your breed plural names.
You can read more in the NetLogo programming guide.

Assign Summed Patch Variable to an Agent or Patch-Set

My simulation is of farms. Farmer agents own the farms and farms are created from a random number of patches around the agent that then "belong to" the farmer.
Each patch owns a Rate of Production variable (random number up to 50).
How do I then assign a value to an agent-owned variable that sums the RoP for each patch in the farm and makes that the farmer's total RoP? Something like... ask farm to [ set farm-RoP ... to the sum of all patches RoP in-radius ]. I am unsure of how to create the syntax.
Thank you, in advance, for any help anyone can provide!

Add a turtle's variable value to another turtle's variable value

I am struggling with trying to write this command.
Basically, what I want to do is this:
I have a collectors [own carryingcapacity], bins [own waste in bins] and warehouses [own waste_in_warehouse] as turtles.
The collectors have a maximum carrying capacity value.
I want to make the collectors check if they have carrying capacity when they find a bin, if trash in bin <= collectors max capacity, the collectors will collect, if not they'll ignore the bin.
I came up with something like this:
ask collectors
[
if any? bins with [distance myself <= 1]
[set carryingcapacity (carryingcapacity + (bins_holding_capacity of myself))]
]
Second command:
I want to make the collectors take the trash they collected to the warehouse. But this variable's value might change from one collector to another, and might vary with the quantity of bins they checked.
I want the warehouse to sum the value that it already had it on the previous days with the new daily values.
I came up with something like this as a line of command:
ask warehouses
[
if any? collectors with [distance myself <= 1]
[set waste_in_warehouse ( waste_in_warehouse + (carryingcapacity of myself))]
Thank you in advance.
Best wishes.
If I'm understanding correctly, your code for command #1 is doing the following:
ask collector agents
See if there are any bins close to a collector (but you didn't ask for this group)
increment the collector's carryingcapacity by (bins_holding_capacity) of myself (you can't use myself like this, because you aren't in a nested ask)
Step 3's logic also seems wrong, since this would be changing the collector's capacity each time, as opposed to checking if it is full.
It should be noted that by using any?, you are not also commanding that group of agents. any? only returns true or false, corresponding to whether there were agents that met the criteria or not. You need to use a second ask to command these agents.
Based on what you said, you'll need to do something like this:
ask collectors
[
ask bins with [distance myself <= 1] ;;myself refers to the collector asking
[
ifelse (waste_in_bin + [waste_in_collector] of myself) > [carryingcapacity] of myself
[;;add the waste to the collector]
[;;stop asking bins, collector is full]
]
]
These same steps should help with your second question, too.