BIG rewrite and changes (too many to list)
This commit is contained in:
@@ -22,12 +22,8 @@ impl Display for Agent {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{{\n (x,y): ({},{})\n angle: {}\n population id: {}, i: {} }}",
|
||||
self.x,
|
||||
self.y,
|
||||
self.angle,
|
||||
self.population_id,
|
||||
self.i,
|
||||
"{{\n(x,y): ({},{})\nangle: {}\npopulation id: {}\ni: {}}}",
|
||||
self.x, self.y, self.angle, self.population_id, self.i,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
18
src/grid.rs
18
src/grid.rs
@@ -4,8 +4,8 @@ use crate::{
|
||||
};
|
||||
|
||||
use rand::{distributions::Uniform, Rng};
|
||||
|
||||
use std::fmt::{Display, Formatter};
|
||||
use rayon::{iter::ParallelIterator, prelude::*};
|
||||
|
||||
// A population configuration.
|
||||
#[derive(Debug)]
|
||||
@@ -159,6 +159,22 @@ impl Grid {
|
||||
);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn tick(&mut self) {
|
||||
let self_immutable = self.clone();
|
||||
self.agents.par_iter_mut().for_each(|agent| {
|
||||
agent.tick(&self_immutable);
|
||||
});
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn deposit_all(&mut self) {
|
||||
let agent_list = self.agents.clone();
|
||||
for agent in agent_list.iter() {
|
||||
self.deposit(agent.x, agent.y);
|
||||
}
|
||||
}
|
||||
|
||||
// No longer needed (moved to imgdata.rs)
|
||||
/*
|
||||
pub fn quantile(&self, fraction: f32) -> f32 {
|
||||
|
||||
@@ -11,8 +11,8 @@ fn main() {
|
||||
// let (width, height) = (1024, 1024);
|
||||
|
||||
// # of agents
|
||||
let n_particles = 1 << 10;
|
||||
// let n_particles = 1 << 16;
|
||||
// let n_particles = 1 << 10;
|
||||
let n_particles = 1 << 16;
|
||||
println!("n_particles: {}", n_particles);
|
||||
|
||||
let diffusivity = 1;
|
||||
|
||||
13
src/model.rs
13
src/model.rs
@@ -118,23 +118,16 @@ impl Model {
|
||||
// Combine grids
|
||||
let grids = &mut self.grids;
|
||||
combine(grids, &self.attraction_table);
|
||||
let grids_immutable_1 = &grids.clone();
|
||||
|
||||
let agents_tick_time = Instant::now();
|
||||
|
||||
// Tick agents
|
||||
for grid in grids.iter_mut() {
|
||||
grid.agents.par_iter_mut().for_each(|agent| {
|
||||
agent.tick(&grids_immutable_1[agent.population_id]);
|
||||
});
|
||||
grid.tick();
|
||||
}
|
||||
|
||||
// Deposit
|
||||
let grids_immutable_2 = &grids.clone();
|
||||
for grid in grids_immutable_2.iter() {
|
||||
for agent in grid.agents.iter() {
|
||||
self.grids[agent.population_id].deposit(agent.x, agent.y);
|
||||
}
|
||||
for grid in self.grids.iter_mut() {
|
||||
grid.deposit_all();
|
||||
}
|
||||
|
||||
// Diffuse + Decay
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn wrap(x: f32, max: f32) -> f32 {
|
||||
x - max * ((x > max) as i32 as f32 - (x < 0.0_f32) as i32 as f32)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user