| agent {villager} | R Documentation |
agent
Description
This is an object that represents a villager (agent).
Details
This class acts as an abstraction for handling villager-level logic. It can take a number of functions that run at each timestep. It also has an associated
Methods
as_table()Represents the current state of the agent as a tibble
get_age()Returns age in terms of years
get_gender()get_days_sincelast_birth()Get the number of days since the agent last gave birth
initialize()Create a new agent
propagate()Runs every day
Create a new agent
Public fields
identifierA unique identifier that can be used to identify and find the agent
first_nameThe agent's first name
last_nameThe agent's last name
ageThe agent's age
mother_idThe identifier of the agent's mother
father_idThe identifier of the agent's father
professionThe agent's profession
partnerThe identifier of the agent's partner
genderThe agent's gender
aliveA boolean flag that represents whether the villager is alive or dead
childrenA list of children identifiers
healthA percentage value of the agent's current health
Methods
Public methods
Method new()
Used to created new agent objects.
Usage
agent$new( identifier = NA, first_name = NA, last_name = NA, age = 0, mother_id = NA, father_id = NA, partner = NA, children = vector(mode = "character"), gender = NA, profession = NA, alive = TRUE, health = 100 )
Arguments
identifierThe agent's identifier
first_nameThe agent's first name
last_nameThe agent's last name
ageThe age of the agent
mother_idThe identifier of the agent's mother
father_idThe identifier of the agent' father
partnerThe identifier of the agent's partner
childrenAn ordered list of of the children from this agent
genderThe gender of the agent
professionThe agent's profession
aliveBoolean whether the agent is alive or not
healthA percentage value of the agent's current health
Returns
A new agent object A function that returns true or false whether the villager dies This is run each day
Method is_alive()
Usage
agent$is_alive()
Returns
A boolean whether the agent is alive (true for yes) Gets the number of days from the last birth. This is also the age of the most recently born agent
Method get_days_since_last_birth()
Usage
agent$get_days_since_last_birth()
Returns
The number of days since last birth Connects a child to the agent. This method ensures that the 'children' vector is ordered.
Method add_child()
Usage
agent$add_child(child)
Arguments
childThe agent object representing the child
Returns
None Returns a data.frame representation of the agent
Method as_table()
I hope there's a more scalable way to do this in R; Adding every new attribute to this function isn't practical
Usage
agent$as_table()
Details
The village_state holds a copy of all of the villagers at each timestep; this method is used to turn the agent properties into the object inserted in the village_state.
Returns
A data.frame representation of the agent
Method clone()
The objects of this class are cloneable with this method.
Usage
agent$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.