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

Represents a single timestep in a simulation, managing a collection of transitions. Each timestep can execute its transitions in sequence, applying their effects to a state vector and updating history records. Transitions can be added, retrieved, and managed within the timestep. The timestep also handles logging for its operations.

#include <timestep.hpp>

Classes

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

Public Member Functions

 Timestep ()
 Default constructor for Timestep. Initializes with default logger.
 
 Timestep (const std::string &log_name)
 Default constructor for Timestep with specified logger name. Initializes with default log file path.
 
 Timestep (const std::string &log_name, const std::string &log_filepath)
 Default constructor for Timestep with specified logger name and log file path.
 
 ~Timestep ()=default
 Destructor for Timestep. Default implementation.
 
 Timestep (const Timestep &other)
 Copy constructor for Timestep. Creates a deep copy of the transitions.
 
Timestepoperator= (const Timestep &other)
 Copy assignment operator for Timestep. Creates a deep copy of the transitions.
 
 Timestep (Timestep &&other) noexcept
 Move constructor for Timestep. Transfers ownership of transitions.
 
Timestepoperator= (Timestep &&other) noexcept
 Move assignment operator for Timestep. Transfers ownership of transitions.
 
const std::unique_ptr< Transition > & CreateTransition (const std::string &transition_name)
 Creates a transition of the specified type and adds it to this timestep.
 
void AddTransition (const std::unique_ptr< Transition > &transition)
 Adds a transition to the timestep. The transition is cloned and managed by the timestep.
 
std::unique_ptr< TransitionRemoveTransition (size_t idx)
 Removes a transition from this timestep by index and returns it.
 
void AddMatrixToTransition (const size_t &idx, const Eigen::Ref< const Eigen::MatrixXd > &m)
 Adds a matrix to an existing transition in this timestep by index.
 
void AddMatrixToTransition (const std::string &transition_name, const Eigen::Ref< const Eigen::MatrixXd > &m)
 Adds a matrix to an existing transition in this timestep by name.
 
const std::unique_ptr< Transition > & GetTransition (const size_t &idx) const
 Retrieves a constant reference to a transition in this timestep by index.
 
const std::unique_ptr< Transition > & GetTransition (const std::string &transition_name) const
 Gets a constant reference to a transition in this timestep by name.
 
std::vector< std::unique_ptr< Transition > > GetTransitions () const
 Gets a vector of unique_ptrs to all transitions in this timestep. The returned vector contains deep copies of the transitions, ensuring that modifications to the returned transitions do not affect the original transitions in the timestep.
 
std::vector< std::string > GetTransitionNames () const
 Gets a vector of the names of all transitions in this timestep.
 
TransitionSlotProxy operator[] (size_t idx)
 Mutable index-based transition access.
 
const Transitionoperator[] (size_t idx) const
 Const index-based transition access.
 
bool operator== (const Timestep &other) const
 Overloaded equality operator for Timestep. Compares two Timestep instances for equality based on their transitions and transition matrices.
 
bool operator!= (const Timestep &other) const
 Overloaded inequality operator for Timestep. Compares two Timestep instances for inequality based on their transitions and transition matrices.
 

Friends

std::ostream & operator<< (std::ostream &os, const Timestep &other)
 Overloaded stream insertion operator for Timestep. Outputs the names of all transitions in the timestep to the provided output stream.
 

Constructor & Destructor Documentation

◆ Timestep() [1/4]

respond::Timestep::Timestep ( const std::string &  log_name)
inline
Parameters
log_nameString name for the logger to be used by this timestep.

◆ Timestep() [2/4]

respond::Timestep::Timestep ( const std::string &  log_name,
const std::string &  log_filepath 
)
inline
Parameters
log_nameString name for the logger to be used by this timestep.
log_filepathString path for the log file to be used by this timestep.

◆ Timestep() [3/4]

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

◆ Timestep() [4/4]

respond::Timestep::Timestep ( Timestep &&  other)
inlinenoexcept
Parameters
otherThe Timestep instance to move from.

Member Function Documentation

◆ AddMatrixToTransition() [1/2]

void respond::Timestep::AddMatrixToTransition ( const size_t &  idx,
const Eigen::Ref< const Eigen::MatrixXd > &  m 
)
inline
Parameters
idxThe index of the transition to which the matrix will be added.
mThe transition matrix to add (not modified by this transition).

◆ AddMatrixToTransition() [2/2]

void respond::Timestep::AddMatrixToTransition ( const std::string &  transition_name,
const Eigen::Ref< const Eigen::MatrixXd > &  m 
)
inline
Parameters
transition_nameThe name of the transition to which the matrix will be added.
mThe transition matrix to add (not modified by this transition).

◆ AddTransition()

void respond::Timestep::AddTransition ( const std::unique_ptr< Transition > &  transition)
inline
Parameters
transitionA unique_ptr to a Transition instance to add.

◆ CreateTransition()

const std::unique_ptr< Transition > & respond::Timestep::CreateTransition ( const std::string &  transition_name)
inline
Parameters
transition_nameThe type of transition to create. Supported types (case-insensitive):
  • "migration": Population migration transitions
  • "behavior": Behavioral state transitions
  • "intervention": Intervention-driven transitions
  • "overdose": Overdose-related transitions
  • "background_death": Background mortality transitions
Returns
A constant reference to the created Transition. Throws an exception if the transition type is unsupported.

◆ GetTransition() [1/2]

const std::unique_ptr< Transition > & respond::Timestep::GetTransition ( const size_t &  idx) const
inline
Parameters
idxThe index of the transition to retrieve.
Returns
A constant reference to the Transition at the specified index. Throws an error if the index is out of range.

◆ GetTransition() [2/2]

const std::unique_ptr< Transition > & respond::Timestep::GetTransition ( const std::string &  transition_name) const
inline
Parameters
transition_nameThe name of the transition to retrieve.
Returns
A constant reference to the Transition with the specified name. Throws an error if the transition is not found.

◆ GetTransitionNames()

std::vector< std::string > respond::Timestep::GetTransitionNames ( ) const
inline
Returns
A vector of strings containing the names of the transitions in this timestep.

◆ GetTransitions()

std::vector< std::unique_ptr< Transition > > respond::Timestep::GetTransitions ( ) const
inline
Returns
A vector of unique_ptrs to the transitions in this timestep.

◆ operator!=()

bool respond::Timestep::operator!= ( const Timestep other) const
inline
Parameters
lhsThe left-hand side Timestep instance to compare.
rhsThe right-hand side Timestep instance to compare.
Returns
True if the two Timestep instances are not equal (different transitions or transition matrices), false otherwise.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ operator==()

bool respond::Timestep::operator== ( const Timestep other) const
inline
Parameters
lhsThe left-hand side Timestep instance to compare.
rhsThe right-hand side Timestep instance to compare.
Returns
True if the two Timestep instances are equal (same transitions and transition matrices), false otherwise.

◆ operator[]() [1/2]

TransitionSlotProxy respond::Timestep::operator[] ( size_t  idx)
inline

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

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

◆ operator[]() [2/2]

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

◆ RemoveTransition()

std::unique_ptr< Transition > respond::Timestep::RemoveTransition ( size_t  idx)
inline
Parameters
idxThe index of the transition to remove. Must be within the range of existing transitions.
Returns
A unique_ptr to the removed Transition. Throws an exception if the index is out of range.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Timestep other 
)
friend

This operator allows for easy logging and debugging of the transitions contained within a Timestep instance. It outputs a list of transition names, each prefixed with a dash for clarity.

Parameters
osThe output stream to which the transition names will be written.
otherThe Timestep instance whose transitions are to be output.
Returns
A reference to the output stream after writing the transition names.

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