Last active
July 22, 2019 13:40
-
-
Save bombsimon/6f7ac002c52139ea9683d66674d0082a to your computer and use it in GitHub Desktop.
Example to show shortes route
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" Find shortest path """ | |
import networkx as nx | |
def main(): | |
""" Main method """ | |
objs = [ | |
{"src": "SWE", "dst": "LDN"}, | |
{"src": "SWE", "dst": "CPH"}, | |
{"src": "SWE", "dst": "LAX"}, | |
{"src": "LAX", "dst": "NYC"}, | |
{"src": "LDN", "dst": "CPH"}, | |
{"src": "CPH", "dst": "SWE"}, | |
{"src": "CPH", "dst": "SPA"}, | |
{"src": "SPA", "dst": "BEI"}, | |
{"src": "LDN", "dst": "BEI"}, | |
] | |
graph = nx.Graph() | |
for obj in objs: | |
graph.add_edge(obj["src"], obj["dst"]) | |
print(nx.shortest_path(graph, source="SWE", target="BEI")) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment