AgentSet

A model's Patches, Turtles, Links, are all subclasses of AgentSet.

AgentSets are AgentArrays that are factories for their own Agents. That means you do not call new Turtle(), rather Turtles will create the Turtle instances, adding them to itself.

Finally, a Breed is simply a subarray of Patches, Turtles, Links. Patches could have a Streets breed, Turtles could have Cops and Robbers breeds, and Links Spokes and Rim breeds

AgentSets are not created directly by modelers. Instead, class Model creates them along with their Breeds. You can easily skip this initially, instead simply understand AgentSets are the basis for Patches, Turtles, Links & Breeds

Constructor

new AgentSet(model, AgentClass, name, baseSetopt)

Parameters:
NameTypeAttributesDefaultDescription
modelModel

Instance of Class Model to which I belong

AgentClassPatch | Turtle | Link

Class of items stored in this AgentSet

nameString

Name of this AgentSet. Ex: Patches

baseSetPatches | Turtles | Links<optional>
null

If a Breed, it's parent AgentSet

Methods

protoMixin(agentProto, AgentClass)

Add common variables to an Agent being added to this AgentSet.

Each Agent has it's AgentSet and the Model instance. It also has an id, set by the AgentSet's global ID.

The Agent also has three methods added: setBreed, getBreed, isBreed.

Parameters:
NameTypeDescription
agentProtoObject

A new instance of the Agent being added

AgentClassPatch | Turtle | Link

It's Class

addAgent(o) → {Object}

Add an Agent to this AgentSet. Only used by factory methods. Adds the id property to Agent. Increment AgentSet ID.

Parameters:
NameTypeDescription
oObject

An Agent to be added to this AgentSet

Returns:

The input Agent, bound to this AgentSet.

Type: 
Object

removeAgent(o) → {AgentSet}

Remove an Agent from this AgentSet

Parameters:
NameTypeDescription
oObject

The Agent to be removed

Returns:

This AgentSet with the Agent removed

Type: 
AgentSet

setBreed(a) → {Agent}

Move an agent from its AgentSet/breed to be in this AgentSet/breed

Parameters:
NameTypeDescription
aAgent

An agent, a member of another AgentSet

Returns:

The updated agent

Type: 
Agent

setDefault(name, value) → {AgentSet}

Set a default value shared by all Agents in this AgentSet

Parameters:
NameTypeDescription
nameString

The name of the shared value

valueany
Returns:

This AgentSet

Type: 
AgentSet

getDefault(name) → {any}

Return a default, shared value

Parameters:
NameTypeDescription
nameString

The name of the default

Returns:

The default value

Type: 
any

newBreed(name) → {AgentSet}

Create a subarray of this AgentSet. Example: create a people breed of Turtles:

people = turtles.newBreed('people')

Parameters:
NameTypeDescription
nameString

The name of the new breed AgentSet

Returns:

A subarray of me

Type: 
AgentSet

isBreedSet() → {boolean}

Returns:

true if I am a baseSet subarray

Type: 
boolean

isBaseSet() → {boolean}

Returns:

true if I am a Patches, Turtles or Links AgentSet

Type: 
boolean

withBreed(breed) → {AgentArray}

Return breeds in a subset of an AgentSet

Ex: patches.inRect(5).withBreed(houses)

Parameters:
NameTypeDescription
breedAgentSet

A breed AgentSet

Returns:
Type: 
AgentArray

clear()

Remove all Agents from this AgentSet using agent.die() for each agent.

ask(fcn)

Call fcn(agent, index, array) for each item in AgentArray. Index & array optional. Overrides AgentArray's ask with additional guards for modifications in AgentSet's array.

Parameters:
NameTypeDescription
fcnfunction

fcn(agent, index?, array?)