RESPOND 2.4.0
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 (const std::string &name="state", const std::string &log_name="console")
 Constructs a History tracker.
 
 History (const std::string &name, const std::string &log_name, HistoryMode mode)
 Constructs a History tracker with an explicit recording mode.
 
 ~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.
 
bool operator== (const History &other) const
 Equality comparison operator.
 
bool operator!= (const History &other) const
 Inequality comparison operator.
 
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.
 
bool HasPendingState () const
 Indicates whether an accumulated history has pending state.
 
Eigen::VectorXd GetPendingState () const
 Retrieves the pending accumulated state.
 
int GetLatestRecordedTimestep () const
 Retrieves the latest recorded timestep.
 
std::string GetHistoryName () const
 Retrieves the identifier name of this history.
 
std::string GetLogName () const
 Retrieves the logger name for 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.
 
void AddState (const Eigen::VectorXd &state, int timestep=-1)
 Records a state vector at a specific or automatic timestep.
 
void RecordSnapshot (const Eigen::VectorXd &state, int timestep)
 Records a snapshot value at a concrete timestep.
 
void AccumulateState (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.
 

Constructor & Destructor Documentation

◆ History() [1/3]

respond::History::History ( const std::string &  name = "state",
const std::string &  log_name = "console" 
)
inline
Parameters
nameThe identifier for this history (default: "state").
log_nameThe logger name for error reporting (default: "console").

◆ History() [2/3]

respond::History::History ( const std::string &  name,
const std::string &  log_name,
HistoryMode  mode 
)
inline
Parameters
nameThe identifier for this history.
log_nameThe logger name for error reporting.
modeWhether the history stores snapshots or accumulations.

◆ History() [3/3]

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::VectorXd &  state)
inline
Parameters
stateThe per-step contribution to accumulate.

◆ AddState()

void respond::History::AddState ( 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.

◆ GetHistoryName()

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

◆ GetLatestRecordedTimestep()

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

◆ GetLogName()

std::string respond::History::GetLogName ( ) const
inline
Returns
The associated logger's name.

◆ 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.

◆ RecordSnapshot()

void respond::History::RecordSnapshot ( const Eigen::VectorXd &  state,
int  timestep 
)
inline
Parameters
stateThe snapshot value to record.
timestepThe simulation timestep for this snapshot.

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