-
Notifications
You must be signed in to change notification settings - Fork 1
/
execute_tests.py
75 lines (67 loc) · 2.38 KB
/
execute_tests.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
import gc
from random import seed
from simulation.tools import *
from simulation.environment import Environment
from time import time
from ga import GA
from gc import disable, enable
import json
import csv
import sys
from pathlib import Path
def main(task_number):
routes = {}
with open('astar/astarRoutes.json', 'r') as f:
routes = json.load(f)
raster_map = get_raster_map('rendering/map.csv')
graph, raster_to_graph, agents_positions, picking_stations = gen_graph(raster_map)
graph_to_raster = gen_graph_to_raster(graph)
new_dic = {}
for key, value in routes.items():
if isinstance(value, dict):
new_dic[graph_to_raster[int(key)][0]] = {}
for key2, value2 in value.items():
nl = []
for i in value2:
nl.append(graph_to_raster[int(i)][0])
new_dic[graph_to_raster[int(key)][0]][graph_to_raster[int(key2)][0]] = nl
else:
nl = []
for i in value:
nl.append(graph_to_raster[int(i)][0])
new_dic[graph_to_raster[int(key)][0]] = nl
routes = new_dic
disable()
e = Environment(task_number=task_number, scheduling="Greedy0",
simulation_name="test", raster_map=raster_map, graph=graph, raster_to_graph=raster_to_graph,
agents_positions=agents_positions, graph_to_raster=graph_to_raster, routes=routes, picking_stations=picking_stations)
name_ga = "".join(["ga_", str(task_number), ".csv"])
t = time()
start = 0
my_file = Path(name_ga)
if my_file.is_file():
file = open(name_ga, "r")
line_count = 0
for line in file:
if line != "\n":
line_count += 1
file.close()
start = line_count
# file exists
# run GA
with open(name_ga, 'a') as f:
write = csv.writer(f)
for seed_i in range(start, 20):
e.seed = seed_i
e.task_handler.new_task_pool(task_number)
print("Ga run number "+str(seed_i+1))
ga = GA(0, e.new_simulation, popsize=100, maxepoc=100000, n=task_number, m=8)
res = ga.run()
gc.collect()
write.writerow(res)
#################################
elapsed = time() - t
print("Elapsed: "+str(elapsed))
if __name__ == '__main__':
print(sys.argv[1]+" tasks")
main(int(sys.argv[1]))