-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreateMap.py
45 lines (41 loc) · 1.37 KB
/
createMap.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
from Loader.mapLoader import mapLoader
import networkx as nx
import matplotlib.pyplot as plt
places=[]
with open('Loader/places.txt', 'r') as f:
i=0
reader = f.readlines()
for place in reader:
if place!='\n':
i+=1
places.append(place)
def loadDistances(place1, place2):
distanceMatrix=[]
with open('Loader/distances.txt') as results:
for result in (results.readlines()):
t=[]
for i in result.split(' '):
if i!='\n':
if i!='nan':
x=float(i)
t.append(x)
else:
t.append(19999)
distanceMatrix.append(t)
return distanceMatrix[places.index(place1)][places.index(place2)]
def makeMap(path):
loader = mapLoader(100)
loader.loadPlaces()
loader.loadCoordinates()
loader.loadGraph()
for i in range(0,len(path)-1):
place1 = loader.places[path[i]]
place2 = loader.places[path[i+1]]
w=loadDistances(place1, place2)
if(w>0 and w<1000):
loader.Graph.add_edge(places.index(place1),places.index(place2), weight=w)
pos = dict(enumerate(loader.coordinates))
nx.draw(loader.Graph, pos, with_labels=True)
labels = nx.get_edge_attributes(loader.Graph,'weight')
nx.draw_networkx_edge_labels(loader.Graph,pos,edge_labels=labels)
plt.show()