RESPOND 2.5.1
Researching Effective Strategies to Prevent Opioid Death
Loading...
Searching...
No Matches
respond::Simulation Class Reference

Manages and executes multiple models in a coordinated simulation. A Simulation aggregates Model instances and coordinates their execution, maintaining history records and providing access to simulation results.

#include <simulation.hpp>

Classes

class  ModelSlotProxy
 Proxy for mutable model slot access with clone-based assignment. More...
 

Public Member Functions

 Simulation ()
 Default constructor for a Simulation instance. Initializes the simulation with the default logger.
 
 Simulation (const std::string &log_name)
 Constructs a Simulation with a specified logger.
 
 Simulation (const std::string &log_name, const std::string &log_filepath)
 Constructs a Simulation with a specified logger and log file.
 
 ~Simulation ()=default
 Virtual destructor for polymorphic cleanup.
 
 Simulation (const Simulation &other)
 Copy constructor creating an independent deep copy of the simulation. All models are cloned; modifications to the copy do not affect the original.
 
Simulationoperator= (const Simulation &other)
 Copy assignment operator for deep copying simulation state.
 
 Simulation (Simulation &&other) noexcept
 Move constructor for transferring simulation ownership.
 
Simulationoperator= (Simulation &&other) noexcept
 Move assignment operator for transferring simulation ownership.
 
std::unique_ptr< ModelCreateNewModel (const std::string &model_name)
 Creates a new model instance and adds it to the simulation.
 
void ClearModels ()
 Removes all models from the simulation.
 
void AddModel (const std::unique_ptr< Model > &model)
 Adds a model to the simulation. The model is cloned and managed by the simulation.
 
void Run (int duration=-1)
 Executes one step of the simulation for all models. Calls RunTransitions() on each registered model in sequence.
 
std::vector< std::unique_ptr< Model > > GetModels () const
 Retrieves all models in the simulation.
 
ModelSlotProxy operator[] (size_t idx)
 Mutable index-based model access.
 
const Modeloperator[] (size_t idx) const
 Const index-based model access.
 
std::map< size_t, std::string > GetModelIndexNameMap () const
 Provide a mapping of model indices to their names for all models in the simulation.
 
std::unique_ptr< ModelGetModel (int idx) const
 Retrieves a specific model by index in the simulation.
 
std::vector< std::string > GetModelNames () const
 Retrieves the names of all models in the simulation.
 
const std::map< std::string, History > & GetModelHistory (size_t idx) const
 Retrieves the complete state histories for the model at the index.
 
const std::vector< std::string > GetModelHistoryNames (size_t idx) const
 Retrieves history names for the model at the specified index.
 
void SetDuration (int duration)
 

Constructor & Destructor Documentation

◆ Simulation() [1/4]

respond::Simulation::Simulation ( const std::string &  log_name)
inline
Parameters
log_nameThe name of the logger to use for simulation output.

◆ Simulation() [2/4]

respond::Simulation::Simulation ( const std::string &  log_name,
const std::string &  log_filepath 
)
inline
Parameters
log_nameThe name of the logger to use for simulation output.
log_filepathThe file path for the logger output.

◆ Simulation() [3/4]

respond::Simulation::Simulation ( const Simulation other)
inline
Parameters
otherThe Simulation instance to copy from.

◆ Simulation() [4/4]

respond::Simulation::Simulation ( Simulation &&  other)
inlinenoexcept
Parameters
otherThe simulation to move from.

Member Function Documentation

◆ AddModel()

void respond::Simulation::AddModel ( const std::unique_ptr< Model > &  model)
inline
Parameters
modelA unique_ptr to a Model instance to add.

◆ CreateNewModel()

std::unique_ptr< Model > respond::Simulation::CreateNewModel ( const std::string &  model_name)
inline
Parameters
model_nameThe name identifier for the model to create. This name is used to identify the model type and initialize it accordingly.
Returns
A deep-copied model instance representing the newly created model.

◆ GetModel()

std::unique_ptr< Model > respond::Simulation::GetModel ( int  idx) const
inline
Parameters
idxThe index of the model to retrieve.
Returns
A deep-copied Model at the specified index.

If idx is -1, the last model is returned.

Exceptions
std::out_of_rangeif no models exist or idx is out of range.

◆ GetModelHistory()

const std::map< std::string, History > & respond::Simulation::GetModelHistory ( size_t  idx) const
inline
Parameters
idxThe index of the model to retrieve histories for.
Returns
Map of history names to history records for the selected model.

◆ GetModelHistoryNames()

const std::vector< std::string > respond::Simulation::GetModelHistoryNames ( size_t  idx) const
inline
Parameters
idxThe index of the model to retrieve history names for.
Returns
Vector of history names for the selected model.

◆ GetModelIndexNameMap()

std::map< size_t, std::string > respond::Simulation::GetModelIndexNameMap ( ) const
inline

This method returns a map where the keys are the indices of the models in the simulation, and the values are the corresponding model names. This allows for easy identification of models by their index in the simulation.

Returns
The map of model indices to model names.

◆ GetModelNames()

std::vector< std::string > respond::Simulation::GetModelNames ( ) const
inline
Returns
Vector of model names in the order they were added.

◆ GetModels()

std::vector< std::unique_ptr< Model > > respond::Simulation::GetModels ( ) const
inline
Returns
A deep-copied vector of Model unique_ptrs.

◆ operator=() [1/2]

Simulation & respond::Simulation::operator= ( const Simulation other)
inline
Parameters
otherThe simulation to copy from.
Returns
Reference to this simulation after assignment.

◆ operator=() [2/2]

Simulation & respond::Simulation::operator= ( Simulation &&  other)
inlinenoexcept
Parameters
otherThe simulation to move from.
Returns
Reference to this simulation after assignment.

◆ operator[]() [1/2]

ModelSlotProxy respond::Simulation::operator[] ( size_t  idx)
inline

Returns a proxy that supports both model member access and clone-based replacement assignment.

Parameters
idxThe index of the model to access.
Returns
A mutable proxy for the model slot.
Exceptions
std::out_of_rangeif idx is out of range.

◆ operator[]() [2/2]

const Model & respond::Simulation::operator[] ( size_t  idx) const
inline
Parameters
idxThe index of the model to access.
Returns
Const reference to the model at the index.
Exceptions
std::out_of_rangeif idx is out of range.

The documentation for this class was generated from the following file: