-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
74 lines (65 loc) · 2.07 KB
/
app.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
import streamlit as st
from tubemap import tubemap
import pandas as pd
import time
stations = tubemap.keys()
st.markdown("<h1 style='text-align: center; color: white;'>Delhi Metro Travel Planner</h1>", unsafe_allow_html=True)
st.image('./metro.jpg')
st.markdown("<h2 style='text-align: center; color: white;'>Enter Station Names</h2>", unsafe_allow_html=True)
m1 = st.selectbox("Source",stations)
m2 = st.selectbox("Destination",stations)
'''
def find_path(graph, start, end, path=[]):
path = path + [start]
if start == end:
return path
if start not in graph:
return None
for node in graph[start]:
if node not in path:
newpath = find_path(graph, node, end, path)
if newpath: return newpath
return None
def find_all_paths(graph, start, end, path=[]):
path = path + [start]
if start == end:
return [path]
if start not in graph:
return []
paths = []
for node in graph[start]:
if node not in path:
newpaths = find_all_paths(graph, node, end, path)
for newpath in newpaths:
paths.append(newpath)
return paths
'''
def find_shortest_path(graph, start, end, shortestLength=-1, path=[]):
path = path + [start]
if start == end:
return path
if start not in graph:
return None
shortest = None
for node in graph[start]:
if node not in path:
if shortestLength==-1 or len(path)<(shortestLength-1):
newpath = find_shortest_path(graph, node, end, shortestLength, path)
if newpath:
if not shortest or len(newpath) < len(shortest):
shortest = newpath
shortestLength = len(newpath)
return shortest
stationFrom=m1
stationTo=m2
if(st.button('Search')):
st.write("Searching shortest route... This may take a while...")
path=find_shortest_path(tubemap,stationFrom,stationTo)
output_data = pd.DataFrame({"Station Name" : path})
output_data.index += 1
my_bar = st.progress(0)
for percent_complete in range(100):
time.sleep(0.001)
my_bar.progress(percent_complete + 1)
st.write("Suggested Route: ")
st.write(output_data)