rustworkx.metric_closure#

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.

Parameters:
  • 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

Returns:

A metric closure graph from the input graph

Return type:

PyGraph

Raises:

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