Skip to content

Commit ff9df1e

Browse files
HenrZureneSchm
andauthored
55 Write mobility data (#971)
- Save data on selected edges during mobility - Any Indices (or Groups of indices) can be chosen as input. Additionally, the total number of commuters is saved Co-authored-by: reneSchm <[email protected]>
1 parent 8616f71 commit ff9df1e

15 files changed

+1094
-99
lines changed

cpp/examples/CMakeLists.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ add_executable(ode_secir_ageres_example ode_secir_ageres.cpp)
8080
target_link_libraries(ode_secir_ageres_example PRIVATE memilio ode_secir)
8181
target_compile_options(ode_secir_ageres_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
8282

83-
add_executable(graph_example graph.cpp)
84-
target_link_libraries(graph_example PRIVATE memilio ode_seir)
85-
target_compile_options(graph_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
83+
add_executable(ode_secir_graph_example ode_secir_graph.cpp)
84+
target_link_libraries(ode_secir_graph_example PRIVATE memilio ode_secir)
85+
target_compile_options(ode_secir_graph_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
8686

8787
add_executable(graph_stochastic_mobility_example graph_stochastic_mobility.cpp)
8888
target_link_libraries(graph_stochastic_mobility_example PRIVATE memilio ode_secir)
@@ -127,9 +127,13 @@ if(MEMILIO_HAS_JSONCPP)
127127
endif()
128128

129129
if(MEMILIO_HAS_HDF5 AND MEMILIO_HAS_JSONCPP)
130-
add_executable(ode_secir_parameter_study_example ode_secir_parameter_study.cpp)
131-
target_link_libraries(ode_secir_parameter_study_example PRIVATE memilio ode_secir)
132-
target_compile_options(ode_secir_parameter_study_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
130+
add_executable(ode_secir_parameter_study_example ode_secir_parameter_study.cpp)
131+
target_link_libraries(ode_secir_parameter_study_example PRIVATE memilio ode_secir)
132+
target_compile_options(ode_secir_parameter_study_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
133+
134+
add_executable(ode_secir_parameter_study_graph ode_secir_parameter_study_graph.cpp)
135+
target_link_libraries(ode_secir_parameter_study_graph PRIVATE memilio ode_secir)
136+
target_compile_options(ode_secir_parameter_study_graph PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
133137
endif()
134138

135139
if(MEMILIO_HAS_JSONCPP)

cpp/examples/graph.cpp

Lines changed: 0 additions & 69 deletions
This file was deleted.

cpp/examples/ode_secir_graph.cpp

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (C) 2020-2024 MEmilio
3+
*
4+
* Authors: Daniel Abele, Henrik Zunker
5+
*
6+
* Contact: Martin J. Kuehn <[email protected]>
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
#include "memilio/config.h"
21+
#include "ode_secir/model.h"
22+
#include "ode_secir/infection_state.h"
23+
#include "ode_secir/parameters.h"
24+
#include "memilio/mobility/metapopulation_mobility_instant.h"
25+
#include "memilio/compartments/simulation.h"
26+
27+
#include <iostream>
28+
29+
int main()
30+
{
31+
const auto t0 = 0.;
32+
const auto tmax = 30.;
33+
const auto dt = 0.5; //time step of Mobility, daily Mobility every second step
34+
35+
const size_t num_groups = 1;
36+
mio::osecir::Model model(num_groups);
37+
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible}] = 10000;
38+
model.parameters.set<mio::osecir::StartDay>(0);
39+
model.parameters.set<mio::osecir::Seasonality<ScalarType>>(0.2);
40+
41+
model.parameters.get<mio::osecir::TimeExposed<ScalarType>>() = 3.2;
42+
model.parameters.get<mio::osecir::TimeInfectedNoSymptoms<ScalarType>>() = 2.0;
43+
model.parameters.get<mio::osecir::TimeInfectedSymptoms<ScalarType>>() = 5.8;
44+
model.parameters.get<mio::osecir::TimeInfectedSevere<ScalarType>>() = 9.5;
45+
model.parameters.get<mio::osecir::TimeInfectedCritical<ScalarType>>() = 7.1;
46+
47+
model.parameters.get<mio::osecir::TransmissionProbabilityOnContact<ScalarType>>() = 0.1;
48+
model.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<ScalarType>>() = 0.7;
49+
model.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<ScalarType>>() = 0.09;
50+
model.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<ScalarType>>() = 0.25;
51+
model.parameters.get<mio::osecir::MaxRiskOfInfectionFromSymptomatic<ScalarType>>() = 0.45;
52+
model.parameters.get<mio::osecir::TestAndTraceCapacity<ScalarType>>() = 35;
53+
model.parameters.get<mio::osecir::SeverePerInfectedSymptoms<ScalarType>>() = 0.2;
54+
model.parameters.get<mio::osecir::CriticalPerSevere<ScalarType>>() = 0.25;
55+
model.parameters.get<mio::osecir::DeathsPerCritical<ScalarType>>() = 0.3;
56+
57+
mio::ContactMatrixGroup& contact_matrix = model.parameters.get<mio::osecir::ContactPatterns<ScalarType>>();
58+
contact_matrix[0] = mio::ContactMatrix(Eigen::MatrixXd::Constant(1, 1, 10));
59+
60+
//two mostly identical groups
61+
auto model_group1 = model;
62+
auto model_group2 = model;
63+
//some contact restrictions in model_group1
64+
mio::ContactMatrixGroup& contact_matrix_m1 =
65+
model_group1.parameters.get<mio::osecir::ContactPatterns<ScalarType>>();
66+
contact_matrix_m1[0].add_damping(0.7, mio::SimulationTime(15.));
67+
68+
//infection starts in group 1
69+
model_group1.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible}] = 9990;
70+
model_group1.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}] = 100;
71+
72+
// get indices of INS and ISy compartments.
73+
std::vector<std::vector<size_t>> indices_save_edges(2);
74+
75+
// Reserve Space. The multiplication by 2 is necessary because we have the
76+
// base and the confirmed compartments for each age group.
77+
for (auto& vec : indices_save_edges) {
78+
vec.reserve(2 * num_groups);
79+
}
80+
81+
// get indices and write them to the vector
82+
for (auto i = mio::AgeGroup(0); i < mio::AgeGroup(num_groups); ++i) {
83+
indices_save_edges[0].emplace_back(
84+
model.populations.get_flat_index({i, mio::osecir::InfectionState::InfectedNoSymptoms}));
85+
indices_save_edges[0].emplace_back(
86+
model.populations.get_flat_index({i, mio::osecir::InfectionState::InfectedNoSymptomsConfirmed}));
87+
indices_save_edges[1].emplace_back(
88+
model.populations.get_flat_index({i, mio::osecir::InfectionState::InfectedSymptoms}));
89+
indices_save_edges[1].emplace_back(
90+
model.populations.get_flat_index({i, mio::osecir::InfectionState::InfectedSymptomsConfirmed}));
91+
}
92+
93+
mio::Graph<mio::SimulationNode<mio::osecir::Simulation<>>, mio::MobilityEdge<ScalarType>> g;
94+
g.add_node(1001, model_group1, t0);
95+
g.add_node(1002, model_group2, t0);
96+
g.add_edge(0, 1, Eigen::VectorXd::Constant((size_t)mio::osecir::InfectionState::Count, 0.1), indices_save_edges);
97+
g.add_edge(1, 0, Eigen::VectorXd::Constant((size_t)mio::osecir::InfectionState::Count, 0.1), indices_save_edges);
98+
99+
auto sim = mio::make_mobility_sim(t0, dt, std::move(g));
100+
101+
sim.advance(tmax);
102+
103+
auto& edge_1_0 = sim.get_graph().edges()[1];
104+
auto& results = edge_1_0.property.get_mobility_results();
105+
results.print_table({"Commuter INS", "Commuter ISy", "Commuter Total"});
106+
107+
return 0;
108+
}

0 commit comments

Comments
 (0)