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 167ef22c authored by Adam Reichold's avatar Adam Reichold
Browse files

Extend the temporal network binary format to include node addition and removal.

parent 70f40596
use std::env::args_os;
use std::io::{stdout, BufWriter, Write};
use measurements::collect;
fn main() {
let stdout = stdout();
let mut stdout = BufWriter::with_capacity(1024 * 1024, stdout.lock());
collect(args_os().nth(1).unwrap(), |_tick, worlds| {
for temporal_network in worlds.iter().map(|world| &world.temporal_network) {
for (tick, source, destination) in &temporal_network.edges {
let tick = tick.as_seconds() as u32;
stdout.write_all(&tick.to_ne_bytes()).unwrap();
stdout.write_all(&source.to_ne_bytes()).unwrap();
stdout.write_all(&destination.to_ne_bytes()).unwrap();
}
}
});
}
use std::env::args_os;
use std::io::{stdout, BufWriter, Write};
use hashbrown::HashMap;
use measurements::collect;
use model::insect::Species as InsectSpecies;
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
// 11 => node added = tick|id|species
const MASK: u32 = 1 << 31 | 1 << 30;
collect(args_os().nth(1).unwrap(), |_tick, worlds| {
for temporal_network in worlds.iter().map(|world| &world.temporal_network) {
for (tick, source, destination) in &temporal_network.edges {
let tick = tick.as_seconds() as u32;
assert!(MASK & tick == 0);
stdout.write_all(&tick.to_ne_bytes()).unwrap();
stdout.write_all(&source.to_ne_bytes()).unwrap();
stdout.write_all(&destination.to_ne_bytes()).unwrap();
}
for (tick, old_node, new_node) in &temporal_network.nodes {
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,
};
stdout.write_all(&[0; 4]).unwrap();
stdout.write_all(&old_node.to_ne_bytes()).unwrap();
stdout.write_all(&species.to_ne_bytes()).unwrap();
species
};
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();
}
}
});
}
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