-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlifi_proj_djikstra.py
94 lines (71 loc) · 2.28 KB
/
lifi_proj_djikstra.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from dijkstar import Graph, find_path
import numpy as np
# architecture=[[0,1,0,0,0,0,1],
# [1,0,1,0,0,0,0],
# [0,1,0,1,0,0,0],
# [0,0,1,0,1,0,0],
# [0,0,0,1,0,1,0],
# [0,0,0,0,1,0,1],
# [1,0,0,0,0,1,0]]
'''
Tested architecture -
0 ------------ 6
| |
| |
1 5
| |
| |
2------3-------4
'''
architecture=[[0,1,0,0,0,0,0,0,0,0,0,1,0,0,], #0
[1,0,1,0,0,0,0,0,0,0,0,0,1,0], #1
[0,1,0,1,0,0,0,0,0,0,0,0,1,1], #2
[0,0,1,0,1,0,0,0,0,0,0,0,0,1], #3
[0,0,0,1,0,1,0,0,0,0,0,0,0,0], #4
[0,0,0,0,1,0,1,0,0,0,0,0,0,0], #5
[0,0,0,0,0,1,0,1,0,0,0,0,0,0], #6
[0,0,0,0,0,0,1,0,1,0,0,0,0,1], #7
[0,0,0,0,0,0,0,1,0,1,0,0,1,1], #8
[0,0,0,0,0,0,0,0,1,0,1,0,1,0], #9
[0,0,0,0,0,0,0,0,0,1,0,1,0,0], #10
[1,0,0,0,0,0,0,0,0,0,1,0,0,0], #11
[0,1,1,0,0,0,0,0,1,1,0,0,0,0], #12
[0,0,1,1,0,0,0,1,1,0,0,0,0,0,]] #13
'''
Tested architecture -
10----9----------8--------------7------6
| | | |
| | | |
11 12 13 |
| | | |
| | | |
0--------1----------2--------3---------4
'''
arc=np.array(architecture)
graph=Graph()
(r,c)=arc.shape
i=0
j=0
while(i<=r-1):
while(j<=c-1):
if(architecture[i][j]!=0):
graph.add_edge(i,j,100)
print('edge created between',i,' ',j)
j=j+1
j=0
i=i+1
i=r-1
j=c-1
while(i>=0):
while(j>=0):
if(architecture[i][j]!=0):
graph.add_edge(j,i,100)
print('edge created between',i,' ',j)
j=j-1
j=c-1
i=i-1
#path=r"C:/Users/arindam bhattacharya/Documents/pythonProject/a/lifi"
start=int(input('enter the starting point: ')) #should be taken from DB
end=int(input('enter ending point: ')) #should be taken from user
#graph.dump(path)
print(list(find_path(graph,start,end))[0]) #returned to the user