Model: rename grids field
This commit is contained in:
parent
5d574c9674
commit
56f3eae156
20
src/model.rs
20
src/model.rs
@ -13,8 +13,8 @@ use std::{path::Path, time::Instant};
|
|||||||
|
|
||||||
// Top-level simulation class.
|
// Top-level simulation class.
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
// The grid they move on.
|
// per-population grid (one for each population)
|
||||||
grids: Vec<Grid>,
|
population_grids: Vec<Grid>,
|
||||||
|
|
||||||
// Attraction table governs interaction across populations
|
// Attraction table governs interaction across populations
|
||||||
attraction_table: Vec<Vec<f32>>,
|
attraction_table: Vec<Vec<f32>>,
|
||||||
@ -39,7 +39,7 @@ impl Model {
|
|||||||
const REPULSION_FACTOR_STD: f32 = 0.1;
|
const REPULSION_FACTOR_STD: f32 = 0.1;
|
||||||
|
|
||||||
pub fn print_configurations(&self) {
|
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!("Grid {}: {}", i, grid.config);
|
||||||
}
|
}
|
||||||
println!("Attraction table: {:#?}", self.attraction_table);
|
println!("Attraction table: {:#?}", self.attraction_table);
|
||||||
@ -84,7 +84,7 @@ impl Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Model {
|
Model {
|
||||||
grids,
|
population_grids: grids,
|
||||||
attraction_table,
|
attraction_table,
|
||||||
diffusivity,
|
diffusivity,
|
||||||
iteration: 0,
|
iteration: 0,
|
||||||
@ -108,14 +108,18 @@ impl Model {
|
|||||||
let mut time_per_agent_list: Vec<f64> = Vec::new();
|
let mut time_per_agent_list: Vec<f64> = Vec::new();
|
||||||
let mut time_per_step_list: Vec<f64> = Vec::new();
|
let mut time_per_step_list: Vec<f64> = 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(|_| {
|
(0..steps).for_each(|_| {
|
||||||
// Combine grids
|
// Combine grids
|
||||||
combine(&mut self.grids, &self.attraction_table);
|
combine(&mut self.population_grids, &self.attraction_table);
|
||||||
let agents_tick_time = Instant::now();
|
let agents_tick_time = Instant::now();
|
||||||
|
|
||||||
// Tick agents
|
// Tick agents
|
||||||
self.grids.par_iter_mut().for_each(|grid| {
|
self.population_grids.par_iter_mut().for_each(|grid| {
|
||||||
grid.tick();
|
grid.tick();
|
||||||
grid.diffuse(self.diffusivity); // Diffuse + Decay
|
grid.diffuse(self.diffusivity); // Diffuse + Decay
|
||||||
});
|
});
|
||||||
@ -144,7 +148,7 @@ impl Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn save_image_data(&mut self) {
|
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);
|
let img_data = ImgData::new(grids, self.palette);
|
||||||
self.img_data_vec.push((self.iteration + 1, img_data));
|
self.img_data_vec.push((self.iteration + 1, img_data));
|
||||||
let size: usize = std::mem::size_of_val(&self.img_data_vec);
|
let size: usize = std::mem::size_of_val(&self.img_data_vec);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user