agent_manager {villager}R Documentation

agent Manager

Description

A class that abstracts the management of aggregations of agent classes. Each village should have an instance of a agent_manager to interface the agents inside.

Methods

add_agent()

Adds a single agent to the manager.

get_average_age()

Returns the average age, in years, of all the agents.

get_living_agents()

Gets a list of all the agents that are currently alive.

get_states()

Returns a data.frame consisting of all of the managed agents.

get_agent()

Retrieves a particular agent from the manager.

get_agent_index()

Retrieves the index of a agent.

initialize()

Creates a new manager instance.

load()

Loads a csv file defining a population of agents and places them in the manager.

remove_agent()

Removes a agent from the manager

Creates a new agent manager instance.

Public fields

agents

A list of agents objects that the agent manager manages.

agent_class

A class describing agents. This is usually the default villager supplied 'agent' class

Methods

Public methods


Method new()

Usage
agent_manager$new(agent_class = villager::agent)
Arguments
agent_class

The class that's being used to represent agents being managed Given the identifier of a agent, sort through all of the managed agents and return it if it exists.


Method get_agent()

Return the R6 instance of a agent with identifier 'agent_identifier'.

Usage
agent_manager$get_agent(agent_identifier)
Arguments
agent_identifier

The identifier of the requested agent.

Returns

An R6 agent object Returns a list of all the agents that are currently alive.


Method get_living_agents()

Usage
agent_manager$get_living_agents()
Returns

A list of living agents Adds a agent to the manager.


Method add_agent()

Usage
agent_manager$add_agent(...)
Arguments
...

One or more agents

Returns

None Removes a agent from the manager


Method remove_agent()

Usage
agent_manager$remove_agent(agent_identifier)
Arguments
agent_identifier

The identifier of the agent being removed

Returns

None Returns a data.frame of agents


Method get_states()

Usage
agent_manager$get_states()
Details

Each row of the data.frame represents a agent object

Returns

A single data.frame of all agents Returns the index of a agent in the internal agent list


Method get_agent_index()

Usage
agent_manager$get_agent_index(agent_identifier)
Arguments
agent_identifier

The identifier of the agent being located

Returns

The index in the list, or R's default return value Connects two agents together as mates


Method connect_agents()

Usage
agent_manager$connect_agents(agent_a, agent_b)
Arguments
agent_a

A agent that will be connected to agent_b

agent_b

A agent that will be connected to agent_a Returns the total number of agents that are alive


Method get_living_population()

Usage
agent_manager$get_living_population()
Returns

The number of living agents Returns the average age, in years, of all of the agents


Method get_average_age()

Usage
agent_manager$get_average_age()
Details

This is an example of the kind of logic that the manager might handle. In this case, the manager is performing calculations about its aggregation (agents). Note that the 364 days needs to work better

Returns

The average age in years Takes all of the agents in the manager and reconstructs the children


Method add_children()

Usage
agent_manager$add_children()
Details

This is typically called when loading agents from disk for the first time. When children are created during the simulation, the family connections are made through the agent class and added to the manager via add_agent.

Returns

None Loads agents from disk.


Method load()

Usage
agent_manager$load(file_name)
Arguments
file_name

The location of the file holding the agents.

Details

Populates the agent manager with a set of agents defined in a csv file.

Returns

None


Method clone()

The objects of this class are cloneable with this method.

Usage
agent_manager$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


[Package villager version 2.0.0 Index]