RESPOND 2.5.1
Researching Effective Strategies to Prevent Opioid Death
Loading...
Searching...
No Matches
Running the Model

The RESPOND model can be used in multiple ways:

  1. As a C++ library - Integrate into your own C++ projects
  2. Via Python package - Use the higher-level respondpy interface
  3. Standalone executable - Legacy support for direct command-line execution

Using RESPOND as a C++ Library

For C++ developers, RESPOND can be integrated directly into projects. See the C++ API Guide for:

  • Complete API reference
  • Usage examples
  • Memory management details
  • Design patterns and best practices

Basic Example

#include <respond/simulation.hpp>
#include <respond/model.hpp>
#include <respond/timestep.hpp>
#include <respond/transition.hpp>
int main() {
// Create a simulation
respond::Simulation sim("my_logger");
// Create and configure a model
auto model = respond::Model::Create("markov", "my_logger");
// Set initial state
Eigen::VectorXd initial_state(50);
initial_state.setZero();
initial_state(0) = 1000; // 1000 individuals in state 0
model->SetState(initial_state);
// Build one timestep and attach transitions
respond::Timestep step("my_logger");
auto &behavior = step.CreateTransition("behavior");
// behavior->AddMatrix(...);
auto migration = respond::Transition::Create("migration");
step.AddTransition(migration);
// Mutable slot access to transitions owned by this timestep
// step[0]->AddMatrix(...);
// Add timesteps to the model
for (int t = 0; t < 52; ++t) {
model->AddTimestep(step);
}
// Add model to simulation
sim.AddModel(model);
// Run simulation for 52 timesteps
sim.Run(52);
// Extract results
auto histories = sim.GetModelHistory(0);
return 0;
}
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.
Manages and executes multiple models in a coordinated simulation. A Simulation aggregates Model insta...
Definition: simulation.hpp:32
Represents a single timestep in a simulation, managing a collection of transitions....
Definition: timestep.hpp:30
static std::unique_ptr< Transition > Create(const std::string &type, const std::string &name=RESPOND_DEFAULT_TRANSITION_NAME, const std::string &log_name=RESPOND_DEFAULT_LOG, const std::string &log_file=RESPOND_DEFAULT_LOG_FILE)
Creates a transition of the specified type.

For complete examples and API documentation, see the C++ API Guide.

Using the Standalone Executable

Legacy support for standalone execution is available in release v0.3.0.

Command-Line Usage

To run the executable (requires legacy release):

./respond_exe /path/to/input/folders 1 1

Arguments

The executable takes 3 positional arguments:

  1. Input folder path: Directory containing simulation configuration and data
  2. Start folder index: First input folder number (e.g., 1 for input1)
  3. End folder index: Last input folder number (inclusive)

Examples

# Run single input folder
./respond_exe /home/user/data 1 1
# Run folders input1, input2, input3
./respond_exe /home/user/data 1 3
# Run folders input5 through input10
./respond_exe /home/user/data 5 10

Output

The executable produces output files in the same directory as the input data.

Python Integration

For a higher-level interface, use the respondpy Python package:

import respondpy as respond
# Configure and run simulations
sim = respond.Simulation(config_path)
results = sim.run()

See the respondpy documentation for details.

Previous: Data

Next: Under the Hood