From 56f3eae15627f8b029d05adbb15b51b78e368466 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Mon, 24 Mar 2025 17:03:26 -0400 Subject: [PATCH] Model: rename grids field --- src/model.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/model.rs b/src/model.rs index e908626..2668756 100644 --- a/src/model.rs +++ b/src/model.rs @@ -13,8 +13,8 @@ use std::{path::Path, time::Instant}; // Top-level simulation class. pub struct Model { - // The grid they move on. - grids: Vec, + // per-population grid (one for each population) + population_grids: Vec, // Attraction table governs interaction across populations attraction_table: Vec>, @@ -39,7 +39,7 @@ impl Model { const REPULSION_FACTOR_STD: f32 = 0.1; pub fn print_configurations(&self) { - for (i, grid) in self.grids.iter().enumerate() { + for (i, grid) in self.population_grids.iter().enumerate() { println!("Grid {}: {}", i, grid.config); } println!("Attraction table: {:#?}", self.attraction_table); @@ -84,7 +84,7 @@ impl Model { } Model { - grids, + population_grids: grids, attraction_table, diffusivity, iteration: 0, @@ -108,14 +108,18 @@ impl Model { let mut time_per_agent_list: Vec = Vec::new(); let mut time_per_step_list: Vec = Vec::new(); - let agents_num: usize = self.grids.iter().map(|grid| grid.agents.len()).sum(); + let agents_num: usize = self + .population_grids + .iter() + .map(|grid| grid.agents.len()) + .sum(); (0..steps).for_each(|_| { // Combine grids - combine(&mut self.grids, &self.attraction_table); + combine(&mut self.population_grids, &self.attraction_table); let agents_tick_time = Instant::now(); // Tick agents - self.grids.par_iter_mut().for_each(|grid| { + self.population_grids.par_iter_mut().for_each(|grid| { grid.tick(); grid.diffuse(self.diffusivity); // Diffuse + Decay }); @@ -144,7 +148,7 @@ impl Model { } fn save_image_data(&mut self) { - let grids = ThinGridData::new_from_grid_vec(self.grids.clone()); + let grids = ThinGridData::new_from_grid_vec(self.population_grids.clone()); let img_data = ImgData::new(grids, self.palette); self.img_data_vec.push((self.iteration + 1, img_data)); let size: usize = std::mem::size_of_val(&self.img_data_vec);