This commit is contained in:
Simon Gardling
2021-04-01 13:02:37 -04:00
parent 930432aefe
commit d09c8e9c9a
4 changed files with 32 additions and 26 deletions

View File

@@ -1,5 +1,5 @@
use crate::{
grid::{Grid, PopulationConfig},
grid::Grid,
util::wrap,
};
@@ -40,18 +40,9 @@ impl Agent {
i,
}
}
#[inline]
pub fn tick(&mut self, grid: &Grid) {
let (width, height) = (grid.width, grid.height);
let PopulationConfig {
sensor_distance,
sensor_angle,
rotation_angle,
step_distance,
..
} = grid.config;
pub fn tick(&mut self, grid: &Grid, sensor_distance: f32, sensor_angle: f32, rotation_angle: f32, step_distance: f32, width: usize, height: usize) {
let xc = self.x + cos(self.angle) * sensor_distance;
let yc = self.y + sin(self.angle) * sensor_distance;

View File

@@ -161,9 +161,22 @@ impl Grid {
#[inline]
pub fn tick(&mut self) {
let self_immutable = self.clone();
let (width, height) = (self.width, self.height);
let PopulationConfig {
sensor_distance,
sensor_angle,
rotation_angle,
step_distance,
..
} = self.config;
let self_imut = self.clone(); // Create immutable copy of self before ticking agents (this is a very bad solution, needs to be improved)
self.agents.par_iter_mut().for_each(|agent| {
agent.tick(&self_immutable);
agent.tick(&self_imut,
sensor_distance, sensor_angle,
rotation_angle, step_distance,
width, height);
});
}

View File

@@ -3,22 +3,23 @@ use physarum::model;
fn main() {
// # of iterations to go through
// let n_iterations = 1024;
let n_iterations = 128;
let n_iterations = 2048;
// Size of grid and pictures
// let (width, height) = (256, 256);
let (width, height) = (512, 512);
let (width, height) = (256, 256);
// let (width, height) = (512, 512);
// let (width, height) = (1024, 1024);
// # of agents
// let n_particles = 1 << 10;
let n_particles = 1 << 16;
// let n_particles = 1 << 16;
let n_particles = 1 << 20;
println!("n_particles: {}", n_particles);
let diffusivity = 1;
// `n_populations` is the # of types of agents
let n_populations = 1;
let n_populations = 4;
// let n_populations = 3;
// let n_populations = 1 + rng.gen_range(1..4); // make # of populations between 2 and 5