vertex_ordering

vertex_ordering#

graph_tool.structure.vertex_ordering(g, method='rcm', weight=None, root=None)[git][source]#

Return an ordering of the vertices that reduces the bandwidth of the adjacency matrix.

Parameters:
gGraph

Undirected graph to be used.

methodstr (optional, default: "rcm")

Ordering algorithm: "cuthill-mckee", "rcm" (reverse Cuthill-McKee), "king", "sloan", "min_degree" (multiple minimum degree), "smallest_last", "max_adjacency" (maximum adjacency search), "mcs" (maximum cardinality search), or "spectral" (Fiedler vector).

weightEdgePropertyMap (optional, default: None)

Edge weights, used only by "max_adjacency" and "spectral".

rootVertex or int (optional, default: None)

First vertex, used only by "max_adjacency" and "mcs". If not given, the first vertex is used.

Returns:
ordernumpy.ndarray

The vertices in their new order.

See also

bandwidth

Bandwidth and profile of a given ordering

treewidth

Elimination ordering that bounds the treewidth

Notes

The Cuthill-McKee algorithm [cuthill-reducing-1969] orders every connected component by a breadth-first search from a pseudo-peripheral vertex, with the neighbors of each vertex in order of increasing degree; its reverse [george-computer-1981] usually gives a smaller profile. The algorithm of King [king-algorithm-1970] chooses the next vertex so that the front of the search grows as little as possible. The bandwidth and profile of the resulting ordering are given by bandwidth(). The running time is \(O(E\log k_{\max})\) for the Cuthill-McKee orderings and higher for King’s.

Sloan’s algorithm [sloan-algorithm-1986] reduces the profile and the wavefront, and is applied to every connected component separately; the candidate list is sorted at every step, so that it takes time \(O(V^2\log V)\) in the worst case. The multiple minimum degree ordering [liu-modification-1985] reduces the fill-in of sparse Cholesky factorizations, and the smallest-last ordering [matula-smallest-1983] removes a vertex of smallest remaining degree at a time and puts it last, so that every vertex has at most \(k\) neighbors before it, where \(k\) is the degeneracy (useful for sequential_vertex_coloring()). Self-loops and parallel edges are ignored by the last three methods.

The last two methods do not reduce the bandwidth, but are orderings of searches used by other algorithms. Maximum adjacency search [nagamochi-computing-1992] visits next the vertex with the largest total weight of edges to the visited vertices, as in the minimum cut algorithm of Stoer and Wagner (see minimum_cut()), and is computed in time \(O(E\log V)\). Maximum cardinality search [tarjan-simple-1984] visits next the vertex with the most visited neighbors, in time \(O(V + E)\); its reverse is a perfect elimination ordering if the graph is chordal (see is_chordal()).

The spectral ordering [barnard-spectral-1995] sorts the vertices of every connected component by their entries in the Fiedler vector of the component, i.e. the eigenvector of the second smallest eigenvalue of its Laplacian (see algebraic_connectivity()), with the components in the order of their labels in label_components(). It tends to reduce the envelope of the matrix, and places close together vertices that are close in the graph. The sign of the Fiedler vector is arbitrary, so the order of a component may be reversed.

References

[cuthill-reducing-1969]

E. Cuthill and J. McKee, “Reducing the bandwidth of sparse symmetric matrices”, Proceedings of the 24th National Conference of the ACM, 157-172 (1969), DOI: 10.1145/800195.805928 [sci-hub, @tor]

[george-computer-1981]

Alan George and Joseph W-H Liu, “Computer Solution of Large Sparse Positive Definite Systems”, Prentice-Hall (1981).

[king-algorithm-1970]

Ian P. King, “An automatic reordering scheme for simultaneous equations derived from network systems”, International Journal for Numerical Methods in Engineering 2, 523-533 (1970), DOI: 10.1002/nme.1620020406 [sci-hub, @tor]

[sloan-algorithm-1986]

S. W. Sloan, “An algorithm for profile and wavefront reduction of sparse matrices”, International Journal for Numerical Methods in Engineering 23, 239-251 (1986), DOI: 10.1002/nme.1620230208 [sci-hub, @tor]

[liu-modification-1985]

Joseph W. H. Liu, “Modification of the minimum-degree algorithm by multiple elimination”, ACM Transactions on Mathematical Software 11, 141-153 (1985), DOI: 10.1145/214392.214398 [sci-hub, @tor]

[matula-smallest-1983]

David W. Matula and Leland L. Beck, “Smallest-last ordering and clustering and graph coloring algorithms”, Journal of the ACM 30, 417-427 (1983), DOI: 10.1145/2402.322385 [sci-hub, @tor]

[nagamochi-computing-1992]

Hiroshi Nagamochi and Toshihide Ibaraki, “Computing edge-connectivity in multigraphs and capacitated graphs”, SIAM Journal on Discrete Mathematics 5, 54-66 (1992), DOI: 10.1137/0405004 [sci-hub, @tor]

[barnard-spectral-1995]

Stephen T. Barnard, Alex Pothen and Horst Simon, “A spectral algorithm for envelope reduction of sparse matrices”, Numerical Linear Algebra with Applications 2, 317-334 (1995), DOI: 10.1002/nla.1680020402 [sci-hub, @tor]

[tarjan-simple-1984]

Robert E. Tarjan and Mihalis Yannakakis, “Simple linear-time algorithms to test chordality of graphs, test acyclicity of hypergraphs, and selectively reduce acyclic hypergraphs”, SIAM Journal on Computing 13, 566-579 (1984), DOI: 10.1137/0213035 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["power"]
>>> order = gt.vertex_ordering(g, "rcm")
>>> print(gt.bandwidth(g), gt.bandwidth(g, order))
4927 455

The effect of the ordering is seen in the nonzero entries of the adjacency matrix, with the rows and columns in the order of the vertex indices and in the reverse Cuthill-McKee order:

>>> import matplotlib.pyplot as plt
>>> A = gt.adjacency(g)
>>> fig, ax = plt.subplots(1, 2, figsize=(6, 3))
>>> ax[0].spy(A, markersize=.1, color="#377eb8")
<...>
>>> ax[1].spy(A[order, :][:, order], markersize=.1, color="#377eb8")
<...>
>>> for a in ax:
...     a.tick_params(left=False, bottom=False, labelleft=False,
...                   labeltop=False, top=False)
>>> plt.tight_layout()
>>> plt.savefig("vertex_ordering-power.pdf")
../_images/vertex_ordering-power.png

Nonzero entries of the adjacency matrix of the western US power grid, with the vertices in the order of their indices (left) and in the reverse Cuthill-McKee order (right).#