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.

random_rewire_connected

Return a degree-preserving randomization of a simple undirected graph, optionally keeping it connected.

random_rewire_lattice

Return a degree-preserving rewiring of a simple undirected graph towards a ring lattice.

is_graphical

Check whether a degree sequence can be realized by a graph.

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.

corrupt_graph

Corrupt a graph by removing and adding edges at random.

price_network

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

generate_chung_lu

Generate a random graph with given expected degrees, with the Chung-Lu model or one of its variants.

generate_static_fitness

Generate a random graph with a given number of edges, whose endpoints are chosen with probabilities proportional to vertex fitnesses.

generate_static_power_law

Generate a random graph with power-law degree distributions, with the static model.

generate_kernel_graph

Generate a random graph from an inhomogeneous random graph model with a given kernel.

generate_random_intersection

Generate a random intersection graph.

generate_joint_degree

Generate a random simple graph with a given joint degree matrix.

is_joint_degree_graphical

Check whether a joint degree matrix can be realized by a simple graph.

spectral_graph_forge

Generate a random graph with approximately the same spectral structure as a given one.

generate_shell

Generate a random shell graph.

generate_cograph

Generate a random cograph with \(2^n\) vertices.

generate_tournament

Generate a uniformly random tournament.

generate_k_lift

Generate a random \(k\)-lift of a graph.

generate_regular_expander

Generate a random regular graph that is a (near-)Ramanujan expander.

generate_internet_as

Generate a random graph of the Internet at the level of autonomous systems.

random_connected_graph

Generate a random connected simple graph with a given degree sequence.

generate_clustered_configuration

Generate a multigraph with the clustered configuration model, with given numbers of single edges and triangles at every vertex.

generate_random_dot_product

Generate a (generalized) random dot product graph.

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.

generate_lfr

Generate a random graph with planted communities according to the benchmark of Lancichinetti, Fortunato, and Radicchi (LFR).

generate_watts_strogatz

Generate a small-world graph with the Watts-Strogatz model.

generate_forest_fire

Generate a graph with the forest fire model.

generate_s1

Generate a graph with the \(\mathbb{S}^1\) geometric model (or its hyperbolic version \(\mathbb{H}^2\)).

generate_rmat

Generate a graph with the R-MAT model.

realize_degree_sequence

Return a graph with the given degree sequence.

generate_erdos_renyi

Generate a random graph with the Erdős-Rényi model.

generate_plod

Generate a graph with the power-law out-degree (PLOD) model.

generate_ssca

Generate a graph of the SSCA#2 benchmark.

solve_sbm_fugacities

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

generate_planted_partition

Generate a simple graph from the planted partition model.

generate_relaxed_caveman

Generate a relaxed caveman graph.

Growing network models#

generate_holme_kim

Generate a scale-free graph with tunable clustering, with the model of Holme and Kim.

generate_dual_ba

Generate a graph with the dual Barabási-Albert model.

generate_extended_ba

Generate a graph with the extended Barabási-Albert model, with edge additions and rewiring.

generate_k_out

Generate a directed multigraph where every vertex has out-degree \(k\), with preferential attachment.

generate_gn

Generate a directed tree with the growing network (GN) model.

generate_gnr

Generate a directed tree with the growing network with redirection (GNR) model.

generate_gnc

Generate a directed acyclic graph with the growing network with copying (GNC) model.

generate_directed_scale_free

Generate a directed scale-free multigraph with the model of Bollobás, Borgs, Chayes, and Riordan.

generate_establishment

Generate a graph with the establishment model, a growing model with vertex types.

generate_growing_random

Generate a growing random multigraph.

generate_recent_degree

Generate a multigraph by preferential attachment to the recently gained degree.

generate_duplication_divergence

Generate a graph with the duplication-divergence model.

generate_partial_duplication

Generate a graph with the partial duplication model.

generate_preferential_aging

Generate a multigraph by preferential attachment with aging of the vertices.

generate_typed_citation

Generate a citation multigraph in which the citation probabilities depend on vertex types.

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 from a set of N-dimensional points.

triangulation

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

generate_geographical_threshold

Generate a geographical threshold graph.

generate_waxman

Generate a Waxman random graph.

generate_soft_geometric

Generate a soft random geometric graph.

generate_thresholded_geometric

Generate a thresholded random geometric graph.

generate_navigable_small_world

Generate a navigable small-world graph with Kleinberg's model.

gabriel_graph

Return the Gabriel graph of a set of points.

relative_neighborhood_graph

Return the relative neighborhood graph of a set of points.

beta_skeleton

Return the \(\beta\)-skeleton of a set of points.

Random trees#

generate_random_tree

Generate a uniformly random tree.

generate_random_forest

Generate a uniformly random rooted forest.

generate_power_law_tree

Generate a random tree with a power-law degree distribution.

generate_lobster

Generate a random lobster graph.

nonisomorphic_trees

Iterate over all nonisomorphic (unlabeled) trees with \(N\) vertices.

count_nonisomorphic_trees

Return the number of nonisomorphic (unlabeled) trees with \(N\) vertices.

Bipartite graphs#

generate_bipartite_erdos_renyi

Generate a random bipartite graph with the Erdős-Rényi model.

generate_bipartite_configuration

Generate a random bipartite multigraph with given degrees, with the configuration model.

generate_bipartite_preferential

Generate a bipartite multigraph with the preferential attachment model of Guillaume and Latapy.

realize_bipartite_degree_sequence

Return a bipartite graph with the given degrees.

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 multiplicities.

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-loop edges from the graph.

label_self_loops

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

remove_labeled_edges

Remove every edge e such that label[e] > 0.

graph_projection

Return the projection of selected vertices on the remaining vertices.

inverse_line_graph

Return the root graph of a line graph.

graph_power

Return the \(k\)-th power of a graph.

dedensify

Compress a graph by replacing the edges to groups of high-degree vertices with compressor vertices.

snap_aggregation

Summarize a graph by aggregating its vertices with the SNAP algorithm.

mycielskian

Return the Mycielskian of an undirected graph.

duplicate_vertices

Duplicate the vertices of a graph.

make_maximal_planar

Add edges to the graph to make it maximally planar.

moral_graph

Return the moral graph of a directed acyclic graph.

Graph set operations#

graph_merge

Merge the edges of graph g2 into g1, combining their weights, and including or excluding the edges according to the resulting weight.

graph_union

Return a graph containing the union of the vertices and edges of graphs g1 and g2.

graph_difference

Return a graph containing the differences of the edges of graphs g1 and g2, i.e. the edges in g1 that are not in g2.

graph_sym_difference

Return a graph containing the symmetric difference of the edges of graphs g1 and g2.

graph_intersection

Return a graph containing the intersection of the edges of graphs g1 and g2.

graph_product

Return the product of two graphs.

graph_join

Return the join of two graphs.

graph_composition

Return the relational composition of two graphs.

complement_graph

Return the complement of a graph.

Deterministic graphs#

named_graph

Return a named graph, or a member of a deterministic family of graphs.

lattice

Generate an N-dimensional square lattice.

complete_graph

Generate a complete graph.

circular_graph

Generate a circular graph.

interval_graph

Return the interval graph of a set of closed intervals.

visibility_graph

Return the natural visibility graph of a time series.

degree_sequence_tree

Return a tree with the given degree sequence.

prufer_tree

Return the labeled tree with the given Prüfer sequence.