This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.


metric_closure(graph, weight_fn, /)#

Return the metric closure of a graph

The metric closure of a graph is the complete graph in which each edge is weighted by the shortest path distance between the nodes in the graph.

  • graph (PyGraph) – The input graph to find the metric closure for

  • weight_fn – A callable object that will be passed an edge’s weight/data payload and expected to return a float. For example, you can use weight_fn=float to cast every weight as a float


A metric closure graph from the input graph

Return type:



ValueError – when an edge weight with NaN or negative value is provided.