RESPOND 2.5.1
Researching Effective Strategies to Prevent Opioid Death
Loading...
Searching...
No Matches
model.hpp
1
2// File: model.hpp //
3// Project: respond //
4// Created Date: 2026-02-05 //
5// Author: Matthew Carroll //
6// ----- //
7// Last Modified: 2026-07-14 //
8// Modified By: Matthew Carroll //
9// ----- //
10// Copyright (c) 2026 Syndemics Lab at Boston Medical Center //
12#ifndef RESPOND_MODEL_HPP_
13#define RESPOND_MODEL_HPP_
14
15#include <memory>
16#include <string>
17#include <vector>
18
19#include <Eigen/Dense>
20
21#include <respond/constants.hpp>
22#include <respond/history.hpp>
23#include <respond/timestep.hpp>
24
25namespace respond {
30class Model {
31public:
33 //
34 // Rule of Five: Copy and Move Semantics
35 //
37
47 static std::unique_ptr<Model>
48 Create(const std::string &name,
49 const std::string &log_name = RESPOND_DEFAULT_LOG,
50 const std::string &log_filepath = RESPOND_DEFAULT_LOG_FILE);
51
53 virtual ~Model() = default;
54
56 Model(const Model &) = delete;
59 Model &operator=(const Model &) = delete;
60
63 virtual std::unique_ptr<Model> clone() const = 0;
64
66 //
67 // Model Behavior Methods: Timestep Execution and History Management
68 //
70
74 virtual void AddTimestep(const Timestep &timestep) = 0;
75
77 virtual void RunTimestep() = 0;
78
80 virtual void RunTimestep(size_t idx) = 0;
81
84 virtual void RunTimesteps() = 0;
85
87 virtual void ClearTimesteps() = 0;
88
90 virtual void ClearHistories() = 0;
91
95 virtual void CreateDefaultHistories() = 0;
96
98 //
99 // Getters and Setters for Model State and Metadata
100 //
102
106 virtual Timestep GetTimestepAtIndex(size_t index) const = 0;
107
111 virtual const Eigen::Ref<const Eigen::VectorXd> GetState() const = 0;
112
115 virtual std::string GetName() const = 0;
116
122 virtual const std::map<std::string, History> &GetHistories() const = 0;
123
127 virtual int GetTimestep() const = 0;
128
131 virtual int GetHistoryCaptureInterval() const = 0;
132
135 virtual int GetFinalTimestep() const = 0;
136
140 virtual bool GetInitialHistoryRecorded() const = 0;
141
146 virtual void SetState(const Eigen::Ref<const Eigen::VectorXd> &state) = 0;
147
151 virtual void SetHistoryCaptureInterval(int interval) = 0;
152
155 virtual void SetFinalTimestep(int final_timestep) = 0;
156
160 virtual void SetInitialHistoryRecorded(bool recorded) = 0;
161
172 virtual void Serialize(std::ostream &os) const = 0;
173
174protected:
177 Model() = default;
178};
179
184inline std::ostream &operator<<(std::ostream &os, const Model &model) {
185 model.Serialize(os);
186 return os;
187}
188
189} // namespace respond
190
191#endif // RESPOND_MODEL_HPP_
Abstract base class representing a state transition model. Models manage a state vector,...
Definition: model.hpp:30
virtual const Eigen::Ref< const Eigen::VectorXd > GetState() const =0
Retrieves the current state of the model.
virtual bool GetInitialHistoryRecorded() const =0
Checks if the initial history has been recorded for this model.
virtual void RunTimestep(size_t idx)=0
Executes the timestep in the model's sequence.
Model & operator=(const Model &)=delete
Deleted copy assignment operator (models are non-copyable by public API).
virtual std::unique_ptr< Model > clone() const =0
Creates a deep copy of this model.
virtual Timestep GetTimestepAtIndex(size_t index) const =0
Retrieve a copy of a specific timestep by index.
virtual std::string GetName() const =0
Retrieves the name identifier for 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.
static std::unique_ptr< Model > Create(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.
virtual int GetHistoryCaptureInterval() const =0
Retrieves the global history capture interval.
virtual int GetTimestep() const =0
Retrieves the current simulation timestep.
virtual void SetFinalTimestep(int final_timestep)=0
Sets the final timestep that must always be recorded.
virtual void Serialize(std::ostream &os) const =0
Function to serialize the model's state and metadata to an output stream.
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...
virtual void SetInitialHistoryRecorded(bool recorded)=0
Sets whether the initial state has been recorded in history.
Model(const Model &)=delete
Deleted copy constructor (models are non-copyable by public API).
virtual int GetFinalTimestep() const =0
Retrieves the final timestep forced into history output.
virtual ~Model()=default
Virtual destructor for proper polymorphic cleanup.
virtual void SetState(const Eigen::Ref< const Eigen::VectorXd > &state)=0
Sets the current state of the model.
Model()=default
Protected default constructor for subclass initialization. Not intended for direct public use.
virtual void RunTimesteps()=0
Executes all registered timesteps in sequence, applying their transitions to the model's state.
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 base...
virtual void ClearTimesteps()=0
Clears all timesteps from the model.
virtual void SetHistoryCaptureInterval(int interval)=0
Sets the global history capture interval for this model.
Represents a single timestep in a simulation, managing a collection of transitions....
Definition: timestep.hpp:30