graph_tool.generation#

This module contains functions that generate different kinds of graphs.

Random graph generation#

random_graph

Generate a random graph, with a given degree distribution and (optionally) vertex-vertex correlation.

random_rewire

Shuffle the graph in-place, following a variety of possible statistical models, chosen via the parameter model.

add_random_edges

Add new edges to a graph, chosen uniformly at random.

remove_random_edges

Remove edges from the graph, chosen uniformly at random.

generate_triadic_closure

Closes open triads in a graph, according to an ego-based process.

price_network

A generalized version of Price's --- or Barabási-Albert if undirected --- preferential attachment network model.

Stochastic block models#

generate_sbm

Generate a random graph by sampling from the Poisson or microcanonical stochastic block model.

generate_maxent_sbm

Generate a random graph by sampling from the maximum-entropy "canonical" stochastic block model.

solve_sbm_fugacities

Obtain SBM fugacities, given expected degrees and edge counts between groups.

Geometric models#

generate_knn

Generate a graph of k-nearest neighbors (or pairs) from a set of multidimensional points.

geometric_graph

Generate a geometric network form a set of N-dimensional points.

triangulation

Generate a 2D or 3D triangulation graph from a given point set.

Graph transformations#

predecessor_tree

Return a graph from a list of predecessors given by the pred_map vertex property.

line_graph

Return the line graph of the given graph g.

condensation_graph

Obtain the condensation graph, where each vertex with the same 'prop' value is condensed in one vertex.

contract_parallel_edges

Contract all parallel edges into simple edges, keeping track of their multipliciites.

remove_parallel_edges

Remove all parallel edges from the graph.

expand_parallel_edges

Expand edge multiplicities into parallel edges.

label_parallel_edges

Label edges which are parallel, i.e, have the same source and target vertices.

remove_self_loops

Remove all self-loops edges from the graph.

label_self_loops

Label edges which are self-loops, i.e, the source and target vertices are the same.

Graph operations#

graph_union

Return the union of graphs g1 and g2, composed of all edges and vertices of g1 and g2, without overlap (if intersection == None).

Deterministic graphs#

lattice

Generate a N-dimensional square lattice.

complete_graph

Generate complete graph.

circular_graph

Generate a circular graph.