Constructor
new AgentSet(model, AgentClass, name, baseSetopt)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
model | Model | Instance of Class Model to which I belong | ||
AgentClass | Patch | | Class of items stored in this AgentSet | ||
name | String | Name of this AgentSet. Ex: Patches | ||
baseSet | Patches | | <optional> | null | If a Breed, it's parent AgentSet |
- Source
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.
Name | Type | Description |
---|---|---|
agentProto | Object | A new instance of the Agent being added |
AgentClass | Patch | | It's Class |
- Source
addAgent(o) → {Object}
Add an Agent to this AgentSet. Only used by factory methods. Adds the id
property to Agent. Increment AgentSet ID
.
Name | Type | Description |
---|---|---|
o | Object | An Agent to be added to this AgentSet |
- Source
The input Agent, bound to this AgentSet.
- Type:
- Object
removeAgent(o) → {AgentSet}
Remove an Agent from this AgentSet
Name | Type | Description |
---|---|---|
o | Object | The Agent to be removed |
- Source
This AgentSet with the Agent removed
- Type:
- AgentSet
setBreed(a) → {Agent}
Move an agent from its AgentSet/breed to be in this AgentSet/breed
Name | Type | Description |
---|---|---|
a | Agent | An agent, a member of another AgentSet |
- Source
The updated agent
- Type:
- Agent
setDefault(name, value) → {AgentSet}
Set a default value shared by all Agents in this AgentSet
Name | Type | Description |
---|---|---|
name | String | The name of the shared value |
value | any |
- Source
This AgentSet
- Type:
- AgentSet
getDefault(name) → {any}
Return a default, shared value
Name | Type | Description |
---|---|---|
name | String | The name of the default |
- Source
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')
Name | Type | Description |
---|---|---|
name | String | The name of the new breed AgentSet |
- Source
A subarray of me
- Type:
- AgentSet
isBreedSet() → {boolean}
- Source
true if I am a baseSet subarray
- Type:
- boolean
isBaseSet() → {boolean}
- Source
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)
Name | Type | Description |
---|---|---|
breed | AgentSet | A breed AgentSet |
- Source
- Type:
- AgentArray
clear()
Remove all Agents from this AgentSet using agent.die() for each agent.
- Source
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.
Name | Type | Description |
---|---|---|
fcn | function | fcn(agent, index?, array?) |
- Source