The UFZ services GitLab and Mattermost will be unavailable on Monday, July 4 from 06:00 AM to 08:00 AM due to maintenance work.

Commit 9715d45c authored by Adam Reichold's avatar Adam Reichold
Browse files

Use a more redundant format for the node replacements that is however not...

Use a more redundant format for the node replacements that is however not affected by the lack of event ordering between subworlds.
parent 167ef22c
......@@ -76,14 +76,14 @@ unsafe impl Dump for World {
unsafe impl Dump for TemporalNetwork {
fn save<'a>(&'a self, buf: &mut Vec<IoSlice<'a>>, pos: &mut usize) {
self.edges.save(buf, pos);
self.nodes.save(buf, pos);
self.species.save(buf, pos);
self.node_additions.save(buf, pos);
self.node_removals.save(buf, pos);
}
unsafe fn restore(mut buf: &mut [u8], this: *mut Self) -> &mut [u8] {
buf = Dump::restore(buf, addr_of_mut!((*this).edges));
buf = Dump::restore(buf, addr_of_mut!((*this).nodes));
Dump::restore(buf, addr_of_mut!((*this).species))
buf = Dump::restore(buf, addr_of_mut!((*this).node_additions));
Dump::restore(buf, addr_of_mut!((*this).node_removals))
}
}
......
use std::env::args_os;
use std::io::{stdout, BufWriter, Write};
use hashbrown::HashMap;
use measurements::collect;
use model::insect::Species as InsectSpecies;
......@@ -10,8 +8,6 @@ fn main() {
let stdout = stdout();
let mut stdout = BufWriter::with_capacity(1024 * 1024, stdout.lock());
let mut node_species = HashMap::<u32, u32>::default();
// The two highest bit of the tick determine the record type:
// 00 => edge = tick|source|destination
// 10 => node removed = tick|id
......@@ -29,40 +25,30 @@ fn main() {
stdout.write_all(&destination.to_ne_bytes()).unwrap();
}
for (tick, old_node, new_node) in &temporal_network.nodes {
for (tick, old_node) in &temporal_network.node_removals {
let mut tick = tick.as_seconds() as u32;
assert!(MASK & tick == 0);
// remove old node
tick |= 1 << 31;
stdout.write_all(&tick.to_ne_bytes()).unwrap();
stdout.write_all(&old_node.to_ne_bytes()).unwrap();
stdout.write_all(&[0; 4]).unwrap();
}
// either we know the species as a node is replaced,
// or this is an initial node and we can index into `species`
let species = if let Some(species) = node_species.get(old_node) {
*species
} else {
let species = match temporal_network.species[*old_node as usize] {
InsectSpecies::Hoverfly(species) => species as u32,
InsectSpecies::SolitaryBee(species) => 256 + species as u32,
InsectSpecies::Bumblebee(species) => 512 + species as u32,
};
for (tick, new_node, species) in &temporal_network.node_additions {
let mut tick = tick.as_seconds() as u32;
assert!(MASK & tick == 0);
stdout.write_all(&[0; 4]).unwrap();
stdout.write_all(&old_node.to_ne_bytes()).unwrap();
stdout.write_all(&species.to_ne_bytes()).unwrap();
tick |= 1 << 31;
tick |= 1 << 30;
species
let species = match species {
InsectSpecies::Hoverfly(species) => *species as u32,
InsectSpecies::SolitaryBee(species) => 256 + *species as u32,
InsectSpecies::Bumblebee(species) => 512 + *species as u32,
};
node_species.insert(*new_node, species);
// insert new node
tick |= 1 << 30;
stdout.write_all(&tick.to_ne_bytes()).unwrap();
stdout.write_all(&new_node.to_ne_bytes()).unwrap();
stdout.write_all(&species.to_ne_bytes()).unwrap();
......
......@@ -21,7 +21,7 @@ use crate::{
solitary_bee::{Nest, NestLocation, SolitaryBee},
space::{mirror, Vector},
units::Length,
CryptoRng, Model, Rng, TaggedIndex, TemporalNetwork, World,
CryptoRng, Model, Rng, TaggedIndex, TemporalNetwork, Tick, World,
};
\end{hiddencode}
......@@ -194,14 +194,19 @@ Hoverflies are mobile entities which perform their reproductive activities using
for _ in 0..params.init.hoverflies {
let hoverfly = Hoverfly::new(&params, id, position(&mut rng), &mut rng);
temporal_network.species.push(hoverfly.insect.species);
id += 1;
let dest = grid.location(&hoverfly.insect.position);
if dest == rank {
hoverflies.push(hoverfly);
temporal_network.node_additions.push((
Tick::default(),
id,
hoverfly.insect.species,
));
}
id += 1;
}
let mut clutches = Vec::new();
......@@ -250,14 +255,19 @@ Solitary bees are mobile entities which perform their reproductive activities us
for _ in 0..params.init.solitary_bees {
let solitary_bee = SolitaryBee::new(&params, id, position(&mut rng), &mut rng);
temporal_network.species.push(solitary_bee.insect.species);
id += 1;
let dest = grid.location(&solitary_bee.insect.position);
if dest == rank {
solitary_bees.push(solitary_bee);
temporal_network.node_additions.push((
Tick::default(),
id,
solitary_bee.insect.species,
));
}
id += 1;
}
let mut nests = Vec::new();
......@@ -322,12 +332,17 @@ Bumblebees are mobile entities which are always associated to single colony. Hen
let bumblebee =
Bumblebee::new(&params, id, colony.location, colony.species, &mut rng);
temporal_network.species.push(bumblebee.insect.species);
id += 1;
if dest == rank {
bumblebees.push(bumblebee);
temporal_network.node_additions.push((
Tick::default(),
id,
bumblebee.insect.species,
));
}
id += 1;
}
}
\end{code}
......
......@@ -340,7 +340,11 @@ Each individual insect is assigned a tick at which it dies as defined in \autore
let next_id = next_id();
if params.trace_temporal_network {
temporal_network.nodes.push((tick, self.id, next_id));
temporal_network.node_removals.push((tick, self.id));
temporal_network
.node_additions
.push((tick, next_id, self.species));
}
self.id = next_id;
......
......@@ -177,14 +177,15 @@ pub type Vectors = Vec<((FlowerPatchSpecies, InsectSpecies, InsectSpecies), usiz
#[derive(Default)]
pub struct TemporalNetwork {
pub edges: Vec<(Tick, u32, u32)>,
pub nodes: Vec<(Tick, u32, u32)>,
pub species: Vec<InsectSpecies>,
pub node_additions: Vec<(Tick, u32, InsectSpecies)>,
pub node_removals: Vec<(Tick, u32)>,
}
impl TemporalNetwork {
pub fn clear(&mut self) {
self.edges.clear();
self.nodes.clear();
self.node_additions.clear();
self.node_removals.clear();
}
}
\end{code}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment