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

Tracks and manages state vector history over time. History records state snapshots at discrete timesteps, enabling analysis of state trajectories during model execution. Supports sparse timesteps (gaps are filled with zero vectors).

#include <history.hpp>

Public Member Functions

 History ()
 Default constructor initializing a history with the default name "state" and default mode based on that name.
 
 History (const std::string &name)
 Constructs a history with a specified name, using the default mode based on that name.
 
 History (const std::string &name, const HistoryMode &mode)
 Constructs a history with a specified name and mode.
 
 History (const std::string &name, const HistoryMode &mode, const std::string &log_name)
 Constructs a history with a specified name, mode, and logger.
 
 History (const std::string &name, const std::string &log_name)
 Constructs a history with a specified name and logger.
 
 History (const std::string &name, const std::string &log_name, const std::string &log_filepath)
 Constructs a history with a specified name, logger, and log file path.
 
 History (const std::string &name, const HistoryMode &mode, const std::string &log_name, const std::string &log_filepath)
 Constructs a history with a specified name, mode, logger, and log file path.
 
 ~History ()=default
 Destructor (default).
 
 History (const History &other)
 Copy constructor implementing the Rule of Five. Creates an independent copy of the history state and metadata.
 
Historyoperator= (const History &other)
 Copy assignment operator implementing the Rule of Five.
 
 History (History &&other) noexcept
 Move constructor implementing the Rule of Five.
 
Historyoperator= (History &&other) noexcept
 Move assignment operator implementing the Rule of Five.
 
void AddState (const Eigen::Ref< const Eigen::VectorXd > &state, int timestep=-1)
 Records a state vector at a specific or automatic timestep.
 
void AccumulateState (const Eigen::Ref< const Eigen::VectorXd > &state)
 Adds a contribution to an accumulated history.
 
void FlushPendingState (int timestep, Eigen::Index state_size)
 Flushes pending accumulated state into a recorded timestep.
 
void Clear ()
 Clears all recorded state history.
 
bool HasPendingState () const
 Indicates whether an accumulated history has pending state.
 
std::map< int, Eigen::VectorXd > GetStateMap () const
 Retrieves the complete state map (timestep -> state vector).
 
const std::vector< int > & GetRecordedTimesteps () const
 Retrieves the recorded timesteps without densifying gaps.
 
const std::vector< Eigen::VectorXd > & GetRecordedStates () const
 Retrieves the recorded state vectors without densifying gaps.
 
HistoryMode GetHistoryMode () const
 Retrieves the configured history recording mode.
 
Eigen::VectorXd GetPendingState () const
 Retrieves the pending accumulated state.
 
int GetLatestRecordedTimestep () const
 Retrieves the latest recorded timestep.
 
std::string GetName () const
 Retrieves the identifier name of this history.
 
std::vector< Eigen::VectorXd > GetStateAsVector () const
 Converts the sparse history map to a contiguous vector of states. Gaps in timesteps are filled with zero vectors of appropriate dimension.
 
bool operator== (const History &other) const
 Equality comparison operator.
 
bool operator!= (const History &other) const
 Inequality comparison operator.
 

Friends

std::ostream & operator<< (std::ostream &os, const History &history)
 

Constructor & Destructor Documentation

◆ History() [1/7]

respond::History::History ( const std::string &  name)
inline
Parameters
nameThe identifier name for this history instance.

◆ History() [2/7]

respond::History::History ( const std::string &  name,
const HistoryMode &  mode 
)
inline
Parameters
nameThe identifier name for this history instance.
modeThe history recording mode (snapshot or accumulated).

◆ History() [3/7]

respond::History::History ( const std::string &  name,
const HistoryMode &  mode,
const std::string &  log_name 
)
inline
Parameters
nameThe identifier name for this history instance.
modeThe history recording mode (snapshot or accumulated).
log_nameThe name of the logger to use for history output.

◆ History() [4/7]

respond::History::History ( const std::string &  name,
const std::string &  log_name 
)
inline
Parameters
nameThe identifier name for this history instance.
log_nameThe name of the logger to use for history output.

◆ History() [5/7]

respond::History::History ( const std::string &  name,
const std::string &  log_name,
const std::string &  log_filepath 
)
inline
Parameters
nameThe identifier name for this history instance.
log_nameThe name of the logger to use for history output.
log_filepathThe file path for the logger output.

◆ History() [6/7]

respond::History::History ( const std::string &  name,
const HistoryMode &  mode,
const std::string &  log_name,
const std::string &  log_filepath 
)
inline
Parameters
nameThe identifier name for this history instance.
modeThe history recording mode (snapshot or accumulated).
log_nameThe name of the logger to use for history output.
log_filepathThe file path for the logger output.

◆ History() [7/7]

respond::History::History ( History &&  other)
inlinenoexcept
Parameters
otherThe history to move from (leaves original state unchanged per current implementation).

Member Function Documentation

◆ AccumulateState()

void respond::History::AccumulateState ( const Eigen::Ref< const Eigen::VectorXd > &  state)
inline
Parameters
stateThe per-step contribution to accumulate.

◆ AddState()

void respond::History::AddState ( const Eigen::Ref< const Eigen::VectorXd > &  state,
int  timestep = -1 
)
inline
Parameters
stateThe state vector to record.
timestepThe timestep index for this state (default: -1 for automatic next timestep). If timestep is negative, the next sequential timestep is used automatically. If timestep already exists, it is considered invalid but is currently overwritten.

◆ FlushPendingState()

void respond::History::FlushPendingState ( int  timestep,
Eigen::Index  state_size 
)
inline
Parameters
timestepThe simulation timestep to record.
state_sizeSize of a zero vector to record if nothing is pending.

◆ GetHistoryMode()

HistoryMode respond::History::GetHistoryMode ( ) const
inline
Returns
Snapshot or accumulated history mode.

◆ GetLatestRecordedTimestep()

int respond::History::GetLatestRecordedTimestep ( ) const
inline
Returns
Largest recorded timestep, or -1 if history is empty.

◆ GetName()

std::string respond::History::GetName ( ) const
inline
Returns
The history's name string.

◆ GetPendingState()

Eigen::VectorXd respond::History::GetPendingState ( ) const
inline
Returns
The pending aggregate vector, or an empty vector if none.

◆ GetRecordedStates()

const std::vector< Eigen::VectorXd > & respond::History::GetRecordedStates ( ) const
inline
Returns
Const reference to the stored state vectors.

◆ GetRecordedTimesteps()

const std::vector< int > & respond::History::GetRecordedTimesteps ( ) const
inline
Returns
Const reference to the stored timestep indices.

◆ GetStateAsVector()

std::vector< Eigen::VectorXd > respond::History::GetStateAsVector ( ) const
inline
Returns
Vector of Eigen vectors from timestep 0 to the maximum recorded timestep. Returns empty vector if no state has been recorded.

◆ GetStateMap()

std::map< int, Eigen::VectorXd > respond::History::GetStateMap ( ) const
inline
Returns
Map of integer timesteps to Eigen vectors representing states.

◆ HasPendingState()

bool respond::History::HasPendingState ( ) const
inline
Returns
True when a pending aggregate exists.

◆ operator!=()

bool respond::History::operator!= ( const History other) const
inline
Parameters
otherThe history to compare with.
Returns
True if histories differ in any aspect.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ operator==()

bool respond::History::operator== ( const History other) const
inline
Parameters
otherThe history to compare with.
Returns
True if all history properties and state are identical.

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