# Chapter 30. Processes on graphs

## 1. Epidemic models

### 1.1. `igraph_sir` — Performs a number of SIR epidemics model runs on a graph.

    igraph_error_t igraph_sir(const igraph_t *graph, igraph_real_t beta,
                   igraph_real_t gamma, igraph_int_t no_sim,
                   igraph_vector_ptr_t *result);

The SIR model is a simple model from epidemiology. The individuals of the population might be in three states: susceptible, infected and recovered. Recovered people are assumed to be immune to the disease. Susceptibles become infected with a rate that depends on their number of infected neighbors. Infected people become recovered with a constant rate. See these parameters below.

This function runs multiple simulations, all starting with a single uniformly randomly chosen infected individual. A simulation is stopped when no infected individuals are left.

Arguments:

`graph`: | The graph to perform the model on. For directed graphs edge directions are ignored and a warning is given.
`beta`: | The rate of infection of an individual that is susceptible and has a single infected neighbor. The infection rate of a susceptible individual with n infected neighbors is n times beta. Formally this is the rate parameter of an exponential distribution.
`gamma`: | The rate of recovery of an infected individual. Formally, this is the rate parameter of an exponential distribution.
`no_sim`: | The number of simulation runs to perform.
`result`: | The result of the simulation is stored here, in a list of `igraph_sir_t` objects. To deallocate memory, the user needs to call `igraph_sir_destroy` on each element, before destroying the pointer vector itself using `igraph_vector_ptr_destroy_all()`.

Returns:

`` | Error code.

Time complexity: O(no_sim * (|V| + |E| log(|V|))).

### 1.2. `igraph_sir_t` — The result of one SIR model simulation.

    typedef struct igraph_sir_t {
        igraph_vector_t times;
        igraph_vector_int_t no_s, no_i, no_r;
    } igraph_sir_t;

Data structure to store the results of one simulation of the SIR (susceptible-infected-recovered) model on a graph. It has the following members. They are all (real or integer) vectors, and they are of the same length.

Values:

`times`: | A vector, the times of the events are stored here.
`no_s`: | An integer vector, the number of susceptibles in each time step is stored here.
`no_i`: | An integer vector, the number of infected individuals at each time step, is stored here.
`no_r`: | An integer vector, the number of recovered individuals is stored here at each time step.

### 1.3. `igraph_sir_destroy` — Deallocates memory associated with a SIR simulation run.

    void igraph_sir_destroy(igraph_sir_t *sir);

Arguments:

`sir`: | The `igraph_sir_t` object storing the simulation.