graph_tool.structure#
This module contains various functions that assess the graph structure.
Shortest paths#
Calculate the distance from a source to a target vertex, or to all vertices from a given source, or the all pairs shortest paths, if the source is not specified. |
|
Return the shortest path from |
|
Return the number of shortest paths from source to target. |
|
Return an iterator over all shortest paths from source to target. |
|
Return a property map with all possible predecessors in the search tree determined by |
|
Return a random shortest path from source to target, uniformly sampled from all paths of equal length. |
|
Return the \(k\) shortest simple paths between two vertices. |
|
Return the width of the widest paths from a source vertex to all others. |
|
Return a widest path from a source to a target vertex. |
|
Return a shortest path subject to constraints on the resources it consumes. |
|
Return a cycle of negative total weight, if there is one. |
|
Assign every vertex to its closest seed vertex. |
|
Return the subgraph induced by the vertices within a given distance of a vertex. |
|
Return a spanner of a graph. |
Distances, eccentricity, and centers#
Compute the pseudo-diameter of the graph. |
|
Compute the eccentricity of every vertex. |
|
Compute the diameter of the graph. |
|
Compute the radius of the graph. |
|
Return the harmonic diameter of the graph. |
|
Return the center of the graph, i.e. the vertices of minimum eccentricity. |
|
Return the periphery of the graph, i.e. the vertices of maximum eccentricity. |
|
Return the barycenter of the graph, i.e. the vertices with the smallest sum of distances to all others. |
|
Return the average shortest path length between the pairs of vertices. |
Distance-based indices and small-world measures#
Return the global efficiency of the graph. |
|
Return the local efficiency of every vertex. |
|
Return the Wiener index of the graph. |
|
Return the hyper-Wiener index of the graph. |
|
Return the Schultz index of the graph. |
|
Return the Gutman index of the graph. |
|
Return the s-metric of the graph. |
|
Return the small-world coefficient sigma of a graph. |
|
Return the small-world coefficient omega of a graph. |
Paths, walks, and cycles#
Return an iterator over all paths from source to target. |
|
Return an iterator over all the cycles in a directed graph. |
|
Sample random walks on the graph. |
|
Return a loop-erased random walk from a vertex to a set of targets. |
|
Return an Eulerian path or circuit, i.e. one that traverses every edge exactly once. |
|
Return the edges to duplicate to make a connected undirected graph Eulerian. |
|
Return a cycle of the graph, if there is one. |
|
Return a basis of the cycle space of the graph. |
|
Return the girth of the graph, i.e. the length of its shortest cycle. |
|
Return an iterator over the chordless cycles of the graph. |
|
Return the maximum (or minimum) ratio of the total weight to the total time of the directed cycles. |
Components and connectivity#
Label the components to which each vertex in the graph belongs. |
|
Label the largest component in the graph. |
|
Extract the largest (strong) component in the graph as a |
|
Label the out-component (or simply the component for undirected graphs) of a root vertex. |
|
Return the number of vertices reachable from every vertex. |
|
Add edges to a graph to make it connected. |
|
Label the edges of biconnected components, and the vertices which are articulation points. |
|
Return the bridges of a graph. |
|
Return the local bridges of a graph and their spans. |
|
Return the chain decomposition of a graph. |
|
Check whether a directed graph is semiconnected. |
|
Return whether the graph is locally \((k, l)\)-connected. |
|
Return the largest locally \((k, l)\)-connected subgraph found by edge removal. |
|
Compute the size of the largest or second-largest component as vertices are (virtually) removed from the graph. |
|
Compute the size of the largest or second-largest component as edges are (virtually) removed from the graph. |
Core decompositions#
Perform a k-core decomposition of the given graph. |
|
Return the \(k\)-core, \(k\)-shell, \(k\)-crust, or \(k\)-corona of the graph. |
|
Perform a k-truss decomposition of the given graph. |
|
Perform the onion decomposition of the given graph. |
Cuts and expansion#
Return the size of the cut between two sets of vertices. |
|
Return the volume of a set of vertices. |
|
Return the conductance of the cut between two sets of vertices. |
|
Return the normalized size of the cut between two sets of vertices. |
|
Return the edge expansion of a set of vertices. |
|
Return the mixing expansion of a set of vertices. |
|
Return the vertex expansion of a set of vertices. |
|
Return the boundary expansion of a set of vertices. |
|
Return the vertex boundary of a set of vertices. |
|
Return the edge boundary of a set of vertices. |
Spanning trees#
Return the minimum spanning tree of a given graph. |
|
Return a random spanning tree of a given graph, which can be directed or undirected. |
|
Return the minimum spanning arborescence of a directed graph. |
|
Return an iterator over the spanning arborescences of a directed graph, in order of increasing (or decreasing) weight. |
|
Return an iterator over the spanning trees common to two graphs with corresponding edges. |
Trees#
Return the Prüfer sequence of a tree. |
|
Unfold a graph into a forest by breadth-first search. |
|
Return the broadcast time and the broadcast center of a tree. |
|
Return the broadcast time of a tree, or from one of its vertices. |
Directed graphs#
Return |
|
Calculate the edge reciprocity of the graph. |
|
Return the topological sort of the given graph. |
|
Return an iterator over all topological orderings of a directed acyclic graph. |
|
Return the topological generation of every vertex of a directed acyclic graph. |
|
Return the transitive closure graph of g. |
|
Return the transitive reduction of a directed acyclic graph. |
|
Return a set of edges whose removal leaves the graph without cycles. |
|
Return a set of vertices whose removal leaves the graph without cycles. |
|
Return a longest path of a directed acyclic graph. |
|
Return the branching of the paths from the sources of a directed acyclic graph. |
|
Return an iterator over all antichains of a directed acyclic graph. |
|
Return the lowest common ancestors of pairs of vertices of a rooted tree or of a directed acyclic graph. |
|
Return a vertex property map containing the dominator vertices for each vertex. |
|
Return the dominance frontier of every vertex of a directed graph. |
|
Check whether a strongly connected directed graph is aperiodic. |
|
Return the flow hierarchy of a directed graph. |
|
Return the CD index of a vertex of a citation graph. |
|
Check whether a directed graph is a tournament. |
|
Return a Hamiltonian path of a tournament. |
d-separation and graphical models#
Check whether a set of vertices d-separates two others in a directed acyclic graph. |
|
Return a minimal d-separator of two sets of vertices in a directed acyclic graph. |
|
Check whether a set of vertices is a minimal d-separator of two others in a directed acyclic graph. |
|
Return a junction tree of a graph. |
Chordal graphs and treewidth#
Check whether a graph is chordal. |
|
Return the edges of a minimal chordal completion of a graph. |
|
Return the maximal cliques of a chordal graph. |
|
Return the vertices on induced paths between two vertices of a chordal graph. |
|
Return an upper bound on the treewidth of an undirected graph. |
Cliques#
Return an iterator over the maximal cliques of the graph. |
|
Return an iterator over all cliques of a graph, maximal or not. |
|
Return all the cliques of maximum size of a graph. |
|
Return a clique of maximum total vertex weight. |
|
Return the clique number, i.e. the number of vertices of a largest clique. |
|
Return an approximate maximum clique. |
|
Return the size of a large clique found by a fast heuristic. |
|
Return an approximate maximum independent vertex set and a clique cover. |
|
Return a clique and an independent vertex set found by the Ramsey approximation. |
|
Return the graphlet decomposition of a weighted graph. |
Matchings, independent sets, and covers#
Find a maximum cardinality matching in the graph. |
|
Find a matching of maximum total weight in the graph. |
|
Return a maximal matching, which approximates the minimum maximal matching within a factor two. |
|
Return a \(k\)-factor of a graph. |
|
Return the maximal extendability of a bipartite graph. |
|
Find a maximal independent vertex set in the graph. |
|
Return the size of the largest independent vertex set of a graph. |
|
Return all the independent vertex sets of maximum size of a graph. |
|
Return an iterator over all maximal independent vertex sets of a graph. |
|
Return an approximate minimum (weighted) vertex cover. |
|
Return a minimum vertex cover of a bipartite graph. |
|
Return an edge cover of minimum size. |
|
Return an edge dominating set within a factor two of the minimum. |
|
Return an approximate minimum (weighted) dominating set. |
|
Return a connected dominating set of a connected graph. |
Coloring#
Returns a vertex coloring of the graph. |
|
Return a vertex coloring obtained with the DSatur heuristic. |
|
Return an equitable vertex coloring with |
|
Return a proper edge coloring of a simple undirected graph. |
Combinatorial optimization#
Return a traveling salesman tour of the graph. |
|
Return an approximate minimum Steiner tree connecting the given terminal vertices. |
|
Return an approximate maximum cut. |
|
Return an approximately densest subgraph. |
|
Return an ordering of the vertices that reduces the bandwidth of the adjacency matrix. |
|
Return the bandwidth of the adjacency matrix with the given vertex ordering. |
Graph comparison and isomorphism#
Return the Jaccard adjacency similarity between two graphs. |
|
Check whether two graphs are isomorphic. |
|
Obtain all subgraph isomorphisms of sub in g (or at most max_n subgraphs, if max_n > 0). |
|
Mark a given subgraph |
|
Return the maximum common induced subgraphs of two graphs. |
|
Return the edit distance between two graphs. |
|
Obtain the automorphism group of the graph with the bliss algorithm. |
|
Obtain the automorphism group of the graph with the nauty or Traces algorithms. |
|
Return the Weisfeiler-Lehman hash of the graph. |
Vertex similarity and link prediction#
Return the similarity between pairs of vertices. |
|
Return the SimRank similarity between pairs of vertices. |
|
Return the vertices most similar to a given one according to the Panther algorithm. |
|
Return link prediction scores of pairs of vertices that use the community structure. |
|
Return the common neighbor and centrality based parameterized algorithm (CCPA) score of pairs of vertices. |
Planarity#
Test if the graph is planar. |
|
Return the faces of a planar embedding of the graph. |
|
Check whether a drawing of a graph with straight edges on an integer grid has no edge crossings. |
Graph classes#
Test if the graph is bipartite. |
|
Check whether a graph is perfect. |
|
Return an asteroidal triple of a graph, if there is one. |
|
Return whether the graph is a threshold graph. |
|
Return a threshold subgraph of the graph. |
|
Check whether a graph is distance-regular. |
|
Check whether a graph is strongly regular. |
|
Check whether a graph is a regular (near-)Ramanujan expander. |
|
Return the intersection array of a distance-regular graph. |
|
Return the global parameters of a distance-regular graph from its intersection array. |
Graph polynomials#
Return the Tutte polynomial of a graph. |
|
Return the chromatic polynomial of a graph. |