-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
83 lines (78 loc) · 2.67 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
73
74
75
76
77
78
79
80
81
82
83
from turtle import color
import folium
from numpy import source
from shortestpathsalgos import *
from graph import create_graph
from rich.console import Console
from rich import print
from rich.columns import Columns
import webbrowser
import networkx as nx
console = Console()
g, points = create_graph()
console.print("\n\nShortest Path Finder By Nicola && Omar",
style="bright_red", justify="center")
console.print("\nCities : ", style="bright_red underline")
console.print(Columns(points), style="bright_white underline")
webbrowser.open_new_tab('map.html')
cities = []
console.print('''
1. Walking
2. driving
Enter A Number :
''', style="bold bright_blue")
ch = int(input())
for key in points:
cities.append(key)
while True:
console.print('''
Choose Shortest path algorithm :
1. BFS
2. greedy
3. A*
0. exit
Enter A Number :
''', style="bold bright_blue")
while True:
choice = int(input())
if choice == 1:
console.print("Enter source City: ", style="bright_blue")
source = (input()).capitalize()
if source not in cities:
print("Enter a exciting city")
break
console.print("Enter target City: ", style="bright_blue")
dest = (input()).capitalize()
path = BFS(g, source, dest)
break
elif choice == 2:
console.print("Enter source City: ", style="bright_blue")
source = (input()).capitalize()
console.print("Enter target City: ", style="bright_blue")
dest = (input()).capitalize()
path = BFS(g, source, dest)
path = greedy(g, source, dest)
break
elif choice == 3:
console.print("Enter source City: ", style="bright_blue")
source = (input()).capitalize()
console.print("Enter target City: ", style="bright_blue")
dest = (input()).capitalize()
path = BFS(g, source, dest)
path = astar(g, source, dest, heuristic=None, weight="weight")
break
elif choice == 0:
exit()
else:
console.print("Enter a Valid Number!",
style="bright_red bold underline")
console.print(f"PATH : {path}")
m = folium.Map(location=[31.70487, 35.20376], zoom_start=8)
for key, [lat, long] in points.items():
folium.Marker([lat, long], popup=key).add_to(m)
pts = []
for city in path:
pts.append((points[city][0], points[city][1]))
folium.PolyLine(pts, color="red").add_to(m)
m.save('map.html')
# webbrowser.open_new_tab('map.html')