AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Node starting cleanexit1/31/2024 Examples - > G = nx.path_graph(5) > print(nx.shortest_path(G, source=0, target=4)) > p = nx.shortest_path(G, source=0) # target not specified > p # shortest path from source=0 to target=3 > p = nx.shortest_path(G, target=4) # source not specified > p # shortest path from source=1 to target=4 > p = nx.shortest_path(G) # source, target not specified > p # shortest path from source=2 to target=4 Notes - There may be more than one shortest path between a source and target. ValueError If `method` is not among the supported options. Raises - NodeNotFound If `source` is not in `G`. If neither the source nor target are specified return a dictionary of dictionaries with path=. If only the target is specified, return a dictionary keyed by sources with a list of nodes in a shortest path from one of the sources to the target. If only the source is specified, return a dictionary keyed by targets with a list of nodes in a shortest path from the source to one of the targets. If the source and target are both specified, return a single list of nodes in a shortest path from the source to the target. ![]() Returns - path: list or dictionary All returned paths include both the source and target in the path. If `weight` is None, unweighted graph methods are used, and this suggestion is ignored. Supported options: 'dijkstra', 'bellman-ford'. method : string, optional (default = 'dijkstra') The algorithm to use to compute the path. The function must accept exactly three positional arguments: the two endpoints of an edge and the dictionary of edge attributes for that edge. If this is a function, the weight of an edge is the value returned by the function. Any edge attribute not present defaults to 1. If a string, use this edge attribute as the edge weight. weight : None, string or function, optional (default = None) If None, every edge has weight/distance/cost 1. If not specified, compute shortest paths to all possible nodes. ![]() target : node, optional Ending node for path. If not specified, compute shortest paths for each possible starting node. ![]() Parameters - G : NetworkX graph source : node, optional Starting node for path. _dispatch def shortest_path ( G, source = None, target = None, weight = None, method = "dijkstra" ): """Compute shortest paths in the graph.
0 Comments
Read More
Leave a Reply. |