def get_num_i(G):
    """
    Calculates the number of agents in state S
    :param G: A networkx graph
    :return: The number of agents in state S
    """
    return len([G.nodes[i]['state'] for i in range(G.number_of_nodes()) if
                G.nodes[i]['state'] == 'I'])