Skip to contents

Create an agent first (through create_agent). This agent can be seen as a blueprint. Then, use this function here to add as many replicates of this blueprint agent as necessary. They will be added independently so that they do not interfere with each other throughout runtime.

Usage

add_agents(.tidyabm, agent, n, ...)

# S3 method for tidyabm_env
add_agents(.tidyabm, agent, n, ...)

# S3 method for tidyabm_env_grid
add_agents(.tidyabm, agent, n, initial_position = NULL, ...)

# S3 method for tidyabm_env_network
add_agents(.tidyabm, agent, n, ...)

Arguments

.tidyabm

the tidyabm_env object to which agents should be added

agent

an tidyabm_agent object (the blueprint) to replicate from

n

number of agents in the style of agent to add

...

other arguments to pass to sub functions

initial_position

either NULL (the default) where agents are placed randomly and independent from each other or a function with two parameters me (the agent to be placed) and abm (the current environment with previous agents already placed) that gets called once per agent to place and which has to return a vector of length 2 that will be interpreted as x and y coordinates (i.e., c(x, y)). Here is an example to position agents in subsequent order via a function: coordinate_counter <- c(0, 1) create_grid_environment(seed = 892, size = 3) %>% add_agents(create_agent(), n = 3, initial_position = \(me, abm) coordinate_counter[1] <- coordinate_counter[1] + 1 if (coordinate_counter[1] > 3) coordinate_counter[1] <- 1 coordinate_counter[2] <- coordiante_counter[2] + 1return(coordinate_counter) )

Value

tidyabm object

Examples

a1 <- create_agent() %>%
  set_characteristic(age = 'young')
a2 <- create_agent() %>%
  set_characteristic(age = 'old')
m <- create_grid_environment(seed = 1024, size = 50) %>%
  add_agents(a1, 100) %>%
  add_agents(a2, 100)