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

Extend temporal network to track the node set in addition to the edges.

parent 5a5d7132
......@@ -17,6 +17,7 @@ fn main() {
let months = args.nth(1).unwrap().parse::<i64>().unwrap();
let life_expectancy = args.next().unwrap().parse::<f64>().unwrap();
let decontamination = args.next().unwrap().parse::<f64>().unwrap();
let narrow_diet = args.next().unwrap().parse::<bool>().unwrap();
let seed = args.next().map_or(0, |arg| arg.parse::<u64>().unwrap());
params.trace_temporal_network = true;
......@@ -50,7 +51,10 @@ fn main() {
Exp::new(Rate::per_day(1. / life_expectancy) * params.tick).unwrap();
params.hoverflies = vec![hoverfly; 2].into();
params.hoverflies[0].insect.preferences = preferences(&[1., 0.]);
if narrow_diet {
params.hoverflies[0].insect.preferences = preferences(&[1., 0.]);
}
params.solitary_bees = Default::default();
params.bumblebees = Default::default();
......
......@@ -11,7 +11,7 @@ use model::{
observer::Observation,
solitary_bee::{Nest, NestLocation, SolitaryBee},
units::Tick,
World,
TemporalNetwork, World,
};
pub fn save<'a, T>(val: &'a T, buf: &mut Vec<IoSlice<'a>>)
......@@ -73,6 +73,20 @@ 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);
}
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))
}
}
unsafe impl Dump for FlowerPatch {}
unsafe impl Dump for FlowerPatchLocation {}
......
......@@ -9,7 +9,7 @@ fn main() {
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 {
for (tick, source, destination) in &temporal_network.edges {
let tick = tick.as_seconds() as u32;
stdout.write_all(&tick.to_ne_bytes()).unwrap();
......
......@@ -21,7 +21,7 @@ use crate::{
solitary_bee::{Nest, NestLocation, SolitaryBee},
space::{mirror, Vector},
units::Length,
CryptoRng, Model, Rng, TaggedIndex, World,
CryptoRng, Model, Rng, TaggedIndex, TemporalNetwork, World,
};
\end{hiddencode}
......@@ -182,6 +182,7 @@ As entities are identified by the rank of the process they are located at and th
Each individual insect is assigned a unique identifier so that its contacts can be traced through the subworlds.
\begin{code}
let mut temporal_network = TemporalNetwork::default();
let mut id = 0;
\end{code}
......@@ -192,6 +193,8 @@ 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);
......@@ -246,6 +249,8 @@ 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);
......@@ -316,6 +321,8 @@ Bumblebees are mobile entities which are always associated to single colony. Hen
for _ in 0..colony.capacity {
let bumblebee =
Bumblebee::new(&params, id, colony.location, colony.species, &mut rng);
temporal_network.species.push(bumblebee.insect.species);
id += 1;
if dest == rank {
......@@ -407,7 +414,7 @@ Finally, an associative set of lists of messages used to relocate mobile entitie
observations: Default::default(),
contacts: Default::default(),
vectors: Default::default(),
temporal_network: Default::default(),
temporal_network,
},
grid,
flower_patch_locations: KDTree::new(flower_patch_locations.into()),
......
......@@ -337,7 +337,13 @@ Each individual insect is assigned a tick at which it dies as defined in \autore
};
if just_died {
self.id = next_id();
let next_id = next_id();
if params.trace_temporal_network {
temporal_network.nodes.push((tick, self.id, next_id));
}
self.id = next_id;
self.dies_at = tick + insect_params.life_expectancy(params, rng);
}
}
......
......@@ -174,7 +174,19 @@ pub type Contacts = Vec<((FlowerPatchSpecies, InsectSpecies), (usize, Vec<usize>
pub type Vectors = Vec<((FlowerPatchSpecies, InsectSpecies, InsectSpecies), usize)>;
pub type TemporalNetwork = Vec<(Tick, u32, u32)>;
#[derive(Default)]
pub struct TemporalNetwork {
pub edges: Vec<(Tick, u32, u32)>,
pub nodes: Vec<(Tick, u32, u32)>,
pub species: Vec<InsectSpecies>,
}
impl TemporalNetwork {
pub fn clear(&mut self) {
self.edges.clear();
self.nodes.clear();
}
}
\end{code}
\section{Process overview and scheduling}
......
......@@ -125,7 +125,7 @@ The \inlinecode{flower_contaminators} hash table is used to track which individu
flower_contaminators.retain(|(contaminator, decontaminates_at)| {
if *decontaminates_at > tick {
temporal_network.push((tick, *contaminator, id));
temporal_network.edges.push((tick, *contaminator, id));
true
} else {
......
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