posted Oct 30, 2017, 6:25 AM by Konstantinovich Samuel   [ updated Oct 30, 2017, 8:45 PM ]
Goal: Agentsets

-Attached to the end of this post is the NetLogo reference-sheet. You can use it as a quick reference. I will print out a copy and include it with the next test/quiz. You should familiarize yourself with it. 

-I said you would have a quiz this week BUT due to timing, I am changing that into an EXAM which will be Friday. 

It will cover all NetLogo up to agent sets and patches. We will finish those topics by Wed. You will have a lab Wed/Thurs.

Agent sets:  groups of agents. This is not a list, you can use agentset related functions.  


What can you do with agentsets?

ask AGENTSET [ commandBlock ]
ask turtles [ wiggle ]
ask turtles [ stamp die ]

display count turtles
ask turtles [ set size count turtles ]

Filtering an agent set:  
These commands specify which agents in an agent set you are talking about:

AGENTSET with [ boolean reporter ]  ; gets the agents from the agentset, that match the boolean.
create an agentset e.g.
turtles  with [ color = green]
patches  with [ pcolor = black]

do something with an agentset e.g.
ask turtles with [color = red] [die]   
   ;turtles with [color = red]    is an agentset with some turtles... but it could be empty!
ask turtles with [ xcor > 0] [set color red]

one-of AGENTSET      ;  gives you a randomly chosen agent from the agentset 
ask one-of turtles [die]   ; one-of turtles   is an agentset with exactly one turtle

one-of turtles  - randomly choose any turtle
one-of patches  - randomly choose any patch
one-of ( turtles with [ color = red] )  - randomly choose one of the red turltes. There must be at least one for this to work!)

!! Notice that agentset reductions can be connected !!

n-of 10 turtles    - randomly choose 10 of the turtles.
n-of 10 turtles with [xcor > 0]   - randomly choose 10 of the turtles from the right of the origin.

let can be used with agentsets!

to go
  let them n-of 10 turtles
  ask them [ set size 2]
  ask patches [ set pcolor random 10]
  ask them [ if pcolor = 5 [die] ]   ;them is the SAME set of 10 turtles. end

These are commands that give you an agent set of turtles, they are used with other commands like ask or count:
turtles  is the agent set of all turtles. 
turtles-here   is the agent set of all turtles on the same patch as the agent using the command (including itself)

Test if there is at least one agent:
any? AGENTSET  -  report true when the agentset isn't empty.

if any? turtles with [color = red] 
    ;you must make sure at least one exists first!
    ask one-of turtles with [color = red] 

Agentsets without including the asking agent:
other - remove yourself from the agentset, when a turtle asks other turtles, it won't include itself!

ask one-of turtles[
    ask other turtles[
        die  ; this won't kill the turtle that runs this command.

Get all the turtles on the patch!
turtles-here   - (turtle OR patch context) the agentset of all turtles on the same patch.

if any? other turtles-here[
    ;do stuff

ask turtles[
  ask other turtles-here[

Advanced filters (we will discuss later dont worry for now)

Konstantinovich Samuel,
Oct 30, 2017, 6:25 AM