-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (52 loc) · 1.68 KB
/
Copy pathmain.py
File metadata and controls
60 lines (52 loc) · 1.68 KB
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
import building
import antenna
def main():
fileName = 'data_scenarios_f_tokyo.in'
buildings = []
antennas = []
# load the file
with open(fileName, 'r') as reader:
lines = reader.readlines()
w, h = lines[0].strip().split(" ")
grid = [[0]* int(w) for _ in range(int(h))]
n, _, r = lines[1].strip().split(" ")
print(f'n: {n}')
for line in lines[2: int(n) + 1]:
x, y, latency, connection_speed = line.strip().split(" ")
buildings.append(building.Building(x, y, latency, connection_speed))
grid[int(y)][int(x)] = 1
id = 0
for line in lines[2+int(n):]:
r, c = line.strip().split(" ")
antennas.append(antenna.Antenna(id, r, c))
id += 1
# process
antennas = process(h, w, buildings, antennas)
# output
outfile = fileName.split('.')[0] + '.out'
with open(outfile, 'w') as writer:
writer.write(f'{len(antennas)}\n')
for an in antennas:
try:
writer.write(f'{an.id} {an.x} {an.y}\n')
except:
print('oops')
def process(h, w, buildings, antennas):
count = 0
# for y in range(int(h)):
# for x in range(int(w)):
# if count > len(antennas):
# return antennas
# if grid[y][x] == 1:
# antennas[count].set_coords(x, y)
# count += 1
print(len(buildings))
for b in buildings:
antennas[count].set_coords(b.x, b.y)
count += 1
if count == len(antennas):
print('returning')
return antennas
return antennas
if __name__ == "__main__":
main()