def n_shortest_paths(self, source, target, n, distance=None, strategy="naive", exclude_edge=False): """Compute n shortest paths from the source to the target. Two search strategies are available: 'naive' and 'yen'. The naive strategy first finds the set of all shortest paths from the source to the target node, it then ranks them by the cumulative distance score and returns n best paths. The second strategy uses Yen's algorithm [1] for finding n shortest paths. The first naive strategy performs better for highly dense graphs (where every node is connected to almost every other node). Note that if there are less than n unweighted shortest paths in the graph, the naive strategy may return less than n paths. 1. Yen, Jin Y. "Finding the k shortest loopless paths in a network". Management Science 17.11 (1971): 712-716. Parameters ---------- source : str Source node ID target : str Target node ID n : int Number of top paths to include in the result distance : str, optional The name of the attribute to use as the edge distance path_condition : func, optional Edge filtering function returning Boolean flag strategy : str, optional Path finding strategy: `naive` or `yen`. By default, `naive`. exclude_edge : bool, optional Flag indicating whether the direct edge from the source to the target should be excluded from the result (if exists). Returns ------- paths : list List containing top n best paths according to the distance score """ if strategy == "yen": raise PathFinder.NotImplementedError( "Yen's algorithm for finding n shortest paths " "is currently not implemented") else: return super().n_shortest_paths(source, target, n, distance=distance, strategy="naive", exclude_edge=exclude_edge)
def _compute_yen_shortest_paths(graph, source, target, n, distance, exclude_edge=False): """Compute n shortest paths using the Yen's algo.""" raise PathFinder.NotImplementedError( "Yen's algorithm for finding n shortest paths " "is currently not implemented for graph-tool backend")