#![allow(dead_code)]
pub mod undirected;
pub use undirected::TemporalHypergraph as UndirectedTemporalGraph;
pub mod directed;
pub use directed::TemporalHypergraph as DirectedTemporalGraph;
#[derive(Debug, Clone, PartialEq, Eq, Copy, Hash)]
pub struct Cooldown {
cooldown_begin: Option<usize>,
cooldown_duration: usize,
switch: bool,
}
impl Cooldown {
pub fn consume(&mut self, time: usize) -> bool {
if let Some(cooldown_begin) = self.cooldown_begin {
if time < (cooldown_begin + self.cooldown_duration) {
return false;
}
}
self.cooldown_begin = Some(time);
true
}
fn is_active(&self, time: usize) -> bool {
let out = {
if let Some(cooldown_begin) = self.cooldown_begin {
time < cooldown_begin || time >= (cooldown_begin + self.cooldown_duration)
} else {
false
}
};
(out && !self.switch) || (!out && self.switch)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Copy, Hash)]
pub enum TemporalBehaviour {
Permanent,
Offset { offset: usize, switch: bool },
Interval {
start: usize,
end: usize,
switch: bool,
},
Periodic {
offset: usize,
period: usize,
switch: bool,
},
Cooldown(Cooldown),
}
impl TemporalBehaviour {
pub fn is_active(&self, time: usize) -> bool {
match self {
TemporalBehaviour::Permanent => true,
TemporalBehaviour::Offset { offset, switch } => {
let out = time >= *offset;
(out && !switch) || (!out && *switch)
}
TemporalBehaviour::Interval { start, end, switch } => {
let out = time >= *start && time < *end;
(out && !switch) || (!out && *switch)
}
TemporalBehaviour::Periodic {
offset,
period,
switch,
} => {
if time <= *offset {
return *switch;
}
return (time - offset) % (2 * period) <= *period;
}
TemporalBehaviour::Cooldown(cooldown) => cooldown.is_active(time),
}
}
}
impl Default for TemporalBehaviour {
fn default() -> Self {
TemporalBehaviour::Permanent
}
}