Closed leenr01 closed 1 year ago
Hi,
I suggest that you send this model and request for advices either in the discussions (I will convert it to discussion anyway) or -- better -- on the mailing list. And it would be more effective if you explain what you intend to do with this grid with 25k agents: if it is only for holding values and serving as an "environment" to the agents, most can be done with fields rather than grids. If problems with GAMA are to be uncovered when measuring performances, feel free to open another issue on these problems.
Thanks ! Alexis
Describe the bug Creating the environment by using a matrix (https://gama-platform.org/wiki/GridSpecies#grid-from-a-matrix) is useful for defined geometries but extremely slow even with dealing with around 2000 agents. The code is very slow to the point that taking readings is not possible.
To Reproduce Steps to reproduce the behavior:
Files Matrix8P.csv
Desktop:
Additional context Any recommendations for speeding up the current code are highly appreciated. The code describes the spread of a disease in a population.
model Project / author: Leen Alrawas (leenr2001@gmail.com) /
global {
// Variables to control the grid> patchesMap; // the numbered patches
map<int, list> tunnelsMap; // the numbered tunnels
list tunnels; // List of tunnels
list entrance; // List of patch entrances
list exit; // List of patch exits
list patches <- []; // list of cells in all patches
map<int, int> PatchesArea; // list of areas of patches
int PatchArea; // patch area
int matrixSize <- 500; // grid size geometry shape <- square(matrixSize); // grid shape file my_csv_file <- csv_file("C:/Users/leenr/Desktop/Matrix8P.csv",","); // change the location of the excel file //file my_map <- gif_file("C:/Users/leenr/Desktop/my_map.gif"); // change the location of the gif file matrix data <- matrix(my_csv_file); int numOfPatches <- 8; int numOfTunnels <- 134; map<int, list
// Variables to control the population int neighbours_size <- 1; // agents at distace of "neighbours_size" cells are considered neighbours float P1 <- 0.06; float P2 <- 0.505; float P3 <- 1 - P2 - P1; float Cn <- 0.649; float C <- 0.95 Cn + 0.05; list initialSList <- [
int(C 30000.75P1),int(C30000.386P2),int(C30000.632P3),int(C30000.080P3),
int(C30000.287P3),int(C30000.25P1),int(C30000.495P2),int(C30000.119*P2)
];
//list initialSList <- [90,390,550,70,250,30,500,120]; // Initial Susceptible population sizes for each patch
list initialIList <- [0, 5, 0, 5, 0, 5, 0, 5]; // Initial Infected population sizes for each patch
list initialVList; // Initial vaccinated population sizes
list sick_agents;// <- [63, 52, 83, 22, 63, 22, 63, 52]; // population with chronic or health conditions - per patch
map<int, float> crowd_index; // population density
list AgeMeanList <- [40.0, 50.0, 60.0, 60.0, 60.0, 40.0, 50.0, 50.0]; // Age mean for each patch
list AgeSDList; // Age standard deviation for each patch
map<int, float> age_index; // [agents(+60) / all agents] - per patch
map<int, float> health_index <- [1::0.173, 2::0.173, 3::0.173, 4::0.173,
5::0.173, 6::0.173, 7::0.173, 8::0.173]; // [sick_agents / all agents] - per patch
// Variables to control the mobility list local_mobility_list <- [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]; // ratio of agents allowed to move locally - per patch
int stay_time <- 10; // time being in a foreign patch (in cycles)
float mobility_probability <- 1.0;
// Variables to control the disease int safe_exposure_time <- 5; // time being exposed before becoming infectious (in cycles) float alpha <- 0.3; // parameters in flowchart // float betaSUS <- 0.5; // float betaVAC <- 0.1; map<int, float> betaSUSList; // list of betaSUS for all patches (determined by age and health indexes) map<int, float> betaVACList; // list of betaVAC for all patches (determined by age and health indexes) float theta <- 0.05; float gamma <- 0.01; int CounterofVac <- 0; // number of vaccinated people since beginning of simulation int CounterofInf; // number of infected people since beginning of simulation list efficacy_list <- [0.9, 0.7, 0.5, 0.5, 0.5, 0.9, 0.7, 0.7]; // list of vaccination efficacies (lambda in flowchart)
float vaccination_percentage <- 0.25; // the percentage of the whole population who are vaccinated
map<int, int> NHI_local; // number of susceptible who have been infected - per patch map<int, int> NAI_local; // number of active infected agents - per patch map<int, float> R0_local; // Basic Reproduction Number - defined as the max of NHI/NAI - per patch float R0_global <- 0.0; // defined as the average of R0_local values map<int, int> I_of_peak_local; // peak of infection is maximum number of infected agents int I_of_peak_global <- 0; map<int, int> time_of_peak_local;
int time_of_peak_global <- 0; map<int, int> R0_max_time; // time of each R0_local float R01; // individual R0 values of patches float R02; float R03; float R04; float R05; float R06; float R07; float R08;
// Set colors in grid ask sir_grid { grid_value <- float(data[grid_x, grid_y]); do setColor; }
// Set patch color list patchCell <- (sir_grid where (each.grid_value = i));
ask patchCell {
color <- #black;
}
// Initialize values add patchCell at: i to: patchesMap; //number the patches add 0.0 at: i to: NHI_local; add 0.0 at: i to: NAI_local; add 0.0 at: i to: I_of_peak_local; add 0.0 at: i to: R0_local; add 0 at: i to: R0_max_time; add 0 at: i to: time_of_peak_local; //add 50 to: AgeMeanList; // uniform mean age for all patches add 15 to: AgeSDList; // age standard deviation for all patches
// Set tunnel color ask tunnelCell { color <- #slategrey; }
// Initiate population
loop i from: 1 to: numOfPatches { create Host number: (initialSList at (i - 1)) { //create initial Susceptible agents is_susceptible <- true; is_exposed <- false; is_infected <- false; is_immune <- false; is_vac <- false; color <- #green; currentPatch <- (patchesMap at i); originalPatch <- (patchesMap at i); local_mobility <- (local_mobility_list at (i - 1)); time_in_patch <- 0; efficacy <- (efficacy_list at (i - 1)); mean_age <- (AgeMeanList at (i - 1)); SD_age <- (AgeSDList at (i - 1)); }
//Grid used to discretize space grid sir_grid width: matrixSize height: matrixSize neighbors: 8 {
// Set entrance color action setColor { if (grid_value = numOfTunnels + numOfPatches + 5) { color <- #orange; } // Set exit color if (grid_value = numOfTunnels + numOfPatches + 6) { color <- #brown; } } }
}
// Species host which represents the host of the disease species Host skills: [moving] {
// Varibales to control agent state and age bool is_susceptible <- true; bool is_exposed <- false; bool is_infected <- false; bool is_immune <- false; bool is_vac <- false; bool infectious <- false; // exposed can be infectious after some defined time bool active <- false; // number of infectious agents rgb color <- #green; float mean_age; float SD_age; int age; float age_risk;
// Variables to control agent location originalPatch;
list currentPatch;
sir_grid myPlace;
list myEntrance;
list current_tunnel;
sir_grid targetEntrance;
int time_in_patch;
bool Leave <- false;
list
// Variables to control agent mobility float local_mobility;
float travel_status;
// Variables to control agent neighbours int ngb_infectious_number function: self neighbors_at (neighbours_size) count (each.is_infected or each.infectious); int ngb_susceptible_number function: self neighbors_at (neighbours_size + 1) count (each.is_susceptible); int ngb_exposed_number function: self neighbors_at (neighbours_size) count (each.is_exposed); list ngb_susceptible function: self neighbors_at (neighbours_size) where (each.is_susceptible);
list ngb_infected function: self neighbors_at (neighbours_size) where (each.is_infected or each.infectious);
list ngb_exposed function: self neighbors_at (neighbours_size + 1) where (each.is_exposed);
// Variables to control the disease int time_being_exposed; // the time an agent spends being exposed float efficacy; int patch_of_vac; // index to vaccinate an agent randomly
float betaSUS; float betaVAC;
// Shape of agents
aspect basic { draw circle(0.5) color: color; }
// ACTIONS to describe mobility
// leave patch when the time in patch reaches the stay time reflex LeavePatch when: (time_in_patch >= stay_time) and (currentPatch!=originalPatch) and (myPlace in patches) { if(!is_infected){ // leave only if not infected Leave <- true; do moveToExit;
}
}
// REFLEXES to control the disease state
/ reflex has_infected when: is_infected { // reflex of infected who infect other agents if (ngb_exposed_number > 0) { list new_exposed <- ngb_exposed where (each.time_being_exposed <= 1);
if (new_exposed != nil) {
active <- true;
}
}
} / // Alternative definition for active
}
experiment Simulation_SA_Project type: gui {
}
experiment Optimization type: batch repeat: 2 until: (Host count (each.is_infected) <= 5 or cycle=2) {
}