forked from dcampora/velopix_tracking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_cellular_automaton.py
97 lines (78 loc) · 2.99 KB
/
run_cellular_automaton.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
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python3
# import event class
import event_model as em
import json
import validator_lite as vl
import os
from CellularAutomaton.CellularAutomaton import CellularAutomaton
from classical_solver import classical_solver
from graph_dfs import graph_dfs
import time
import csv
import sys
solutions = {}
# For 1 of the files; algorithm runs quickly
# f = open("velojson/9.json")
# json_data = json.loads(f.read())
# event = em.event(json_data)
# f.close()
#
# # solve with CA
# ca = CellularAutomaton()
# # solutions["CA"], times = ca.solve_without_Profiling(event)
# solutions["CA"], times = ca.solve_with_profiling(event)
#
#
# for k, v in iter(sorted(solutions.items())):
# print("%s method validation" % (k))
# vl.validate_print([json_data], [v])
# print()
#
#
# print (times)
# For all 30 Jsons
all_times = []
index = 1
for file in os.listdir("velojson"):
if file.endswith(".json"):
# f = open("velojson/23.json")
f = open("velojson/"+file)
json_data = json.loads(f.read())
event = em.event(json_data)
f.close()
for a in range(5):
# current_run = []
# Solve with the classic method
# classical = classical_solver()
# start = time.clock()
# solutions["classic"] = classical.solve(event)
# current_run.append(time.clock() - start)
# Solve with the DFS method
# dfs = graph_dfs()
# start = time.clock()
# solutions["dfs"] = dfs.solve(event)
# current_run.append(time.clock() - start)
# solve with CA
ca = CellularAutomaton()
start = time.clock()
# solutions["CA"], time_parts = ca.solve_with_profiling(event)
solutions["CA"], time_parts = ca.solve_without_Profiling(event)
# time_parts.append(time.clock() - start)
# time_parts.append(event.number_of_hits)
# time_parts.append(max([(len(i.hits())) for i in event.sensors]))
# all_times.append(time_parts)
# for k, v in iter(sorted(solutions.items())):
# print("%s method validation" % (k))
# vl.validate_print([json_data], [v])
# # print()
print("File " + str(index) + " done", file=sys.stderr)
index += 1
# with open ("Profiling/DetailedMeasure-030518_5runs_per_file.csv", 'a') as output_file:
# wr = csv.writer(output_file, delimiter=',', lineterminator='\n')
# # wr.writerow(['CA', 'Total Hits in Event', 'Maximum number of Hits in a Sensor'])
# wr.writerow(['Doublet Creation', 'Neighbour search', 'CA', 'Extract Possible Tracks', 'Remove Short', 'Remove Ghost and Clones', 'Full Time', 'Total Hits in Event', 'Maximum number of Hits in a Sensor'])
# for line in all_times:
# # wr.writerow([line[0], line[1], line[2]])
# # wr.writerow([line[0]])
# wr.writerow([line[0], line[1], line[2], line[3], line[4], line[5], line[6], line[7], line[8]])
# print(line)