-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
65 lines (57 loc) · 2.47 KB
/
main.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
from shapely.geometry import Polygon
import geometry
import a_star
import sys
import time
def read_data_from_file():
with open(sys.argv[1]) as file:
gallery_coordinates = [[float(x) for x in line.split()] for line in file]
return gallery_coordinates
def print_results(cameras,node,a_star_time):
print("LISTA WSZYSTKICH DOSTĘPNYCH KAMER: ")
print_cameras_coordinates(cameras)
if node is None:
print("NIE DA SIĘ POKRYĆ WSZYSTKIMI KAMERAMI CAŁEGO OBSZARU!")
return
print("\nKAMERY, KTÓRE NALEŻY WŁĄCZYĆ: ")
print_cameras_to_turn_on(node)
print()
print("Czas wykonania algorytmu: {}".format(a_star_time))
def print_cameras_coordinates(cameras):
for (i, camera) in enumerate(geometry.Gallery.cameras):
print("Kamera nr {} o współrzędnych {}".format(i,camera.point))
def print_cameras_to_turn_on(node):
counter=0
for (i, camera) in enumerate(node.camerasState):
if node.camerasState[i]:
counter=counter+1
print("Kamera nr {} o współrzędnych {}".format(i,geometry.Gallery.cameras[i].point))
print("\nMINIMALNA LICZBA KAMER DO POKRYCIA OBSZARU: {}".format(counter))
def print_experiment_results(a_star_time,cameras,node):
amountOfTurnOnCameras = 0
if node is None:
print("{}\t{}\t{}\t{}\t{}".format(float(sys.argv[2]), float(sys.argv[3]), a_star_time, geometry.Gallery.camerasAmount,"-"))
return
for (i,camera) in enumerate(node.camerasState):
if node.camerasState[i] == True:
amountOfTurnOnCameras +=1
print("{}\t{}\t{}\t{}\t{}".format(float(sys.argv[2]),float(sys.argv[3]),a_star_time,geometry.Gallery.camerasAmount,amountOfTurnOnCameras))
def main():
radius, net_density=(float(sys.argv[2]), float(sys.argv[3]))
gallery_coordinates = read_data_from_file()
geometry.Gallery.gallery_polygon = Polygon(gallery_coordinates)
cameras_coordinates=geometry.get_cameras_coordinates(net_density, gallery_coordinates)
cameras = geometry.get_cameras_array(cameras_coordinates,radius)
geometry.Gallery.cameras = cameras
geometry.Gallery.camerasAmount = len(cameras)
userFriendlyOutput=(sys.argv[4]=='t')
start = time.time()
node = a_star.aStar(cameras)
end = time.time()
a_star_time = round(end - start,4)
if userFriendlyOutput:
print_results(cameras,node,a_star_time)
if not userFriendlyOutput:
print_experiment_results(a_star_time,cameras,node)
if __name__ == "__main__":
main()