Skip to content
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

646 use graph model with ABMs v3 #1085

Merged
merged 126 commits into from
Jan 31, 2025
Merged
Changes from 1 commit
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
f272d9c
add ABM simulation node and edge
jubicker Jun 7, 2024
1f29e1c
graph abm implementation
jubicker Jul 11, 2024
5e91137
remove warning surpression for boost
jubicker Jul 11, 2024
22a2a60
merge main
jubicker Jul 11, 2024
4368cb5
add CMakeList
jubicker Jul 12, 2024
81df1a8
CMake List Bug fix
jubicker Jul 12, 2024
5b2c64a
fix include
jubicker Jul 12, 2024
414c3f4
bug fix
jubicker Jul 12, 2024
4e2a733
test
jubicker Jul 15, 2024
8f1d7cb
test apply_mobility
jubicker Jul 15, 2024
7400802
extend apply_mobility test
jubicker Jul 16, 2024
b314715
error in abm_minimal example
jubicker Jul 16, 2024
dbbd068
test for apply mobility
jubicker Jul 17, 2024
196275f
finx clang bug
jubicker Jul 18, 2024
a5a4e88
abm minimal bug fix
jubicker Jul 18, 2024
3367fa6
Merge branch '646-use-graph-model-with-abms-v2' of https://github.com…
jubicker Jul 18, 2024
8cce390
graph_abm example
jubicker Jul 18, 2024
2fc9026
graph abm example
jubicker Jul 19, 2024
ef4c0b1
merge main
jubicker Jul 22, 2024
0ece6be
fix merge conflicts
jubicker Jul 23, 2024
b773193
fix test
jubicker Jul 23, 2024
b4d44d5
graph abm example
jubicker Jul 25, 2024
ae95301
remove unnecessary comment
jubicker Jul 25, 2024
5ebd62f
Merge branch '646-use-graph-model-with-abms-v2' of https://github.com…
jubicker Jul 25, 2024
e22009b
fix bug
jubicker Jul 25, 2024
11c3ae8
delete dbugging comments
jubicker Jul 26, 2024
1f85548
Merge branch '646-use-graph-model-with-abms-v2' of https://github.com…
jubicker Jul 26, 2024
fdad4da
benchmark inactive persons
jubicker Jul 31, 2024
509854c
merge main
jubicker Aug 1, 2024
b5b9338
fix merge conflicts
jubicker Aug 1, 2024
5ef826d
[ci skip] model wrapper
jubicker Aug 5, 2024
8ec2fcf
add tests
jubicker Aug 7, 2024
07b268a
msvc is a diva
jubicker Aug 7, 2024
8623ad3
add location model id to constructor
jubicker Aug 7, 2024
d4e3765
review comments
jubicker Aug 7, 2024
7f59e08
Merge branch '646-use-graph-model-with-abms-v3' of https://github.com…
jubicker Aug 7, 2024
a34989e
bug fix
jubicker Aug 7, 2024
9d76ae6
add example
jubicker Aug 7, 2024
267aa52
merge main
jubicker Aug 7, 2024
56c9708
fix bindings
jubicker Aug 7, 2024
251012c
python bindings
jubicker Aug 7, 2024
b9a777d
fix python test
jubicker Aug 8, 2024
8478a94
fix python test
jubicker Aug 8, 2024
41f7f21
adjust benchmark
jubicker Aug 8, 2024
c29f670
extend tests
jubicker Aug 8, 2024
62a790e
Merge branch '646-use-graph-model-with-abms-v3' of https://github.com…
jubicker Aug 8, 2024
af1e7f6
test ci
jubicker Aug 8, 2024
983ca21
ci test
jubicker Aug 9, 2024
59c4450
ci test
jubicker Aug 9, 2024
a8e84a4
ci test
jubicker Aug 9, 2024
9e568d7
test ci
jubicker Aug 9, 2024
53d19a1
ci
jubicker Aug 9, 2024
f8897e4
test ci
jubicker Aug 9, 2024
e4a75fd
ci test
jubicker Aug 9, 2024
cadfecd
CI comment out node.evolve
jubicker Aug 9, 2024
99c1d4c
CI comment in node.evolve
jubicker Aug 9, 2024
6b8d9b0
log in test
jubicker Aug 9, 2024
336998a
test
jubicker Aug 9, 2024
b5a6a0b
test
jubicker Aug 9, 2024
7484ce9
more tests
jubicker Aug 9, 2024
53c45e2
more logs
jubicker Aug 9, 2024
de0cae6
bug fix
jubicker Aug 12, 2024
4daeac6
another bug fix
jubicker Aug 12, 2024
ef0bff3
logs
jubicker Aug 12, 2024
afdbc6d
more logs
jubicker Aug 12, 2024
39d3b48
test log
jubicker Aug 12, 2024
f0aafd4
rename world.get_location
jubicker Aug 12, 2024
de4fd46
more logs
jubicker Aug 12, 2024
c5bc31b
log fix
jubicker Aug 12, 2024
0632c13
log
jubicker Aug 12, 2024
db910b7
Mock exponential dist in test
jubicker Aug 12, 2024
31935e4
don't use trip and mobility rules
jubicker Aug 12, 2024
72200ee
make mobility rules input
jubicker Aug 13, 2024
c285c38
remove logs
jubicker Aug 13, 2024
b659311
rework add_person such that person id can be kept
jubicker Nov 21, 2024
50bcd3b
merge main
jubicker Nov 21, 2024
bece66b
bug fix after merge
jubicker Nov 21, 2024
8237f36
finx abm python bindings
jubicker Nov 21, 2024
a6e9c82
python test abm
jubicker Nov 21, 2024
cb977f1
python bindings template abm simulation
jubicker Nov 21, 2024
b2023af
abm python bindings
jubicker Nov 22, 2024
58d4bb1
merge main
jubicker Dec 3, 2024
1e69b4d
Debug logs
jubicker Dec 6, 2024
0a822ef
Merge branch '646-use-graph-model-with-abms-v3' of https://github.com…
jubicker Dec 6, 2024
1eabac2
Update cpp/examples/graph_abm.cpp
jubicker Jan 8, 2025
944736f
Apply suggestions from code review
jubicker Jan 8, 2025
ecdd68a
merge main
jubicker Jan 8, 2025
26fe99f
add unique person id
jubicker Jan 10, 2025
66896aa
review comment
jubicker Jan 10, 2025
8a97b5c
fix CI
jubicker Jan 10, 2025
a106505
bug fix
jubicker Jan 13, 2025
34ebe3b
remove const from id getter
jubicker Jan 13, 2025
f21f37f
sort m_persons vector before moving persons between nodes
jubicker Jan 14, 2025
6a76553
unique id
jubicker Jan 14, 2025
e0f3be1
extend tests
jubicker Jan 14, 2025
788724a
fix test
jubicker Jan 14, 2025
a807dd0
[CI Skip] test
jubicker Jan 14, 2025
7a4d6d6
[ci skip]
jubicker Jan 14, 2025
17ff528
test
jubicker Jan 14, 2025
c3c92c5
test
jubicker Jan 14, 2025
c7e60a8
ci
jubicker Jan 14, 2025
f221fb3
ci
jubicker Jan 14, 2025
bfb7b72
fix CI
jubicker Jan 14, 2025
ad4a5fd
Rename model_wrapper to graph_abmodel
jubicker Jan 15, 2025
dd58d68
rename evolve to advance in graph
jubicker Jan 15, 2025
3eaa51a
introduce local index and global id
jubicker Jan 15, 2025
830aff3
add tests
jubicker Jan 15, 2025
ce3aad4
test person init
jubicker Jan 16, 2025
ac8e4ec
remove local index from person
jubicker Jan 17, 2025
5a57215
fix msvc problems
jubicker Jan 20, 2025
ccb157d
fix graph ABM example
jubicker Jan 20, 2025
db66cac
rename GlobalID to PersonId
jubicker Jan 20, 2025
9071313
Review and CodeCov
jubicker Jan 20, 2025
c300dbf
Add assertion
jubicker Jan 20, 2025
151e89b
add attributes to per son serialize
jubicker Jan 23, 2025
9ea7d30
bug finding comment
xsaschako Jan 23, 2025
03661d0
bug refining comment
xsaschako Jan 23, 2025
c7c26c3
Merge branch 'main' into 646-use-graph-model-with-abms-v3
jubicker Jan 23, 2025
8147922
fix test after merge
jubicker Jan 23, 2025
f37a92f
save rng key in person
jubicker Jan 26, 2025
c4ae180
Update cpp/models/abm/person.h
jubicker Jan 30, 2025
f9ab818
Apply suggestions from code review
jubicker Jan 30, 2025
f8927cc
Review
jubicker Jan 30, 2025
e1cdec1
Merge branch '646-use-graph-model-with-abms-v3' of https://github.com…
jubicker Jan 30, 2025
533c3ed
code cov
jubicker Jan 31, 2025
f3632a7
add assertion to get_person
jubicker Jan 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
graph abm example
  • Loading branch information
jubicker committed Jul 25, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit b4d44d56c9e8dc969a230f3c3e2d6238d4319905
7 changes: 4 additions & 3 deletions cpp/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -112,9 +112,10 @@ add_executable(history_example history.cpp)
target_link_libraries(history_example PRIVATE memilio)
target_compile_options(history_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

# add_executable(graph_abm_example graph_abm.cpp)
# target_link_libraries(graph_abm_example PRIVATE memilio graph_abm abm)
# target_compile_options(abm_minimal_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
add_executable(graph_abm_example graph_abm.cpp)
target_link_libraries(graph_abm_example PRIVATE memilio graph_abm abm)
target_compile_options(abm_minimal_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

if(MEMILIO_HAS_JSONCPP)
add_executable(ode_secir_read_graph_example ode_secir_read_graph.cpp)
target_link_libraries(ode_secir_read_graph_example PRIVATE memilio ode_secir)
87 changes: 49 additions & 38 deletions cpp/examples/graph_abm.cpp
Original file line number Diff line number Diff line change
@@ -18,10 +18,12 @@
* limitations under the License.
*/

#include "abm/abm.h"
#include "abm/household.h"
#include "abm/world.h"
#include "abm/infection_state.h"
#include "abm/location_type.h"
#include "abm/time.h"
#include "abm/person_id.h"
#include "graph_abm/graph_abm_mobility.h"
#include "graph_abm/mobility_rules.h"
#include "memilio/io/history.h"
@@ -41,20 +43,22 @@ struct Logger : mio::LogAlways {
* - The total number of Persons at the location
* - A map containing the number of Persons per InfectionState at the location
*/
using Type = std::vector<std::tuple<mio::abm::LocationId, size_t, std::map<mio::abm::InfectionState, size_t>>>;
using Type = std::vector<std::tuple<int, mio::abm::LocationType, mio::abm::LocationId, size_t,
std::map<mio::abm::InfectionState, size_t>>>;
static Type log(const mio::abm::Simulation& sim)
{
Type location_information{};
std::map<mio::abm::InfectionState, size_t> persons_per_infection_state;
auto t = sim.get_time();
for (auto&& loc : sim.get_world().get_locations()) {
std::map<mio::abm::InfectionState, size_t> persons_per_infection_state;
for (size_t i = 0; i < static_cast<size_t>(mio::abm::InfectionState::Count); ++i) {
auto inf_state = mio::abm::InfectionState(i);
persons_per_infection_state.insert({inf_state, loc.get_subpopulation(t, inf_state)});
persons_per_infection_state.insert(
{inf_state, sim.get_world().get_subpopulation(loc.get_id(), t, inf_state)});
}
location_information.push_back(
std::make_tuple(mio::abm::LocationId{loc.get_index(), loc.get_type(), loc.get_world_id()},
loc.get_number_persons(), persons_per_infection_state));
location_information.push_back(std::make_tuple(loc.get_world_id(), loc.get_type(), loc.get_id(),
sim.get_world().get_number_persons(loc.get_id()),
persons_per_infection_state));
}
return location_information;
}
@@ -131,10 +135,12 @@ int main()

//add persons from world 0 to vector
for (auto& person : world1.get_persons()) {
persons.push_back(person);
mio::abm::PersonId new_id{static_cast<uint32_t>(persons.size())};
persons.emplace_back(person, new_id);
}

auto world2 = mio::abm::World(num_age_groups, 1);

//Household groups for world 2
auto single_hh_group_w2 = mio::abm::HouseholdGroup();
single_hh_group_w2.add_households(single_hh, 6);
@@ -151,36 +157,37 @@ int main()

//add persons from world 1 to vector
for (auto& person : world2.get_persons()) {
persons.push_back(person);
mio::abm::PersonId new_id{static_cast<uint32_t>(persons.size())};
persons.emplace_back(person, new_id);
}

//Create locations for both worlds
//world 0
auto event_w1 = world1.add_location(mio::abm::LocationType::SocialEvent);
world1.get_individualized_location(event_w1).get_infection_parameters().set<mio::abm::MaximumContacts>(10);
world1.get_location(event_w1).get_infection_parameters().set<mio::abm::MaximumContacts>(10);
auto hospital_w1 = world1.add_location(mio::abm::LocationType::Hospital);
world1.get_individualized_location(hospital_w1).get_infection_parameters().set<mio::abm::MaximumContacts>(10);
world1.get_location(hospital_w1).get_infection_parameters().set<mio::abm::MaximumContacts>(10);
auto icu_w1 = world1.add_location(mio::abm::LocationType::ICU);
world1.get_individualized_location(icu_w1).get_infection_parameters().set<mio::abm::MaximumContacts>(5);
world1.get_location(icu_w1).get_infection_parameters().set<mio::abm::MaximumContacts>(5);
auto shop_w1 = world1.add_location(mio::abm::LocationType::BasicsShop);
world1.get_individualized_location(shop_w1).get_infection_parameters().set<mio::abm::MaximumContacts>(20);
world1.get_location(shop_w1).get_infection_parameters().set<mio::abm::MaximumContacts>(20);
auto school_w1 = world1.add_location(mio::abm::LocationType::School);
world1.get_individualized_location(school_w1).get_infection_parameters().set<mio::abm::MaximumContacts>(20);
world1.get_location(school_w1).get_infection_parameters().set<mio::abm::MaximumContacts>(20);
auto work_w1 = world1.add_location(mio::abm::LocationType::Work);
world1.get_individualized_location(work_w1).get_infection_parameters().set<mio::abm::MaximumContacts>(10);
world1.get_location(work_w1).get_infection_parameters().set<mio::abm::MaximumContacts>(10);
//World 1
auto event_w2 = world2.add_location(mio::abm::LocationType::SocialEvent);
world2.get_individualized_location(event_w2).get_infection_parameters().set<mio::abm::MaximumContacts>(10);
world2.get_location(event_w2).get_infection_parameters().set<mio::abm::MaximumContacts>(10);
auto hospital_w2 = world2.add_location(mio::abm::LocationType::Hospital);
world2.get_individualized_location(hospital_w2).get_infection_parameters().set<mio::abm::MaximumContacts>(10);
world2.get_location(hospital_w2).get_infection_parameters().set<mio::abm::MaximumContacts>(10);
auto icu_w2 = world2.add_location(mio::abm::LocationType::ICU);
world2.get_individualized_location(icu_w2).get_infection_parameters().set<mio::abm::MaximumContacts>(5);
world2.get_location(icu_w2).get_infection_parameters().set<mio::abm::MaximumContacts>(5);
auto shop_w2 = world2.add_location(mio::abm::LocationType::BasicsShop);
world2.get_individualized_location(shop_w2).get_infection_parameters().set<mio::abm::MaximumContacts>(20);
world2.get_location(shop_w2).get_infection_parameters().set<mio::abm::MaximumContacts>(20);
auto school_w2 = world2.add_location(mio::abm::LocationType::School);
world2.get_individualized_location(school_w2).get_infection_parameters().set<mio::abm::MaximumContacts>(20);
world2.get_location(school_w2).get_infection_parameters().set<mio::abm::MaximumContacts>(20);
auto work_w2 = world2.add_location(mio::abm::LocationType::Work);
world2.get_individualized_location(work_w2).get_infection_parameters().set<mio::abm::MaximumContacts>(10);
world2.get_location(work_w2).get_infection_parameters().set<mio::abm::MaximumContacts>(10);

auto start_date = mio::abm::TimePoint(0);
auto end_date = mio::abm::TimePoint(0) + mio::abm::days(30);
@@ -192,52 +199,53 @@ int main()
for (auto& person : persons) {
mio::abm::InfectionState infection_state = mio::abm::InfectionState(
mio::DiscreteDistribution<size_t>::get_instance()(mio::thread_local_rng(), infection_distribution));
auto rng = mio::abm::Person::RandomNumberGenerator(mio::thread_local_rng(), person);
auto rng = mio::abm::PersonalRandomNumberGenerator(mio::thread_local_rng(), person);
if (infection_state != mio::abm::InfectionState::Susceptible) {
person.add_new_infection(mio::abm::Infection(rng, mio::abm::VirusVariant::Wildtype, person.get_age(),
world1.parameters, start_date, infection_state));
}
// Assign locations to persons from world 1
if (person.get_assigned_location_world_id(mio::abm::LocationType::Home) == world1.get_id()) {
person.set_assigned_location(event_w1);
person.set_assigned_location(shop_w1);
person.set_assigned_location(hospital_w1);
person.set_assigned_location(icu_w1);
person.set_assigned_location(mio::abm::LocationType::SocialEvent, event_w1, world1.get_id());
person.set_assigned_location(mio::abm::LocationType::BasicsShop, shop_w1, world1.get_id());
person.set_assigned_location(mio::abm::LocationType::Hospital, hospital_w1, world1.get_id());
person.set_assigned_location(mio::abm::LocationType::ICU, icu_w1, world1.get_id());
if (person.get_age() == age_group_children) {
person.set_assigned_location(school_w1);
person.set_assigned_location(mio::abm::LocationType::School, school_w1, world1.get_id());
}
if (person.get_age() == age_group_adults) {
//10% of adults in world 0 work in world 1
size_t work_world = mio::DiscreteDistribution<size_t>::get_instance()(mio::thread_local_rng(),
std::vector<double>{0.9, 0.1});
if (work_world == 1) { //person works in other world
person.set_assigned_location(work_w2);
person.set_assigned_location(mio::abm::LocationType::Work, work_w2, world2.get_id());
//add person to edge parameters
params_e1.push_back(person.get_person_id());
params_e1.push_back(person.get_id().get());
}
else { //person works in same world
person.set_assigned_location(work_w1);
person.set_assigned_location(mio::abm::LocationType::Work, work_w1, world1.get_id());
}
}
}
else {
person.set_assigned_location(event_w2);
person.set_assigned_location(shop_w2);
person.set_assigned_location(hospital_w2);
person.set_assigned_location(icu_w2);
person.set_assigned_location(mio::abm::LocationType::SocialEvent, event_w2, world2.get_id());
person.set_assigned_location(mio::abm::LocationType::BasicsShop, shop_w2, world2.get_id());
person.set_assigned_location(mio::abm::LocationType::Hospital, hospital_w2, world2.get_id());
person.set_assigned_location(mio::abm::LocationType::ICU, icu_w2, world2.get_id());
if (person.get_age() == age_group_children) {
person.set_assigned_location(school_w2);
person.set_assigned_location(mio::abm::LocationType::School, school_w2, world2.get_id());
}
if (person.get_age() == age_group_adults) {
//20% of adults in world 1 work in world 0
size_t work_world = mio::DiscreteDistribution<size_t>::get_instance()(mio::thread_local_rng(),
std::vector<double>{0.2, 0.8});
if (work_world == 0) { //person works in other world
person.set_assigned_location(work_w1);
person.set_assigned_location(mio::abm::LocationType::Work, work_w1, world1.get_id());
//add person to edge parameters
params_e2.push_back(person.get_person_id());
params_e2.push_back(person.get_id().get());
}
else { //person works in same world
person.set_assigned_location(work_w2);
person.set_assigned_location(mio::abm::LocationType::Work, work_w2, world2.get_id());
}
}
}
@@ -259,5 +267,8 @@ int main()
auto sim = mio::make_abm_graph_sim<HistoryType>(start_date, mio::abm::hours(12), std::move(graph));
DavidKerkmann marked this conversation as resolved.
Show resolved Hide resolved
sim.advance(end_date);

auto& log_n1 = std::get<0>(sim.get_graph().nodes()[0].property.get_history()).get_log();
auto& log_n2 = std::get<0>(sim.get_graph().nodes()[1].property.get_history()).get_log();

return 0;
}
26 changes: 11 additions & 15 deletions cpp/models/abm/world.cpp
Original file line number Diff line number Diff line change
@@ -73,18 +73,6 @@ PersonId World::add_person(Person&& person)
return new_id;
}

// Person& World::add_external_person(Location& loc, AgeGroup age)
// {
// assert(age.get() < parameters.get_num_groups());
// uint32_t person_id = static_cast<uint32_t>(m_persons.size());
// m_persons.push_back(std::make_unique<Person>(m_rng, loc, age, person_id));
// m_activeness_statuses.push_back(false);
// auto& person = *m_persons.back();
// person.set_assigned_location(m_cemetery_id);
// loc.add_person(person);
// return person;
// }

void World::evolve(TimePoint t, TimeSpan dt)
{
begin_step(t, dt);
@@ -96,10 +84,16 @@ void World::evolve(TimePoint t, TimeSpan dt)

void World::interaction(TimePoint t, TimeSpan dt)
{
if (t.days() == 14) {
std::cout << "stop\n";
}
const uint32_t num_persons = static_cast<uint32_t>(m_persons.size());
PRAGMA_OMP(parallel for)
for (uint32_t person_id = 0; person_id < num_persons; ++person_id) {
if (m_activeness_statuses[person_id]) {
if (person_id == 41 && t.days() == 14) {
std::cout << "person= " << person_id << std::endl;
}
interact(person_id, t, dt);
}
}
@@ -256,9 +250,11 @@ void World::compute_exposure_caches(TimePoint t, TimeSpan dt)
for (size_t i = 0; i < num_persons; ++i) {
const Person& person = m_persons[i];
const auto location = person.get_location().get();
mio::abm::add_exposure_contribution(m_air_exposure_rates_cache[location],
m_contact_exposure_rates_cache[location], person,
get_location(person.get_id()), t, dt);
if (person.get_location_world_id() == m_id) {
mio::abm::add_exposure_contribution(m_air_exposure_rates_cache[location],
m_contact_exposure_rates_cache[location], person,
get_location(person.get_id()), t, dt);
}
} // implicit taskloop barrier
} // implicit single barrier
}
12 changes: 8 additions & 4 deletions cpp/models/abm/world.h
Original file line number Diff line number Diff line change
@@ -75,10 +75,10 @@ class World
*/
World(const Parameters& params, int world_id = 0)
: parameters(params.get_num_groups())
, m_id(world_id)
, m_trip_list()
, m_use_migration_rules(true)
, m_cemetery_id(add_location(LocationType::Cemetery))
, m_id(world_id)
{
parameters = params;
}
@@ -91,6 +91,7 @@ class World
, m_is_local_population_cache_valid(false)
, m_are_exposure_caches_valid(false)
, m_exposure_caches_need_rebuild(true)
, m_id(world_id)
, m_persons(other.m_persons)
, m_locations(other.m_locations)
, m_activeness_statuses(other.m_activeness_statuses)
@@ -101,7 +102,6 @@ class World
, m_migration_rules(other.m_migration_rules)
, m_cemetery_id(other.m_cemetery_id)
, m_rng(other.m_rng)
, m_id(world_id)
{
}
World& operator=(const World&) = default;
@@ -380,7 +380,8 @@ class World
size_t get_subpopulation(LocationId location, TimePoint t, InfectionState state) const
{
return std::count_if(m_persons.begin(), m_persons.end(), [&](auto&& p) {
return p.get_location() == location && p.get_infection_state(t) == state;
return p.get_location_world_id() == m_id && p.get_location() == location &&
p.get_infection_state(t) == state;
});
}

@@ -485,6 +486,9 @@ class World
void change_activeness(PersonId person_id)
{
m_activeness_statuses[person_id.get()] = !m_activeness_statuses[person_id.get()];
if (get_person(person_id).get_location_world_id() != m_id && m_activeness_statuses[person_id.get()]) {
std::cout << "Problem\n";
}
}

/**
@@ -584,6 +588,7 @@ class World
bool m_are_exposure_caches_valid = false;
bool m_exposure_caches_need_rebuild = true;

int m_id; ///< World id. Is only used for abm graph model or hybrid model.
std::vector<Person> m_persons; ///< Vector of every Person.
std::vector<Location> m_locations; ///< Vector of every Location.
std::vector<bool> m_activeness_statuses; ///< Vector with activeness status for every person
@@ -598,7 +603,6 @@ class World
m_migration_rules; ///< Rules that govern the migration between Location%s.
LocationId m_cemetery_id; // Central cemetery for all dead persons.
RandomNumberGenerator m_rng; ///< Global random number generator
int m_id; ///< World id. Is only used for abm graph model or hybrid model.
};

} // namespace abm
23 changes: 19 additions & 4 deletions cpp/models/graph_abm/graph_abm_mobility.h
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ class ABMSimulationNode
}

/**
*@brief get abm simulation in this node.
*@brief Get abm simulation in this node.
*/
Sim& get_simulation()
{
@@ -64,6 +64,18 @@ class ABMSimulationNode
return m_simulation;
}

/**
* @brief Get history object(s) in this node.
*/
std::tuple<History...>& get_history()
{
return m_history;
}
const std::tuple<History...>& get_history() const
{
return m_history;
}

/**
* @brief advances the simulation in this node by t+dt and logs information in History object(s)
* @tparam History history object type(s)
@@ -236,9 +248,11 @@ class ABMMobilityEdge
// invalidate both worlds' cache
node_to.get_simulation().get_world().invalidate_cache();
node_from.get_simulation().get_world().invalidate_cache();
// change activeness status for commuted person
node_to.get_simulation().get_world().change_activeness(p);
node_from.get_simulation().get_world().change_activeness(p);
if (target_world_id != current_world_id) {
// change activeness status for commuted person
node_to.get_simulation().get_world().change_activeness(p);
node_from.get_simulation().get_world().change_activeness(p);
}
// only one mobility rule per person can be applied
break;
}
@@ -275,6 +289,7 @@ void apply_mobility(abm::TimePoint t, abm::TimeSpan /*dt*/, ABMMobilityEdge<Hist
template <class... History>
void evolve_model(abm::TimePoint t, abm::TimeSpan dt, ABMSimulationNode<History...>& node)
DavidKerkmann marked this conversation as resolved.
Show resolved Hide resolved
{
std::cout << "t= " << t.days() << std::endl;
node.evolve(t, dt);
}

Loading