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

Abstract base class representing a state transition model. Models manage a state vector, execute transitions, and maintain history of state changes. Subclasses must implement state management, transition execution, and history tracking.

#include <model.hpp>

Public Member Functions

virtual ~Model ()=default
 Virtual destructor for proper polymorphic cleanup.
 
 Model (const Model &)=delete
 Deleted copy constructor (models are non-copyable by public API).
 
Modeloperator= (const Model &)=delete
 Deleted copy assignment operator (models are non-copyable by public API).
 
virtual std::unique_ptr< Modelclone () const =0
 Creates a deep copy of this model.
 
virtual void AddTimestep (const Timestep &timestep)=0
 Helper function to add a single timestep to the model.
 
virtual void RunTimestep ()=0
 Executes the next timestep in the model's sequence.
 
virtual void RunTimestep (size_t idx)=0
 Executes the timestep in the model's sequence.
 
virtual void RunTimesteps ()=0
 Executes all registered timesteps in sequence, applying their transitions to the model's state.
 
virtual void ClearTimesteps ()=0
 Clears all timesteps from the model.
 
virtual void ClearHistories ()=0
 Clear all history records and reset the history tracking state.
 
virtual void CreateDefaultHistories ()=0
 Creates default history tracking for the model. This method initializes standard history records based on the model's state.
 
virtual Timestep GetTimestepAtIndex (size_t index) const =0
 Retrieve a copy of a specific timestep by index.
 
virtual const Eigen::Ref< const Eigen::VectorXd > GetState () const =0
 Retrieves the current state of the model.
 
virtual std::string GetName () const =0
 Retrieves the name identifier for this model.
 
virtual const std::map< std::string, History > & GetHistories () const =0
 Retrieves a reference to the map of all registered histories. The histories cannot be edited directly and must be saved to their own space by users before being consumed.
 
virtual int GetTimestep () const =0
 Retrieves the current simulation timestep.
 
virtual int GetHistoryCaptureInterval () const =0
 Retrieves the global history capture interval.
 
virtual int GetFinalTimestep () const =0
 Retrieves the final timestep forced into history output.
 
virtual bool GetInitialHistoryRecorded () const =0
 Checks if the initial history has been recorded for this model.
 
virtual void SetState (const Eigen::Ref< const Eigen::VectorXd > &state)=0
 Sets the current state of the model.
 
virtual void SetHistoryCaptureInterval (int interval)=0
 Sets the global history capture interval for this model.
 
virtual void SetFinalTimestep (int final_timestep)=0
 Sets the final timestep that must always be recorded.
 
virtual void SetInitialHistoryRecorded (bool recorded)=0
 Sets whether the initial state has been recorded in history.
 
virtual void Serialize (std::ostream &os) const =0
 Function to serialize the model's state and metadata to an output stream.
 

Static Public Member Functions

static std::unique_ptr< ModelCreate (const std::string &name, const std::string &log_name=RESPOND_DEFAULT_LOG, const std::string &log_filepath=RESPOND_DEFAULT_LOG_FILE)
 Factory method to create a Model instance.
 

Protected Member Functions

 Model ()=default
 Protected default constructor for subclass initialization. Not intended for direct public use.
 

Member Function Documentation

◆ AddTimestep()

virtual void respond::Model::AddTimestep ( const Timestep timestep)
pure virtual
Parameters
timestepA shared pointer to a Timestep instance. The model gains an ownership reference to this timestep and will manage its lifecycle.

◆ clone()

virtual std::unique_ptr< Model > respond::Model::clone ( ) const
pure virtual
Returns
A unique_ptr to an independent copy of this model.

◆ Create()

static std::unique_ptr< Model > respond::Model::Create ( const std::string &  name,
const std::string &  log_name = RESPOND_DEFAULT_LOG,
const std::string &  log_filepath = RESPOND_DEFAULT_LOG_FILE 
)
static

This method creates a new instance of a Model subclass based on the provided name. It initializes logging for the model and returns a unique_ptr to the created instance. Throws an exception if the model name is unsupported.

Parameters
nameThe name identifier for the model to create.
log_nameName of the logger for this model (default: "console").
log_filepathFile path for the log file (default: "respond.log").
Returns
A unique_ptr to the newly created Model instance.

◆ GetFinalTimestep()

virtual int respond::Model::GetFinalTimestep ( ) const
pure virtual
Returns
The configured final simulation timestep, or -1 if unset.

◆ GetHistories()

virtual const std::map< std::string, History > & respond::Model::GetHistories ( ) const
pure virtual
Returns
A constant reference to a map of history names to History objects.

◆ GetHistoryCaptureInterval()

virtual int respond::Model::GetHistoryCaptureInterval ( ) const
pure virtual
Returns
The active capture interval. A value of 1 means full capture.

◆ GetInitialHistoryRecorded()

virtual bool respond::Model::GetInitialHistoryRecorded ( ) const
pure virtual
Returns
True if the initial state has been recorded in history, false otherwise.

◆ GetName()

virtual std::string respond::Model::GetName ( ) const
pure virtual
Returns
The model's name as a string.

◆ GetState()

virtual const Eigen::Ref< const Eigen::VectorXd > respond::Model::GetState ( ) const
pure virtual
Returns
A reference to the model's internal state. It is limited to observation and changes cannot be made to it directly.

◆ GetTimestep()

virtual int respond::Model::GetTimestep ( ) const
pure virtual
Returns
The current timestep index. Returns -1 if no timesteps have been executed yet.

◆ GetTimestepAtIndex()

virtual Timestep respond::Model::GetTimestepAtIndex ( size_t  index) const
pure virtual
Parameters
indexThe zero-based index of the timestep to retrieve.
Returns
A constant reference to the Timestep at the specified index.

◆ Serialize()

virtual void respond::Model::Serialize ( std::ostream &  os) const
pure virtual

This function is intended to be overridden by subclasses to provide custom serialization logic. It should write the model's state, metadata, and any relevant information to the provided output stream.

Note
The output format is implementation-defined and may vary between subclasses. Users should refer to the specific subclass documentation for details on the serialization format.
Parameters
osThe output stream to which the model's serialized data will be written.

◆ SetFinalTimestep()

virtual void respond::Model::SetFinalTimestep ( int  final_timestep)
pure virtual
Parameters
final_timestepThe final simulation timestep.

◆ SetHistoryCaptureInterval()

virtual void respond::Model::SetHistoryCaptureInterval ( int  interval)
pure virtual
Parameters
intervalRecord every interval timesteps. Values less than 1 default to full capture.

◆ SetInitialHistoryRecorded()

virtual void respond::Model::SetInitialHistoryRecorded ( bool  recorded)
pure virtual
Parameters
recordedTrue if the initial state has been recorded, false otherwise.

◆ SetState()

virtual void respond::Model::SetState ( const Eigen::Ref< const Eigen::VectorXd > &  state)
pure virtual
Parameters
stateA constant reference to a vector. This vector is then applied to the model's internal state. The model may copy or reference this vector as needed.

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