# AgentSet

Subclass of AgentArray, used for Model Patches, Turtles, Links & Breeds.

AgentSets are AgentArrays that are factories for their own Agents.

Thus the Turtles AgentSet is a factory for class Turtle instances using the create() or addAgent() factory methods.

AgentSets are not created directly by modelers, only other AgentSet subclasses: Patches, Turtles, Links & Breeds.

## Constructor

#### # new AgentSet(model, AgentClass, name, baseSetopt)

Create an empty AgentSet and initialize the `ID` counter for add(). If baseSet is supplied, the new agentset is a "breed" of baseSet

Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`model` | Model |  |  | Instance of Class Model to which I belong
`AgentClass` | Patch | Turtle | Link |  |  | Class of items stored in this AgentSet
`name` | String |  |  | Name of this AgentSet. Ex: Patches
`baseSet` | Patches | Turtles | Links | <optional> | null | If a Breed, it's parent AgentSet

Source:
  - AgentSet.js, line 14

### Methods

#### # addAgent(o) → {Object}

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

Parameters:

Name | Type | Description
--- | --- | ---
`o` | Object | An Agent to be added to this AgentSet

Source:
  - AgentSet.js, line 157

Returns:

The input Agent, bound to this AgentSet.

Type
  Object

#### # 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:

Name | Type | Description
--- | --- | ---
`fcn` | function | fcn(agent, index?, array?)

Source:
  - AgentSet.js, line 267

#### # askSet(fcn)

A much stronger version of ask(fcn) with stronger mutability guards.

Parameters:

Name | Type | Description
--- | --- | ---
`fcn` | function | fcn(agent, index?, array?)

Source:
  - AgentSet.js, line 281

#### # clear()

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

Source:
  - AgentSet.js, line 173

#### # getDefault(name) → {any}

Return a default, shared value

Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the default

Source:
  - AgentSet.js, line 211

Returns:

The default value

Type
  any

#### # isBaseSet() → {boolean}

Source:
  - AgentSet.js, line 129

Returns:

true if I am a Patches, Turtles or Links AgentSet

Type
  boolean

#### # isBreedSet() → {boolean}

Source:
  - AgentSet.js, line 123

Returns:

true if I am a baseSet subarray

Type
  boolean

#### # newBreed(name) → {AgentSet}

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

`people = turtles.newBreed('people')`

Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the new breed AgentSet

Source:
  - AgentSet.js, line 116

Returns:

A subarray of me

Type
  AgentSet

#### # 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:

Name | Type | Description
--- | --- | ---
`agentProto` | Object | A new instance of the Agent being added
`AgentClass` | Patch | Turtle | Link | It's Class

Source:
  - AgentSet.js, line 77

#### # removeAgent(o) → {AgentSet}

Remove an Agent from this AgentSet

Parameters:

Name | Type | Description
--- | --- | ---
`o` | Object | The Agent to be removed

Source:
  - AgentSet.js, line 183

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:

Name | Type | Description
--- | --- | ---
`a` | Agent | An agent, a member of another AgentSet

Source:
  - AgentSet.js, line 236

Returns:

The updated agent

Type
  Agent

#### # setDefault(name, value) → {AgentSet}

Set a default value shared by all Agents in this AgentSet

Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the shared value
`value` | any |

Source:
  - AgentSet.js, line 201

Returns:

This AgentSet

Type
  AgentSet

#### # withBreed(breed) → {AgentArray}

Return breeds in a subset of an AgentSet

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

Parameters:

Name | Type | Description
--- | --- | ---
`breed` | AgentSet | A breed AgentSet

Source:
  - AgentSet.js, line 141

Returns:

Type
  AgentArray