Health-GPS  1.2.2.0
Global Health Policy Simulation model (Health-GPS)
modelrunner.h
Go to the documentation of this file.
1 #pragma once
2 #include "event_aggregator.h"
3 #include "simulation.h"
4 
5 #include <atomic>
6 #include <functional>
7 #include <memory>
8 #include <stop_token>
9 
10 namespace hgps {
11 
24 class ModelRunner {
25  public:
26  ModelRunner() = delete;
27 
31  ModelRunner(EventAggregator &bus, std::unique_ptr<RandomBitGenerator> generator) noexcept;
32 
38  double run(Simulation &baseline, const unsigned int trial_runs);
39 
46  double run(Simulation &baseline, Simulation &intervention, const unsigned int trial_runs);
47 
50  bool is_running() const noexcept;
51 
53  void cancel() noexcept;
54 
55  private:
56  std::atomic<bool> running_;
57  std::reference_wrapper<EventAggregator> event_bus_;
58  std::unique_ptr<RandomBitGenerator> rnd_;
59  std::stop_source source_;
60  std::string runner_id_{};
61 
62  void run_model_thread(std::stop_token token, Simulation &model, const unsigned int run,
63  const std::optional<unsigned int> seed = std::nullopt);
64 
65  void notify(std::unique_ptr<hgps::EventMessage> message);
66 };
67 } // namespace hgps
Defines the event aggregator interface type.
Definition: event_aggregator.h:59
Defines the simulation executive data type class.
Definition: modelrunner.h:24
void cancel() noexcept
Cancel a running experiment.
Definition: modelrunner.cpp:118
ModelRunner()=delete
double run(Simulation &baseline, const unsigned int trial_runs)
Run an experiment for baseline scenario only.
Definition: modelrunner.cpp:17
bool is_running() const noexcept
Gets a value indicating whether an experiment is current running.
Definition: modelrunner.cpp:116
Pseudo-random number generator algorithm interface.
Definition: randombit_generator.h:9
Defines the simulation class interface.
Definition: simulation.h:9
Top-level namespace for Health-GPS C++ API.
Definition: analysis_definition.h:8
Global namespace.
Definition: jsonparser.h:88