From d09c8e9c9aa25c73f421b53036b2a769961e3700 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Thu, 1 Apr 2021 13:02:37 -0400 Subject: [PATCH] things --- TODO.md | 15 ++++++++------- src/agent.rs | 15 +++------------ src/grid.rs | 17 +++++++++++++++-- src/main.rs | 11 ++++++----- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/TODO.md b/TODO.md index cf85d01..c829da1 100644 --- a/TODO.md +++ b/TODO.md @@ -2,18 +2,19 @@ 1. `grid.rs` - Remove need for `deposit`/`deposit_all` - Possible solution: Make it so when data is called, it generates it in a function when needed -2. GPU compute +2. Add check to make sure that `img_data_vec` isn't over a set size in ram, if so, render it and flush to disk +3. Auto create gif instead of doing that after the fact manually with imagemagick +4. GPU compute - Tried [ArrayFire-rust](https://github.com/arrayfire/arrayfire-rust) didn't work well, looking for another library - Try using [emu](https://github.com/calebwin/emu) (seems to be a very good option) - emu seems to be the way to go - May have to completely rewrite simulation to run on the gpu (that'll be fun *pain*) -3. Auto create a video from generated images +5. Auto create a video from generated images - Instead of using the command `ffmpeg -r 20 -i tmp/out_%d.png -vcodec libx265 -crf 25 -s 512x512 test.mp4` maybe use a rust library to do the same (more research needed) -4. Live output - - Might want to do after #3 ("Auto create a video from generated images") -5. Make collisions for walls of grid -6. Add config and cmd arguments when running the binary to adjust simulation settings7. -7. sin and cos optimizations +6. Live output + - Might want to do after #5 and #3 +7. Add config and cmd arguments when running the binary to adjust simulation settings7. +8. sin and cos optimizations - sin/cos table - precompute before simulation - Cache sin/cos values in hashmap to be recalled later diff --git a/src/agent.rs b/src/agent.rs index 49ecd2d..f576600 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -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; diff --git a/src/grid.rs b/src/grid.rs index acc3ae7..f71367b 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -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); }); } diff --git a/src/main.rs b/src/main.rs index a86d5b2..00ab9ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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