-
Notifications
You must be signed in to change notification settings - Fork 0
/
routerA.py
76 lines (58 loc) · 2.15 KB
/
routerA.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#sources:
#https://pypi.python.org/pypi/Dijkstar/2.2
#https://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/io.html
# http://www.bogotobogo.com/python/python_Dijkstras_Shortest_Path_Algorithm.php
# https://stackoverflow.com/questions/13795758/what-is-sys-maxint-in-python-3
from dijkstar import Graph, find_path
graph = Graph()
graph.add_edge('A', 'B', {'cost' :4})
graph.add_edge('B', 'A', {'cost' :4})
graph.add_edge('A', 'C', {'cost' :3})
graph.add_edge('C', 'A', {'cost' :3})
graph.add_edge('A', 'E', {'cost' :7})
graph.add_edge('E', 'A', {'cost' :7})
graph.add_edge('B', 'C', {'cost' :6})
graph.add_edge('C', 'B', {'cost' :6})
graph.add_edge('B', 'L', {'cost' :5})
graph.add_edge('L', 'B', {'cost' :5})
graph.add_edge('C', 'D', {'cost' :11})
graph.add_edge('D', 'C', {'cost' :11})
graph.add_edge('D', 'F', {'cost' :6})
graph.add_edge('F', 'D', {'cost' :6})
graph.add_edge('D', 'G', {'cost' :10})
graph.add_edge('G', 'D', {'cost' :10})
graph.add_edge('D', 'L', {'cost' :9})
graph.add_edge('L', 'D', {'cost' :9})
graph.add_edge('F', 'L', {'cost' :5})
graph.add_edge('L', 'F', {'cost' :5})
graph.add_edge('E', 'G', {'cost' :5})
graph.add_edge('G', 'E', {'cost' :5})
cost_func = lambda u, v, e, prev_e: e['cost']
#src = input('Select source router (A-L): ')
#dest = input('Enter destination vertex (A-L): ')
src = 'B'
print('Source: '+src)
dest = 'A'
print('Destination: '+dest)
print(find_path(graph, src, dest, cost_func=cost_func))
dest = 'B'
print('Destination: '+dest)
print(find_path(graph, src, dest, cost_func=cost_func))
dest = 'C'
print('Destination: '+dest)
print(find_path(graph, src, dest, cost_func=cost_func))
dest = 'D'
print('Destination: '+dest)
print(find_path(graph, src, dest, cost_func=cost_func))
dest = 'E'
print('Destination: '+dest)
print(find_path(graph, src, dest, cost_func=cost_func))
dest = 'F'
print('Destination: '+dest)
print(find_path(graph, src, dest, cost_func=cost_func))
dest = 'G'
print('Destination: '+dest)
print(find_path(graph, src, dest, cost_func=cost_func))
dest = 'L'
print('Destination: '+dest)
print(find_path(graph, src, dest, cost_func=cost_func))