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

identifier

A unique identifier that can be used to identify and find the agent

first_name

The agent's first name

last_name

The agent's last name

age

The agent's age

mother_id

The identifier of the agent's mother

father_id

The identifier of the agent's father

profession

The agent's profession

partner

The identifier of the agent's partner

gender

The agent's gender

alive

A boolean flag that represents whether the villager is alive or dead

children

A list of children identifiers

health

A 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
identifier

The agent's identifier

first_name

The agent's first name

last_name

The agent's last name

age

The age of the agent

mother_id

The identifier of the agent's mother

father_id

The identifier of the agent' father

partner

The identifier of the agent's partner

children

An ordered list of of the children from this agent

gender

The gender of the agent

profession

The agent's profession

alive

Boolean whether the agent is alive or not

health

A 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
child

The 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
deep

Whether to make a deep clone.


[Package villager version 2.0.0 Index]