Skip to content

Commit

Permalink
Fixed the comorbidities calculation. (#61)
Browse files Browse the repository at this point in the history
* Fixed the comorbidities calculation to include diseases free individuals.
  • Loading branch information
israel-vieira authored Jun 24, 2022
1 parent c272385 commit 268a968
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

project(HealthGPS
VERSION 1.1.2.0
VERSION 1.1.3.0
DESCRIPTION "Global Health Policy Simulation model (Health-GPS)"
HOMEPAGE_URL "/~https://github.com/imperialCHEPI/healthgps"
LANGUAGES CXX)
Expand Down
2 changes: 1 addition & 1 deletion src/HealthGPS.Console/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ std::unique_ptr<hgps::InterventionScenario> create_intervention_scenario(
{
using namespace hgps;

fmt::print(fg(fmt::color::light_coral), "\nIntervention policy: {}.\n", info.identifier);
fmt::print(fg(fmt::color::light_coral), "\nIntervention policy: {}.\n\n", info.identifier);
auto period = PolicyInterval(info.active_period.start_time, info.active_period.finish_time);
auto risk_impacts = std::vector<PolicyImpact>{};
for (auto& item : info.impacts) {
Expand Down
10 changes: 5 additions & 5 deletions src/HealthGPS.Console/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ int main(int argc, char* argv[])
auto runtime = 0.0;

// GCC thread initialisation bug reverses derived to base-class, when declared in line
fmt::print(fg(fmt::color::cyan), "\nStarting baseline simulation with {} trials ...\n\n", config.trial_runs);
auto baseline_rnd = std::make_unique<hgps::MTRandom32>();
auto baseline_scenario = std::make_unique<BaselineScenario>(channel);
auto baseline = HealthGPS{
SimulationDefinition{ model_input, std::move(baseline_scenario) , std::move(baseline_rnd) },
factory, event_bus };

fmt::print(fg(fmt::color::cyan), "\nStarting intervention simulation with {} trials ...\n\n", config.trial_runs);
if (config.has_active_intervention) {
fmt::print(fg(fmt::color::cyan), "\nStarting intervention simulation with {} trials ...\n", config.trial_runs);
auto policy_scenario = create_intervention_scenario(channel, config.intervention);
auto policy_rnd = std::make_unique<hgps::MTRandom32>();
auto intervention = HealthGPS{
Expand All @@ -141,7 +142,6 @@ int main(int argc, char* argv[])
worker.join();
}
else {
fmt::print(fg(fmt::color::cyan), "\nStarting baseline simulation with {} trials ...\n\n", config.trial_runs);
channel.close(); // Will not store any message
auto worker = std::jthread{ [&runtime, &executive, &baseline, &config, &done] {
runtime = executive.run(baseline, config.trial_runs);
Expand All @@ -156,16 +156,16 @@ int main(int argc, char* argv[])
}

std::this_thread::sleep_for(std::chrono::milliseconds(100));
fmt::print(fg(fmt::color::light_green), "Completed, elapsed time : {}ms\n\n", runtime);
fmt::print(fg(fmt::color::light_green), "\nCompleted, elapsed time : {}ms\n\n", runtime);
}
catch (const std::exception& ex) {
fmt::print(fg(fmt::color::red), "\n\nFailed with message - {}.\n", ex.what());
}

event_monitor.stop();
fmt::print("\n\n");
fmt::print(fg(fmt::color::yellow) | fmt::emphasis::bold, "Goodbye");
fmt::print("\n\n");
fmt::print(fg(fmt::color::yellow) | fmt::emphasis::bold, "Goodbye.");
fmt::print(" {}.\n\n", getTimeNowStr());

return EXIT_SUCCESS;
}
22 changes: 10 additions & 12 deletions src/HealthGPS/analysis_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace hgps {
}

auto comorbidity = std::map<unsigned int, ResultByGender>{};
for (auto i = 1u; i <= comorbidities_; i++)
for (auto i = 0u; i <= comorbidities_; i++)
{
comorbidity.emplace(i, ResultByGender{});
}
Expand Down Expand Up @@ -163,17 +163,15 @@ namespace hgps {
}
}

if (comorbidity_number > 0) {
if (comorbidity_number > comorbidities_) {
comorbidity_number = comorbidities_;
}
if (comorbidity_number > comorbidities_) {
comorbidity_number = comorbidities_;
}

if (entity.gender == core::Gender::male) {
comorbidity[comorbidity_number].male++;
}
else {
comorbidity[comorbidity_number].female++;
}
if (entity.gender == core::Gender::male) {
comorbidity[comorbidity_number].male++;
}
else {
comorbidity[comorbidity_number].female++;
}
}

Expand Down Expand Up @@ -208,7 +206,7 @@ namespace hgps {
for (const auto& item : comorbidity) {
result.comorbidity.emplace(item.first, ResultByGender{
.male = item.second.male * 100.0 / males_count,
.female = item.second.female * 100.0 / males_count
.female = item.second.female * 100.0 / females_count
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/HealthGPS/population.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "population.h"
#include <execution>

namespace hgps {
Population::Population(const std::size_t size)
Expand All @@ -14,7 +15,7 @@ namespace hgps {
}

std::size_t Population::current_active_size() const noexcept {
auto active_pop_size = std::count_if(people_.cbegin(),people_.cend(),
auto active_pop_size = std::count_if(std::execution::par, people_.cbegin(),people_.cend(),
[](const auto& p) { return p.is_active(); });

return active_pop_size;
Expand Down

0 comments on commit 268a968

Please sign in to comment.