# Class: Agent

## (private) Agent()

#### (private) new Agent()

The main class representing individual agents, using Leaflet class system.

Source:
  - agents.js, line 16

### Methods

#### (private, static) checkArrival(sub_goal_lat_lng, leftover_after_goal)

Check if the agent has arrived at the next goal in its path or to a sub_goal along the way and perform appropriate arrival operations.

##### Parameters:

Name | Type | Description
--- | --- | ---
`sub_goal_lat_lng` | LatLng | A sub_goal on the way to the goal (possibly the goal itself).
`leftover_after_goal` | number | If the agent arrives at its goal during the tick, the number of meters, according to its speed, leftover beyond the goal that it should still move during the tick.

Source:
  - agents.js, line 600

#### (static) checkSpeed(speed)

Check whether a given speed is greater than the minimum.

##### Parameters:

Name | Type | Description
--- | --- | ---
`speed` | number | A number representing the speed of an agent in meters per second.

Source:
  - agents.js, line 484

#### (static) increaseSpeed(magnitude)

Increase the speed the agent moves along its currently scheduled path by a constant.

##### Parameters:

Name | Type | Description
--- | --- | ---
`magnitude` | number | The number to add to the agent's scheduled speed. All scheduled speeds must be >= .1

Source:
  - agents.js, line 465

#### (static) moveIt()

Make the agent proceed along its trip.

Source:
  - agents.js, line 635

#### (static) multiplySpeed(multiplier)

Multiply the speed the agent moves along its currently scheduled path by a constant.

##### Parameters:

Name | Type | Description
--- | --- | ---
`multiplier` | number | The number to multiply the agent's scheduled speed by. All scheduled speeds must be >= .1.

Source:
  - agents.js, line 445

#### (private, static) newTripStartPlace() → {Place}

Given the agent's currently scheduledthis.trips (its path), get the place from which a newthis.trip should start (namely, the end of the current path). That is: If there's already a path in queue, start the new path from the end of the existing one.

Source:
  - agents.js, line 151

##### Returns:

- The place where a newthis.trip should start.

Type
  Place

#### (static) pauseTrip()

Stop the agent where it is along its trip.

Source:
  - agents.js, line 103

#### (static) resetTrip()

Reset all the properties of its trip, but don't change whether it's allowed to be traveling or not.

Source:
  - agents.js, line 77

#### (static) resumeTrip()

Have the agent continue from where it was left off along its trip.

Source:
  - agents.js, line 112

#### (static) setSpeed(speed)

Set a new, constant speed for the agent to move along its currently scheduled path.

##### Parameters:

Name | Type | Description
--- | --- | ---
`speed` | number | The speed (in meters per tick) that the agent should move. Must be >= .1.

Source:
  - agents.js, line 424

#### (private, static) setTravelAlongStreet(goal_lat_lng, goal_place, speed)

Schedule the agent to travel to a point along the streets, via streets.

##### Parameters:

Name | Type | Description
--- | --- | ---
`goal_lat_lng` | LatLng | The coordinates of a point on a street to which the agent should travel.
`goal_place` | Place | The place to which the agent will travel. Must be a street.
`speed` | number | The speed that the agent should travel, in meters per tick.

Source:
  - agents.js, line 280

#### (private, static) setTravelInUnit(goal_lat_lng, speed)

Schedule the agent to travel to a point within the unit he is in.

##### Parameters:

Name | Type | Description
--- | --- | ---
`goal_lat_lng` | LatLng | LatLng coordinate object for a point in the same unit the agent is in.
`speed` | number | The speed that the agent should travel, in meters per tick.

Source:
  - agents.js, line 171

#### (private, static) setTravelOnSameStreet(start_lat_lng, goal_lat_lng, street_feature, street_id, speed)

Schedule the agent to travel between two points on the same street.

##### Parameters:

Name | Type | Description
--- | --- | ---
`start_lat_lng` | LatLng | The coordinates of the point on the street from which the agent will be traveling.
`goal_lat_lng` | LatLng | The coordinates of the point on the street to which the agent should travel.
`street_feature` | Feature | A GeoJSON object representing an OpenStreetMap street.
`street_id` | number | The ID of the street in the streets layerGroup.
`speed` | number | The speed that the agent should travel, in meters per tick.

Source:
  - agents.js, line 334

#### (private, static) setTravelOnStreetNetwork(start_lat_lng, goal_lat_lng, start_int_lat_lng, goal_int_lat_lng, speed)

Schedule the agent up to travel between two points on a street network.

##### Parameters:

Name | Type | Description
--- | --- | ---
`start_lat_lng` | LatLng | The coordinates of the point on the street from which the agent will be traveling.
`goal_lat_lng` | LatLng | The coordinates of the point on the street to which the agent should travel.
`start_int_lat_lng` | LatLng | The coordinates of the nearest intersection on the same street at the start_lat_lng.
`goal_int_lat_lng` | LatLng | The coordinates of the nearest intersection on the same street as the goal_lat_lng.
`speed` | number | The speed that the agent should travel, in meters per tick.

Source:
  - agents.js, line 406

#### (static) setTravelToPlace(goal_lat_lng, goal_place, speedopt, move_directlyopt, replace_tripopt)

Schedule the agent to travel directly from any point (e.g. of a street or unit) to a point (e.g. of another street or unit).

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`goal_lat_lng` | LatLng |  |  | The point within the place to which the agent is to travel.
`goal_place` | Place |  |  | The place to which the agent will travel.
`speed` | number | <optional> | 1 | The speed in meters per tick that the agent should try to travel. Must be >= .1.
`move_directly` | Boolean | <optional> | false | Whether to ignore the streets & roads and move directly to the goal.
`replace_trip` | Boolean | <optional> | false | Whether to empty the currently scheduled path and replace it with this new trip; false by default (the new trip is simply appended to the current scheduled path).

Source:
  - agents.js, line 189

#### (static) startTrip()

Set the agent up to start traveling along the path specified in the agent's trip..

Source:
  - agents.js, line 92

#### (private, static) step(lat_step_value, lng_step_value)

Move the agent a given latitude and longitude.

##### Parameters:

Name | Type | Description
--- | --- | ---
`lat_step_value` | number | The number to add to the agent's latitude.
`lng_step_value` | number | The number to add to the agent's longitude.

Source:
  - agents.js, line 575

#### (private, static) travel(override_speed)

Continue to move the agent directly along the points in its path, at approximately the speed associated with each point in the path. Since two points along the path may be far apart, the agent will make multiple intermediary movements too, splitting up its transfer from its current point to its goal point into a sub-path with multiple sub-goals.

##### Parameters:

Name | Type | Description
--- | --- | ---
`override_speed` | number | Have the agent step this distance, instead of the distance suggested by the current state's speed property.

Source:
  - agents.js, line 500

#### (private, static) travelTo(goal_point)

Set the agent to travel to some point on the map.

##### Parameters:

Name | Type | Description
--- | --- | ---
`goal_point` | LatLng | The point to which the agent should travel.

Source:
  - agents.js, line 124

## Agent(lat_lng, options, agentmap)

#### new Agent(lat_lng, options, agentmap)

Constructor for the Agent class, using Leaflet class system.

##### Parameters:

Name | Type | Description
--- | --- | ---
`lat_lng` | LatLng | A pair of coordinates to place the agent at.
`options` | Object | An array of options for the agent, namely its layer.
`agentmap` | Agentmap | The agentmap instance in which the agent exists.

##### Properties:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`feature.AgentMap_id` | number |  |  | The agent's instance id, so it can be accessed from inside the Leaflet layer. To avoid putting the actual instance inside the feature object.
`agentmap` | Agentmap |  |  | The agentmap instance in which the agent exists.
`place` | Place |  |  | A place object specifying where the agent is currently at.
`steps_made` | number | <optional> | 0 | The number of steps the agent has moved since the beginning.

`this.trip`

Object

Properties detailing information about the agent's trip that change sometimes, but needs to be accessed by future updates.

###### Properties

Name | Type | Attributes | Description
--- | --- | --- | ---
`moving` | boolean |  | Whether the agent currently moving.
`paused` | boolean |  | Whether the agent should be allowed to move along its trip.
`current_point` | Point | <nullable> | The point where the agent is currently located.
`goal_point` | Point | <nullable> | The point where the agent is traveling to.
`lat_dir` | number | <nullable> | The latitudinal direction. -1 if traveling to lower latitude (down), 1 if traveling to higher latitude (up).
`lng_dir` | number | <nullable> | The longitudinal direction. -1 if traveling to lesser longitude (left), 1 if traveling to greater longitude (right).
`speed` | number | <nullable> | The speed that the agent should travel, in meters per tick.
`angle` | number | <nullable> | The angle between the current point and the goal.
`slope` | number | <nullable> | The slope of the line segment formed by the two points between which the agent is traveling at this time during its trip.
`path` | Array |  | A sequence of LatLngs; the agent will move from one to the next, popping each one off after it arrives until the end of the street; or, until the trip is changed/reset.

`controller` | function | <nullable> |  | User-defined function to be called on each update (each tick).
`fine_controller` | function | <nullable> |  | User-defined function to be called before & after each movemnt (on each step an agent performs during a tick).

Source:
  - agents.js, line 24

### Methods

#### (private, static) checkArrival(sub_goal_lat_lng, leftover_after_goal)

Check if the agent has arrived at the next goal in its path or to a sub_goal along the way and perform appropriate arrival operations.

##### Parameters:

Name | Type | Description
--- | --- | ---
`sub_goal_lat_lng` | LatLng | A sub_goal on the way to the goal (possibly the goal itself).
`leftover_after_goal` | number | If the agent arrives at its goal during the tick, the number of meters, according to its speed, leftover beyond the goal that it should still move during the tick.

Source:
  - agents.js, line 600

#### (static) checkSpeed(speed)

Check whether a given speed is greater than the minimum.

##### Parameters:

Name | Type | Description
--- | --- | ---
`speed` | number | A number representing the speed of an agent in meters per second.

Source:
  - agents.js, line 484

#### (static) increaseSpeed(magnitude)

Increase the speed the agent moves along its currently scheduled path by a constant.

##### Parameters:

Name | Type | Description
--- | --- | ---
`magnitude` | number | The number to add to the agent's scheduled speed. All scheduled speeds must be >= .1

Source:
  - agents.js, line 465

#### (static) moveIt()

Make the agent proceed along its trip.

Source:
  - agents.js, line 635

#### (static) multiplySpeed(multiplier)

Multiply the speed the agent moves along its currently scheduled path by a constant.

##### Parameters:

Name | Type | Description
--- | --- | ---
`multiplier` | number | The number to multiply the agent's scheduled speed by. All scheduled speeds must be >= .1.

Source:
  - agents.js, line 445

#### (private, static) newTripStartPlace() → {Place}

Given the agent's currently scheduledthis.trips (its path), get the place from which a newthis.trip should start (namely, the end of the current path). That is: If there's already a path in queue, start the new path from the end of the existing one.

Source:
  - agents.js, line 151

##### Returns:

- The place where a newthis.trip should start.

Type
  Place

#### (static) pauseTrip()

Stop the agent where it is along its trip.

Source:
  - agents.js, line 103

#### (static) resetTrip()

Reset all the properties of its trip, but don't change whether it's allowed to be traveling or not.

Source:
  - agents.js, line 77

#### (static) resumeTrip()

Have the agent continue from where it was left off along its trip.

Source:
  - agents.js, line 112

#### (static) setSpeed(speed)

Set a new, constant speed for the agent to move along its currently scheduled path.

##### Parameters:

Name | Type | Description
--- | --- | ---
`speed` | number | The speed (in meters per tick) that the agent should move. Must be >= .1.

Source:
  - agents.js, line 424

#### (private, static) setTravelAlongStreet(goal_lat_lng, goal_place, speed)

Schedule the agent to travel to a point along the streets, via streets.

##### Parameters:

Name | Type | Description
--- | --- | ---
`goal_lat_lng` | LatLng | The coordinates of a point on a street to which the agent should travel.
`goal_place` | Place | The place to which the agent will travel. Must be a street.
`speed` | number | The speed that the agent should travel, in meters per tick.

Source:
  - agents.js, line 280

#### (private, static) setTravelInUnit(goal_lat_lng, speed)

Schedule the agent to travel to a point within the unit he is in.

##### Parameters:

Name | Type | Description
--- | --- | ---
`goal_lat_lng` | LatLng | LatLng coordinate object for a point in the same unit the agent is in.
`speed` | number | The speed that the agent should travel, in meters per tick.

Source:
  - agents.js, line 171

#### (private, static) setTravelOnSameStreet(start_lat_lng, goal_lat_lng, street_feature, street_id, speed)

Schedule the agent to travel between two points on the same street.

##### Parameters:

Name | Type | Description
--- | --- | ---
`start_lat_lng` | LatLng | The coordinates of the point on the street from which the agent will be traveling.
`goal_lat_lng` | LatLng | The coordinates of the point on the street to which the agent should travel.
`street_feature` | Feature | A GeoJSON object representing an OpenStreetMap street.
`street_id` | number | The ID of the street in the streets layerGroup.
`speed` | number | The speed that the agent should travel, in meters per tick.

Source:
  - agents.js, line 334

#### (private, static) setTravelOnStreetNetwork(start_lat_lng, goal_lat_lng, start_int_lat_lng, goal_int_lat_lng, speed)

Schedule the agent up to travel between two points on a street network.

##### Parameters:

Name | Type | Description
--- | --- | ---
`start_lat_lng` | LatLng | The coordinates of the point on the street from which the agent will be traveling.
`goal_lat_lng` | LatLng | The coordinates of the point on the street to which the agent should travel.
`start_int_lat_lng` | LatLng | The coordinates of the nearest intersection on the same street at the start_lat_lng.
`goal_int_lat_lng` | LatLng | The coordinates of the nearest intersection on the same street as the goal_lat_lng.
`speed` | number | The speed that the agent should travel, in meters per tick.

Source:
  - agents.js, line 406

#### (static) setTravelToPlace(goal_lat_lng, goal_place, speedopt, move_directlyopt, replace_tripopt)

Schedule the agent to travel directly from any point (e.g. of a street or unit) to a point (e.g. of another street or unit).

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`goal_lat_lng` | LatLng |  |  | The point within the place to which the agent is to travel.
`goal_place` | Place |  |  | The place to which the agent will travel.
`speed` | number | <optional> | 1 | The speed in meters per tick that the agent should try to travel. Must be >= .1.
`move_directly` | Boolean | <optional> | false | Whether to ignore the streets & roads and move directly to the goal.
`replace_trip` | Boolean | <optional> | false | Whether to empty the currently scheduled path and replace it with this new trip; false by default (the new trip is simply appended to the current scheduled path).

Source:
  - agents.js, line 189

#### (static) startTrip()

Set the agent up to start traveling along the path specified in the agent's trip..

Source:
  - agents.js, line 92

#### (private, static) step(lat_step_value, lng_step_value)

Move the agent a given latitude and longitude.

##### Parameters:

Name | Type | Description
--- | --- | ---
`lat_step_value` | number | The number to add to the agent's latitude.
`lng_step_value` | number | The number to add to the agent's longitude.

Source:
  - agents.js, line 575

#### (private, static) travel(override_speed)

Continue to move the agent directly along the points in its path, at approximately the speed associated with each point in the path. Since two points along the path may be far apart, the agent will make multiple intermediary movements too, splitting up its transfer from its current point to its goal point into a sub-path with multiple sub-goals.

##### Parameters:

Name | Type | Description
--- | --- | ---
`override_speed` | number | Have the agent step this distance, instead of the distance suggested by the current state's speed property.

Source:
  - agents.js, line 500

#### (private, static) travelTo(goal_point)

Set the agent to travel to some point on the map.

##### Parameters:

Name | Type | Description
--- | --- | ---
`goal_point` | LatLng | The point to which the agent should travel.

Source:
  - agents.js, line 124