trplearn.shortest_path module#
- class trplearn.shortest_path.TropicalShortestPath[source]#
Bases:
objectAll-pairs shortest path solver using tropical (min-plus) algebra. This class acts as an interpretation layer over the algebraic star() operation.
Examples
>>> import numpy as np >>> from trplearn.shortest_path import TropicalShortestPath >>> adj = [[0, 3, np.inf], [np.inf, 0, 1], [np.inf, np.inf, 0]] >>> tsp = TropicalShortestPath() >>> tsp.compute(adj) >>> tsp.distances array([[0., 3., 4.], [inf, 0., 1.], [inf, inf, 0.]])
- compute(adjacency_matrix)[source]#
Compute the shortest path distance matrix.
- Parameters:
adjacency_matrix (array-like) – Weighted adjacency matrix of the graph.
- Returns:
self
- Return type:
object
- property distances#
Return the calculated distance matrix as a numpy array.
- trplearn.shortest_path.all_pairs_shortest_paths(adjacency_matrix)[source]#
Compute all-pairs shortest paths using Min-Plus algebra.
- Parameters:
adjacency_matrix (array-like) – Weighted adjacency matrix of the graph. Use np.inf for no edge between nodes.
- Returns:
The all-pairs shortest path distance matrix.
- Return type: