-
Notifications
You must be signed in to change notification settings - Fork 20
1210 abm paper logger #1507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
1210 abm paper logger #1507
Changes from all commits
840303d
c7ffab3
e986d96
6e4c6fe
663a189
28c3187
2ba672e
baa272b
20b651e
706aea0
ab2e0e8
e4df6cb
c5cf7dc
f5dffd6
f124f04
75e1105
ddb9cb4
c2433fc
606ba7f
e316b6a
a446792
8a002c7
392ec54
cb08197
7ccdb45
2132e8a
0c5c13a
0fdbb15
e22dd77
7d544bf
9724423
22044c6
6c6879f
49d0587
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,6 +189,67 @@ struct LogInfectionState : mio::LogAlways { | |
| } | ||
| }; | ||
|
|
||
| struct LogInfectionStatePerAgeGroup : mio::LogAlways { | ||
| using Type = std::pair<mio::abm::TimePoint, Eigen::VectorXd>; | ||
| /** | ||
| * @brief Log the TimeSeries of the number of Person%s in an #InfectionState. | ||
| * @param[in] sim The simulation of the abm. | ||
| * @return A pair of the TimePoint and the TimeSeries of the number of Person%s in an #InfectionState. | ||
| */ | ||
| static Type log(const mio::abm::Simulation<>& sim) | ||
| { | ||
|
|
||
| Eigen::VectorXd sum = Eigen::VectorXd::Zero( | ||
| Eigen::Index((size_t)mio::abm::InfectionState::Count * sim.get_model().parameters.get_num_groups())); | ||
| const auto curr_time = sim.get_time(); | ||
| const auto persons = sim.get_model().get_persons(); | ||
|
|
||
|
|
||
| for (auto i = size_t(0); i < persons.size(); ++i) { | ||
| auto& p = persons[i]; | ||
| auto index = (((size_t)(mio::abm::InfectionState::Count)) * ((uint32_t)p.get_age().get())) + | ||
| ((uint32_t)p.get_infection_state(curr_time)); | ||
| // PRAGMA_OMP(atomic) | ||
| sum[index] += 1; | ||
| } | ||
| return std::make_pair(curr_time, sum); | ||
| } | ||
| }; | ||
|
Comment on lines
+192
to
+217
|
||
|
|
||
| struct LogInfectionPerLocationTypePerAgeGroup : mio::LogAlways { | ||
| using Type = std::pair<mio::abm::TimePoint, Eigen::VectorXd>; | ||
|
Comment on lines
+192
to
+220
|
||
| /** | ||
| * @brief Log the TimeSeries of the number of Person%s in an #InfectionState. | ||
| * @param[in] sim The simulation of the abm. | ||
| * @return A pair of the TimePoint and the TimeSeries of the number of Person%s in an #InfectionState. | ||
| */ | ||
|
Comment on lines
+219
to
+225
|
||
| static Type log(const mio::abm::Simulation<>& sim) | ||
| { | ||
|
|
||
| Eigen::VectorXd sum = Eigen::VectorXd::Zero( | ||
| Eigen::Index((size_t)mio::abm::LocationType::Count * sim.get_model().parameters.get_num_groups())); | ||
| auto curr_time = sim.get_time(); | ||
| auto prev_time = sim.get_prev_time(); | ||
| const auto persons = sim.get_model().get_persons(); | ||
|
|
||
|
|
||
| for (auto i = size_t(0); i < persons.size(); ++i) { | ||
| auto& p = persons[i]; | ||
|
|
||
|
|
||
| if ((p.get_infection_state(prev_time) != mio::abm::InfectionState::Exposed) && | ||
| (p.get_infection_state(curr_time) == mio::abm::InfectionState::Exposed)) { | ||
| auto index = (((size_t)(mio::abm::LocationType::Count)) * ((uint32_t)p.get_age().get())) + | ||
| ((uint32_t)p.get_location_type()); | ||
| sum[index] += 1; | ||
|
|
||
| } | ||
| } | ||
| return std::make_pair(curr_time, sum); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| /** | ||
| * @brief This is like the DataWriterToMemory, but it only logs time series data. | ||
| * @tparam Loggers The loggers that are used to log data. The loggers must return a touple with a TimePoint and a value. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,19 +45,33 @@ class ResultSimulation : public Simulation<M> | |
| */ | ||
| void advance(TimePoint tmax) | ||
| { | ||
| Simulation<Model>::advance(tmax, history); | ||
| Simulation<Model>::advance(tmax, history, history_detailed); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Return the simulation result aggregated by infection states. | ||
| */ | ||
| const mio::TimeSeries<double>& get_result() const | ||
| mio::TimeSeries<double> get_result() const | ||
| { | ||
| return get<0>(history.get_log()); | ||
| return std::get<0>(history.get_log()); | ||
| } | ||
|
Comment on lines
+54
to
57
|
||
|
|
||
| /** | ||
| * @brief Return the detailed simulation result aggregated by infection states. | ||
| */ | ||
| mio::TimeSeries<double> get_result_detailed() const | ||
| { | ||
| return std::get<0>(history_detailed.get_log()); | ||
| } | ||
|
Comment on lines
+62
to
+65
|
||
|
|
||
|
|
||
| mio::History<TimeSeriesWriter, LogInfectionState> history{ | ||
| Eigen::Index(InfectionState::Count)}; ///< History used to create the result TimeSeries. | ||
| Eigen::Index(InfectionState::Count)}; | ||
|
Comment on lines
68
to
+69
|
||
|
|
||
| mio::History<TimeSeriesWriter, LogInfectionPerLocationTypePerAgeGroup> history_detailed{ | ||
| Eigen::Index(LocationType::Count) * this->get_model().parameters.get_num_groups()}; | ||
|
|
||
|
|
||
| }; | ||
|
|
||
| } // namespace abm | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,7 @@ class Simulation | |
| Simulation(TimePoint t0, Model&& model) | ||
| : m_model(std::move(model)) | ||
| , m_t(t0) | ||
| , m_t_prev(t0-hours(1)) | ||
|
||
| , m_dt(hours(1)) | ||
| { | ||
| } | ||
|
|
@@ -85,6 +86,15 @@ class Simulation | |
| return m_t; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Get the previous time of the Simulation. | ||
| */ | ||
| TimePoint get_prev_time() const | ||
| { | ||
| return m_t_prev; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @brief Get the Model that this Simulation evolves. | ||
| */ | ||
|
|
@@ -103,11 +113,14 @@ class Simulation | |
| { | ||
| auto dt = std::min(m_dt, tmax - m_t); | ||
| m_model.evolve(m_t, dt); | ||
| m_t_prev = m_t; | ||
| m_t += m_dt; | ||
|
|
||
| } | ||
|
|
||
| Model m_model; ///< The Model to simulate. | ||
| TimePoint m_t; ///< The current TimePoint of the Simulation. | ||
| TimePoint m_t_prev; ///< The previous TimePoint of the Simulation. | ||
|
||
| TimeSpan m_dt; ///< The length of the time steps. | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The directory name
"standart_results"contains a typo: it should be"standard_results". This typo will appear in the output directory path visible to users.