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-09-24 //
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/runtime_config.hpp>
24#include <respond/timestep.hpp>
25
26namespace respond {
31class Model {
32public:
34 //
35 // Rule of Five: Copy and Move Semantics
36 //
38
47 [[deprecated("Use Model::Create(name, RuntimeConfig) instead")]]
48 static std::unique_ptr<Model>
49 Create(const std::string &name,
50 const std::string &log_name = RESPOND_DEFAULT_LOG,
51 const std::string &log_filepath = RESPOND_DEFAULT_LOG_FILE);
52
63 [[deprecated("Use Model::Create(name, RuntimeConfig) instead")]]
64 static std::unique_ptr<Model>
65 Create(const std::string &name, const unsigned int processor_count,
66 const std::string &log_name = RESPOND_DEFAULT_LOG,
67 const std::string &log_filepath = RESPOND_DEFAULT_LOG_FILE);
68
75 [[deprecated("Use Model::Create(name, RuntimeConfig) instead")]]
76 static std::unique_ptr<Model>
77 Create(const std::string &name, const ExecutionConfig &execution_config,
78 const std::string &log_name = RESPOND_DEFAULT_LOG,
79 const std::string &log_filepath = RESPOND_DEFAULT_LOG_FILE);
80
83 static std::unique_ptr<Model> Create(const std::string &name,
84 const RuntimeConfig &runtime_config);
85
87 virtual ~Model() = default;
88
90 Model(const Model &) = delete;
93 Model &operator=(const Model &) = delete;
94
97 virtual std::unique_ptr<Model> clone() const = 0;
98
100 //
101 // Model Behavior Methods: Timestep Execution and History Management
102 //
104
108 virtual void AddTimestep(const Timestep &timestep) = 0;
109
111 virtual void RunTimestep() = 0;
112
114 virtual void RunTimestep(size_t idx) = 0;
115
118 virtual void RunTimesteps() = 0;
119
121 virtual void ClearTimesteps() = 0;
122
124 virtual void ClearHistories() = 0;
125
129 virtual void CreateDefaultHistories() = 0;
130
132 //
133 // Getters and Setters for Model State and Metadata
134 //
136
140 virtual Timestep GetTimestepAtIndex(size_t index) const = 0;
141
145 virtual const Eigen::Ref<const Eigen::VectorXd> GetState() const = 0;
146
149 virtual std::string GetName() const = 0;
150
156 virtual const std::map<std::string, History> &GetHistories() const = 0;
157
161 virtual int GetTimestep() const = 0;
162
165 virtual int GetHistoryCaptureInterval() const = 0;
166
169 virtual int GetFinalTimestep() const = 0;
170
174 virtual bool GetInitialHistoryRecorded() const = 0;
175
180 virtual void SetState(const Eigen::Ref<const Eigen::VectorXd> &state) = 0;
181
185 virtual void SetHistoryCaptureInterval(int interval) = 0;
186
189 virtual void SetFinalTimestep(int final_timestep) = 0;
190
194 virtual void SetInitialHistoryRecorded(bool recorded) = 0;
195
206 virtual void Serialize(std::ostream &os) const = 0;
207
208protected:
211 Model() = default;
212};
213
218inline std::ostream &operator<<(std::ostream &os, const Model &model) {
219 model.Serialize(os);
220 return os;
221}
222
223} // namespace respond
224
225#endif // RESPOND_MODEL_HPP_
Abstract base class representing a state transition model. Models manage a state vector,...
Definition: model.hpp:31
virtual const Eigen::Ref< const Eigen::VectorXd > GetState() const =0
Retrieves the current state of the model.
static std::unique_ptr< Model > Create(const std::string &name, const RuntimeConfig &runtime_config)
Creates a Markov model with shared runtime settings.
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.
static std::unique_ptr< Model > Create(const std::string &name, const ExecutionConfig &execution_config, const std::string &log_name=RESPOND_DEFAULT_LOG, const std::string &log_filepath=RESPOND_DEFAULT_LOG_FILE)
Creates a Model with explicit execution settings.
virtual void SetState(const Eigen::Ref< const Eigen::VectorXd > &state)=0
Sets the current state of the model.
static std::unique_ptr< Model > Create(const std::string &name, const unsigned int processor_count, const std::string &log_name=RESPOND_DEFAULT_LOG, const std::string &log_filepath=RESPOND_DEFAULT_LOG_FILE)
Alternate factory method to create a Model instance.
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:31
Controls how a Simulation distributes execution resources.
Definition: execution_config.hpp:14
Groups execution and logging settings shared by runtime objects.
Definition: runtime_config.hpp:17