Routing Module¶
- wayfarer.routing.find_ordered_path(edges, start_node=None, with_direction_flag=True)[source]¶
Given a collection of randomly ordered connected edges, find the full path, covering all edges, from one end to the other. A start_node can be provided to return the edges in a specific direction. Uses the eulerian_path function from networkx
- Return type:
list
[Edge
]
- wayfarer.routing.get_path_ends(edges)[source]¶
For a list of connected edges find the (unattached) end nodes TODO Check if the edges form a loop
- Return type:
tuple
[int
|str
,int
|str
]
>>> edges = [Edge(0, 1, 1, {}), Edge(1, 2, 1, {})] >>> get_path_ends(edges) (0, 2)
- wayfarer.routing.solve_all_shortest_paths(net, start_node, end_node)[source]¶
Find all shortest paths between the two nodes on the network. This includes loops and repeated nodes. A wrapper function for all_shortest_paths Unsure why less results are returned in the example below than when using all_simple_paths
- Parameters:
net (
MultiGraph
|MultiDiGraph
) – The networkstart_node (
int
|str
) – The node Id of the start nodeend_node (
int
|str
) – The node Id of the end node
- Returns:
An iterator of a list of list of nodes
>>> edges = [Edge(0, 1, "A", {}), Edge(1, 2, "B", {"LEN_": 10}), Edge(2, 1, "C", {"LEN_": 10})] >>> net = functions.edges_to_graph(edges) >>> pths = solve_all_shortest_paths(net, 0, 2) >>> print(list(pths)) [[0, 1, 2]]
# noqa: E501
- wayfarer.routing.solve_all_simple_paths(net, start_node, end_node, cutoff=10)[source]¶
Find all simple paths between the two nodes on the network. A simple path does not have any repeated nodes A wrapper function for all_simple_paths TODO add
has_path
check prior to running- Parameters:
net (
MultiGraph
|MultiDiGraph
) – The networkstart_node (
int
|str
) – The node Id of the start nodeend_node (
int
|str
) – The node Id of the end nodecutoff (
int
) – The maximum number of edges to search for before stopping the search
- Return type:
list
- Returns:
An iterator of a list of list of nodes
>>> edges = [Edge(0, 1, "A", {}), Edge(1, 2, "B", {"LEN_": 10}), Edge(2, 1, "C", {"LEN_": 10})] >>> net = functions.edges_to_graph(edges) >>> pths = solve_all_simple_paths(net, 0, 2) >>> print(list(pths)) [[0, 1, 2], [0, 1, 2]]
- wayfarer.routing.solve_matching_path(net, start_node, end_node, distance=0, cutoff=10, include_key=None)[source]¶
Return the path between the nodes that best matches the distance If no distance is supplied the shortest path is returned
Cut-off is the maximum number of edges to search for If long solves are not as expected then increase this value
include_key can be used to only include paths that contain this edge key
- Return type:
list
[Edge
] |None
- wayfarer.routing.solve_matching_path_from_nodes(net, node_list, distance)[source]¶
From a list of unordered nodes find the longest path that connects all nodes Then rerun the solve from the start to the end of the path getting a path closest to the desired distance
- Return type:
list
[Edge
] |None
- wayfarer.routing.solve_shortest_path(net, start_node, end_node, with_direction_flag=True, weight='LEN_')[source]¶
Solve the shortest path between two nodes, returning a list of Edge objects. Set weight to the attribute name for deciding the shortest path, or to None to ignore any weightings (faster).
- wayfarer.routing.solve_shortest_path_from_edges(net, edge_id_list)[source]¶
Return a path routing from edge to edge, rather than from node to node
- wayfarer.routing.solve_shortest_path_from_nodes(net, node_list, weight='LEN_')[source]¶
Return a list of nodes found by solving from each node in node_list to the next. Set weight to the attribute name for deciding the shortest path, or to None to ignore any weightings (faster).
- Return type:
list
[int
|str
]