pub fn sir(
graph: &Graph,
beta: f64,
gamma: f64,
no_sim: usize,
seed: u64,
) -> IgraphResult<Vec<Sir>>Expand description
Runs no_sim independent SIR epidemic simulations on graph.
Edge directions are ignored: an edge contributes to both endpoints’ neighbourhoods. The graph must be simple in its undirected view (no self-loops, no parallel or mutual edges).
beta— per-edge infection rate (rate for a susceptible with one infected neighbour); the rate scales linearly with the number of infected neighbours. Must be non-negative.gamma— recovery rate of an infected individual. Must be strictly positive (otherwise the process would never terminate).no_sim— number of independent runs. Must be positive.seed— seed for the deterministicSplitMix64PRNG.
Returns one Sir trajectory per simulation.
§Errors
- The graph is empty (
vcount == 0). beta < 0,gamma <= 0, orno_sim == 0.- The graph is not simple in its undirected view.
§Examples
use rust_igraph::{Graph, sir};
// A small ring; every run starts with exactly one infected vertex.
let mut g = Graph::with_vertices(5);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
g.add_edge(3, 4).unwrap();
g.add_edge(4, 0).unwrap();
let runs = sir(&g, 2.0, 1.0, 3, 0x5152).unwrap();
assert_eq!(runs.len(), 3);
for run in &runs {
// Every trajectory starts at t = 0 with one infected, four susceptible.
assert_eq!(run.times[0], 0.0);
assert_eq!(run.no_i[0], 1);
assert_eq!(run.no_s[0], 4);
assert_eq!(run.no_r[0], 0);
// Population is conserved at every step and ends with no infected.
for k in 0..run.times.len() {
assert_eq!(run.no_s[k] + run.no_i[k] + run.no_r[k], 5);
}
assert_eq!(*run.no_i.last().unwrap(), 0);
}