I am working on an organizational behavior problem where I have a work group/community of practice I'm trying to create out of agents from each region. As seen below, I am using the GIS extension to load in a regional shapefile and then randomly distribute agents based on a slider in the interface. Agent attributes are set, with two of them being randomly generated between 0-1 (EJknowledge and EJtranslation). The code then assigns the agents to the region they are spawned in.
Where I am stuck is in my need to take the agent with the highest EJknowledge in each agentset (region) and create a new agentset with all of those agents so I can have them "meet" once a month for their work group/community of practice meeting. All attributes are the same for all agents, so I didn't think having a separate breed would provide me any advantage.
I have two questions:
In the code I have it set up where I was attempting to use max-one-of to identify the highest EJknowledge agent in a region and set it to another agentset. This current writing didn't work for me because I only know how to write this for one agentset and have not figured out how to run it for multiple agentsets then assigning to the "cop" agentset. I'm sure this is just a shortcoming in my syntax knowledge but I have yet to find other questions that have a satisfying application for my problem.
globals [region1 region2 cop]
turtles-own [region EJknowledge]
patches-own [ID]
to go
;; create turtles and assign attributes
create 25 turtles
ask turtles [
set shape "person"
set color blue
set EJknowledge random-normal 0.5 0.1
set region [ID] patch-here
]
;; assign agents to regions
ask turtles [
set region1 turtles with [region = 1]
set region2 turtles with [region = 2]
]
;;
ask turtles [
set cop max-one-of region1 [ EJknowledge ]
]
end
You can use the turtle-set
primitive, which works like the list
primitive.
Here is a simplified example:
globals [topknowers]
turtles-own [region knowledge]
patches-own [ID]
to setup
clear-all
ask patches [
ifelse pxcor > 0 [ set ID 1 ] [ set ID 2 ]
]
create-turtles 25 [
set shape "person"
set color green
setxy random-xcor random-ycor
set knowledge random-normal 0.5 0.1
set region [ID] of patch-here
]
set topknowers (turtle-set (max-n-of 5 turtles with [region = 1] [knowledge]) (max-n-of 5 turtles with [region = 2] [knowledge]))
ask topknowers [
set color blue
]
reset-ticks
end
turtle-set
primitive can be used to combine any number of agent-sets turtle-set agentset1 agentset2 ...
. However, as the name suggests, you cannot mix turtles with patches or links.link-set
and patch-set
variables for those agents.max-n-of
primitive to pick more than one agent from each group instead of max-one-of.
Note: I noticed a few syntax errors in your code, such as create 25 turtles
, which should be create-turtles 25
, or creating turtles in a go
procedure, which is conventionally done within the setup
procedure.