-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTraffic Light.py
85 lines (60 loc) · 1.96 KB
/
Traffic Light.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
for i in ['a','b','c','d','e','f']:
file_name = f"{i}.txt"
output = f"{i}_sub.txt"
fileh = open(file_name,'r')
# Streets : line 2 - 1+line 1[2]
# Paths : 1 + line 1[2] + 1 : 1 + line 1[2] + 2
for index,lines in enumerate(fileh):
if index == 0:
header = lines.split()
print(header)
list = []
end_list = []
dict = {}
fileh = open(file_name,'r')
for index,lines in enumerate(fileh):
if (index >= 1 ) and (index <= int(header[2]) ):
start = lines.strip().split()[-1]
end = lines.strip().split()[0]
if end not in list:
list.append(end)
end_list.append(end)
if start not in list:
list.append(start)
fileh = open(file_name,'r')
for index,lines in enumerate(fileh):
if (index >= 1 ) and (index <= int(header[2]) ):
end = lines.strip().split()[1]
road = lines.strip().split()[-2]
if end in dict.keys():
dict[end].append(road)
else:
dict[end] = [road]
for nodes,roads in dict.items():
for i,road in enumerate(roads):
#k = road
#count = 0
#fileh = open(file_name, 'r')
#for index, lines in enumerate(fileh):
#if index >= int(header[2]) + 1 and index <= int(header[2]) + int(header[3]):
#lines = lines.strip().split()
#if road in lines:
# count = count + 1
dict[nodes][i] = {road:1}
file = open(output,'w')
file.write(f"{len(dict)} \n")
for nodes,roads in dict.items():
list = []
for road in roads:
for road,value in road.items():
print(value)
# list = [list[[i]]*3//max(list) for i in list]
# for i,road in enumerate(roads):
# for key in road.keys():
# road[key] = list[i]
for nodes,roads in dict.items():
file.write(f"{nodes}\n")
file.write(f"{len(roads)} \n")
for road in roads:
for keys,values in road.items():
file.write(f"{keys} {1} \n")