Skip to content

Commit

Permalink
#000: Shubham: upgrade geo and add 10k and 20k standalone configs
Browse files Browse the repository at this point in the history
  • Loading branch information
i-am-chauhan committed Sep 22, 2023
1 parent bb4fc4a commit d1e0a83
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 22 deletions.
2 changes: 1 addition & 1 deletion engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ futures = "0.3.4"
tokio = { version = "1.20.1", features = ["full"] }
time = { version = "0.3.14", features = ["formatting"] }
geo-types = "0.7.7"
geo = "0.23.0"
geo = "0.26.0"
geojson = "0.24.0"
plotters = { version = "0.3.3", default-features = false, features = ["bitmap_backend", "bitmap_encoder"] }
log = "0.4"
Expand Down
45 changes: 45 additions & 0 deletions engine/config/10K_standalone.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"output_file": "simulation_10K_standalone_config",
"population": {
"Auto": {
"number_of_agents": 10000,
"public_transport_percentage": 0.2,
"working_percentage": 0.7
}
},
"disease": {
"death_rate": 0.035,
"percentage_asymptomatic_population": 0.3,
"exposed_duration": 48,
"last_day": 26,
"asymptomatic_last_day": 9,
"mild_infected_last_day": 12,
"regular_transmission_rate": 0.25,
"pre_symptomatic_duration": 48,
"percentage_severe_infected_population": 0.3,
"high_transmission_start_day": 6,
"high_transmission_rate": 0.25,
"regular_transmission_start_day": 5
},
"geography_parameters": {
"grid_size": 250,
"hospital_beds_percentage": 0.003
},
"end_of_migration": 336,
"reduced_travel_percentage": 0.0005,
"hours": 1080,
"interventions": [
{
"Lockdown": {
"at_number_of_infections": 100,
"essential_workers_population": 0.1
}
}
],
"starting_infections": {
"exposed": 1,
"infected_mild_asymptomatic": 0,
"infected_mild_symptomatic": 0,
"infected_severe": 0
}
}
45 changes: 45 additions & 0 deletions engine/config/20K_standalone.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"output_file": "simulation_20K_standalone_config",
"population": {
"Auto": {
"number_of_agents": 20000,
"public_transport_percentage": 0.2,
"working_percentage": 0.7
}
},
"disease": {
"death_rate": 0.035,
"percentage_asymptomatic_population": 0.3,
"exposed_duration": 48,
"last_day": 26,
"asymptomatic_last_day": 9,
"mild_infected_last_day": 12,
"regular_transmission_rate": 0.25,
"pre_symptomatic_duration": 48,
"percentage_severe_infected_population": 0.3,
"high_transmission_start_day": 6,
"high_transmission_rate": 0.25,
"regular_transmission_start_day": 5
},
"geography_parameters": {
"grid_size": 400,
"hospital_beds_percentage": 0.003
},
"end_of_migration": 336,
"reduced_travel_percentage": 0.0005,
"hours": 1080,
"interventions": [
{
"Lockdown": {
"at_number_of_infections": 100,
"essential_workers_population": 0.1
}
}
],
"starting_infections": {
"exposed": 1,
"infected_mild_asymptomatic": 0,
"infected_mild_symptomatic": 0,
"infected_severe": 0
}
}
32 changes: 17 additions & 15 deletions engine/src/allocation_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,20 @@ impl CitizenLocationMap {
disease_handler: &T,
) {
csv_record.clear();
let updates: Vec<((Point, Point), Citizen, bool)> = self.par_iter().map(|(cell, agent)| {
let mut rng_thread = RandomWrapper::new();
let mut current_agent = *agent;
let infection_status = current_agent.state_machine.is_infected();
let point = current_agent.perform_operation(*cell, simulation_hour, &self.grid, self, &mut rng_thread, disease_handler);
((*cell, point), current_agent, infection_status)
}).collect();
let updates: Vec<((Point, Point), Citizen, bool)> = self
.par_iter()
.map(|(cell, agent)| {
let mut rng_thread = RandomWrapper::new();
let mut current_agent = *agent;
let infection_status = current_agent.state_machine.is_infected();
let point =
current_agent.perform_operation(*cell, simulation_hour, &self.grid, self, &mut rng_thread, disease_handler);
((*cell, point), current_agent, infection_status)
})
.collect();
updates.iter().for_each(|pair| {
let old_cell = pair.0.0;
let new_cell = pair.0.1;
let old_cell = pair.0 .0;
let new_cell = pair.0 .1;
let agent = pair.1;
let mut new_location = &new_cell;
let agent_at_new_cell = *self.upcoming_locations.entry(new_cell).or_insert(agent);
Expand Down Expand Up @@ -346,7 +350,7 @@ impl CitizenLocationMap {

pub fn lock_city(&mut self, hr: Hour) {
info!("Locking the city. Hour: {}", hr);
self.iter_mut().for_each(|(_, r)| {
self.iter_mut().for_each(|(_, r)| {
if !r.is_essential_worker() {
(*r).set_isolation(true);
}
Expand All @@ -355,7 +359,7 @@ impl CitizenLocationMap {

pub fn unlock_city(&mut self, hr: Hour) {
info!("Unlocking city. Hour: {}", hr);
self.iter_mut().for_each(|(_, r)| {
self.iter_mut().for_each(|(_, r)| {
if r.is_isolated() {
(*r).set_isolation(false);
}
Expand All @@ -377,7 +381,7 @@ impl CitizenLocationMap {
}

pub(crate) fn vaccinate(&mut self, vaccination_percentage: f64, rng: &mut RandomWrapper) {
self.iter_mut().for_each(|( _, r)| {
self.iter_mut().for_each(|(_, r)| {
if r.state_machine.is_susceptible() && rng.get().gen_bool(vaccination_percentage) {
(*r).set_vaccination(true);
}
Expand All @@ -388,9 +392,7 @@ impl CitizenLocationMap {
self.current_locations.len() as Count
}

pub fn iter_upcoming_locations(
&self,
) -> Iter<'_, Point, Citizen> {
pub fn iter_upcoming_locations(&self) -> Iter<'_, Point, Citizen> {
self.upcoming_locations.iter()
}

Expand Down
8 changes: 4 additions & 4 deletions engine/src/epidemiology_simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use opentelemetry::trace::{FutureExt, Span, TraceContextExt, Tracer};
use opentelemetry::{global, Context, KeyValue};

use crate::allocation_map::CitizenLocationMap;
use crate::geography;
use crate::geography::Point;
use crate::interventions::hospital::BuildNewHospital;
use crate::interventions::lockdown::LockdownIntervention;
Expand All @@ -53,7 +54,6 @@ use crate::travel::commute::Commuter;
use crate::travel::commute::CommutersByRegion;
use crate::travel::migration::{EngineMigrationPlan, Migrator, MigratorsByRegion};
use crate::utils::util::{counts_at_start, output_file_format};
use crate::{geography};

pub struct Epidemiology<T: DiseaseHandler + Sync> {
pub citizen_location_map: CitizenLocationMap,
Expand Down Expand Up @@ -121,7 +121,7 @@ impl<T: DiseaseHandler + Sync> Epidemiology<T> {
let csv_listener = CsvListener::new(counts_file_name);

let hotspot_tracker = Hotspot::new();
let intervention_reporter = InterventionReporter::new(format!("{output_file_format}_interventions.json" ));
let intervention_reporter = InterventionReporter::new(format!("{output_file_format}_interventions.json"));
let mut listeners_vec: Vec<Box<dyn Listener>> =
vec![Box::new(csv_listener), Box::new(hotspot_tracker), Box::new(intervention_reporter)];

Expand Down Expand Up @@ -156,7 +156,7 @@ impl<T: DiseaseHandler + Sync> Epidemiology<T> {
let hospital_intervention = BuildNewHospital::init(config);
let essential_workers_population = lock_down_details.get_essential_workers_percentage();

citizen_location_map.iter_mut().for_each(| r| {
citizen_location_map.iter_mut().for_each(|r| {
(*r.1).assign_essential_worker(essential_workers_population, rng);
});
Interventions { vaccinate: vaccinations, lockdown: lock_down_details, build_new_hospital: hospital_intervention }
Expand Down Expand Up @@ -410,7 +410,7 @@ impl<T: DiseaseHandler + Sync> Epidemiology<T> {

if is_migration_enabled {
let migration_start_time = Instant::now();
let (mut incoming, ) = join!(received_migrators.unwrap());
let (mut incoming,) = join!(received_migrators.unwrap());
total_receive_migration_sync_time += migration_start_time.elapsed().as_millis();
n_incoming += incoming.len();
n_outgoing += outgoing.len();
Expand Down
2 changes: 1 addition & 1 deletion engine/src/kafka/kafka_consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::error::Error;
use common::config::request::Request;
use futures::StreamExt;
use opentelemetry::trace::{FutureExt, TraceContextExt, Tracer};
use opentelemetry::{Context, global};
use opentelemetry::{global, Context};
use rdkafka::consumer::Consumer;
use rdkafka::consumer::{MessageStream, StreamConsumer};
use rdkafka::error::KafkaError;
Expand Down
2 changes: 1 addition & 1 deletion engine/src/travel/commute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
mod commuter;
mod commuters_by_region;

use common::models::custom_types::Hour;
use common::models::travel_plan::TravelPlan;
use common::models::CommutePlan;
use rdkafka::consumer::MessageStream;
use common::models::custom_types::Hour;

use crate::models::constants;
use crate::models::events::Tick;
Expand Down

0 comments on commit d1e0a83

Please sign in to comment.