| ModelSimulator | R Documentation |
R6 class for running individual model simulations via a
simulation function, storing results, and generating success/error statuses.
poems::GenericClass -> ModelSimulator
attachedA list of dynamically attached attributes (name-value pairs).
simulation_modelA SimulationModel object or an inherited class object.
simulation_functionName (character string) or direct assignment (assigned or loaded via source path) of the simulation function, which takes a SimulationModel (or inherited class) as an input and returns the simulation results.
sample_idAn identifier for the simulation sample.
resultsA list of result structures.
new()Initialization method sets the population model, and optionally the simulation function, the sample ID, and any attached attributes listed individually.
ModelSimulator$new( simulation_model = NULL, simulation_function = NULL, sample_id = NULL, ... )
simulation_modelA SimulationModel (or inherited class) object (can be set later).
simulation_functionOptional name (character string) or direct assignment (assigned or loaded via source path) of the simulation function, which takes a SimulationModel (or inherited class) as an input and returns the simulation results.
sample_idOptional identifier for the simulation sample.
...Additional parameters passed individually are attached.
new_clone()Creates a new (re-initialized) object of the current (inherited) object class with optionally passed parameters.
ModelSimulator$new_clone(...)
...Parameters passed via the inherited class constructor (defined in initialize and run via new).
New object of the current (inherited) class.
get_attribute()Returns selected named simulator or attached attribute.
ModelSimulator$get_attribute(param)
paramName of the parameter/attribute.
Selected parameter/attribute value.
run()Runs a model simulator (function), stores the results, and creates a status log entry as a list.
ModelSimulator$run()
A list representing a simulation log entry with a successful boolean and a status message template (with a placeholder for the sample identifier).
clone()The objects of this class are cloneable with this method.
ModelSimulator$clone(deep = FALSE)
deepWhether to make a deep clone.
# Simulation model
model1 <- SimulationModel$new(
time_steps = 10,
model_attributes = c("time_steps", "a", "b"),
params = list(a = 1:7)
)
model1$required_attributes <- model1$model_attributes
# Simulation function
test_simulator <- function(model) {
sum(unlist(model$get_attributes(model$required_attributes)))
}
# Model simulator
simulator1 <- ModelSimulator$new(
simulation_model = model1,
simulation_function = test_simulator
)
simulator1$run()
model1$set_attributes(a = 1:10, b = 15)
model1$get_attributes(model1$required_attributes)
simulator1$run()
simulator1$results
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.