well that didn't work
This commit is contained in:
parent
e163387755
commit
c25b0d1795
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -372,9 +372,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.91"
|
||||
version = "0.2.92"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8916b1f6ca17130ec6568feccee27c156ad12037880833a3b842a823236502e7"
|
||||
checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714"
|
||||
|
||||
[[package]]
|
||||
name = "libm"
|
||||
@ -551,9 +551,9 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.24"
|
||||
version = "1.0.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
|
||||
checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
@ -755,9 +755,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.67"
|
||||
version = "1.0.68"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6498a9efc342871f91cc2d0d694c674368b4ceb40f62b65a7a08c3792935e702"
|
||||
checksum = "3ce15dd3ed8aa2f8eeac4716d6ef5ab58b6b9256db41d7e1a0224c2788e8fd87"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
||||
@ -88,8 +88,6 @@ pub struct Grid {
|
||||
// Scratch space for the blur operation.
|
||||
buf: Vec<f32>,
|
||||
blur: Blur,
|
||||
|
||||
pub i: Vec<usize>,
|
||||
}
|
||||
|
||||
impl Clone for Grid {
|
||||
@ -101,14 +99,13 @@ impl Clone for Grid {
|
||||
data: self.data.clone(),
|
||||
buf: self.buf.clone(),
|
||||
blur: self.blur.clone(),
|
||||
i: self.i.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Grid {
|
||||
// Create a new grid filled with random floats in the [0.0..1.0) range.
|
||||
pub fn new<R: Rng + ?Sized>(width: usize, height: usize, rng: &mut R, i: Vec<usize>) -> Self {
|
||||
pub fn new<R: Rng + ?Sized>(width: usize, height: usize, rng: &mut R) -> Self {
|
||||
if !width.is_power_of_two() || !height.is_power_of_two() {
|
||||
panic!("Grid dimensions must be a power of two.");
|
||||
}
|
||||
@ -122,7 +119,6 @@ impl Grid {
|
||||
config: PopulationConfig::new(rng),
|
||||
buf: vec![0.0; width * height],
|
||||
blur: Blur::new(width),
|
||||
i,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
14
src/main.rs
14
src/main.rs
@ -2,22 +2,22 @@ use physarum::model;
|
||||
|
||||
fn main() {
|
||||
// # of iterations to go through
|
||||
let n_iterations = 256;
|
||||
let n_iterations = 2048;
|
||||
|
||||
// Size of grid and pictures
|
||||
let (width, height) = (256, 256);
|
||||
// let (width, height) = (1024, 1024);
|
||||
// let (width, height) = (256, 256);
|
||||
let (width, height) = (1024, 1024);
|
||||
|
||||
// # of agents
|
||||
// let n_particles = 1 << 20;
|
||||
let n_particles = 1 << 16;
|
||||
let n_particles = 1 << 26;
|
||||
// let n_particles = 1 << 16;
|
||||
println!("n_particles: {}", n_particles);
|
||||
|
||||
let diffusivity = 1;
|
||||
|
||||
// `n_populations` is the # of types of agents
|
||||
// let n_populations = 1;
|
||||
let n_populations = 3;
|
||||
let n_populations = 1;
|
||||
// let n_populations = 3;
|
||||
// let n_populations = 1 + rng.gen_range(1..4); // make # of populations between 2 and 5
|
||||
|
||||
let mut model = model::Model::new(width, height, n_particles, n_populations, diffusivity); // Create the model
|
||||
|
||||
33
src/model.rs
33
src/model.rs
@ -130,7 +130,7 @@ impl Model {
|
||||
.map(|i| Agent::new(width, height, i / particles_per_grid, &mut rng, i))
|
||||
.collect(),
|
||||
grids: (0..n_populations)
|
||||
.map(|_| Grid::new(width, height, &mut rng, vec![]))
|
||||
.map(|_| Grid::new(width, height, &mut rng))
|
||||
.collect(),
|
||||
attraction_table,
|
||||
diffusivity,
|
||||
@ -157,23 +157,6 @@ impl Model {
|
||||
let mut time_per_agent_list: Vec<f64> = Vec::new();
|
||||
let mut time_per_step_list: Vec<f64> = Vec::new();
|
||||
|
||||
|
||||
println!("Doing some population stuff...");
|
||||
let time_1 = Instant::now();
|
||||
let mut i_pop: Vec<Vec<usize>> = Vec::new();
|
||||
for _i in 0..(self.grids.len()) {
|
||||
i_pop.push(vec![]);
|
||||
}
|
||||
for agent in self.agents.iter() {
|
||||
i_pop[agent.population_id].push(agent.i);
|
||||
}
|
||||
|
||||
for i in 0..(self.grids.len()) {
|
||||
self.grids[i].i = i_pop[i].clone();
|
||||
}
|
||||
println!("Took {}ms", time_1.elapsed().as_millis());
|
||||
|
||||
let use_exp_deposit: bool = true;
|
||||
for i in 0..steps {
|
||||
if debug {
|
||||
println!("Starting tick for all agents...")
|
||||
@ -241,18 +224,8 @@ impl Model {
|
||||
});
|
||||
|
||||
// Deposit
|
||||
if use_exp_deposit {
|
||||
let agent_list = self.agents.clone();
|
||||
self.grids.par_iter_mut().for_each(|grid|{
|
||||
for i in 0..grid.i.len() {
|
||||
let agent = &agent_list[i];
|
||||
grid.deposit(agent.x, agent.y);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
for agent in self.agents.iter() {
|
||||
self.grids[agent.population_id].deposit(agent.x, agent.y);
|
||||
}
|
||||
for agent in self.agents.iter() {
|
||||
self.grids[agent.population_id].deposit(agent.x, agent.y);
|
||||
}
|
||||
|
||||
// Diffuse + Decay
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user