Skip to content

Graph generators

Deterministic and random graph generators.

Function Description
grid() Returns the edges and node positions of a 2D grid graph of height x width nodes, where each node is connected to itself and to its (up to 8) horizontal, vertical and diagonal neighbors.
erdos_renyi_graph() Returns the edges of a random Erdos-Renyi graph: each possible edge (without self-loops) is present independently with probability edge_prob.
barabasi_albert_graph() Returns the edges of a random Barabasi-Albert graph (preferential attachment): each new node is connected to num_edges existing nodes, chosen with a probability proportional to their degree.
stochastic_blockmodel_graph() Returns the edges of a random graph from the stochastic block model: the nodes are split into blocks, and each possible edge (without self-loops) between a node of block a and a node of block b is present independently with probability edge_probs[a][b].