forked from anyaschukin/N-Puzzle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_plot.py
50 lines (42 loc) · 1.36 KB
/
test_plot.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
import csv
import numpy as np
import matplotlib.pyplot as plt
# read_csv reads solve_time.csv
def read_csv(filepath):
heuristics = []
with open(filepath, 'r') as file:
reader = csv.reader(file)
for row in reader:
heuristic = []
for test in row:
heuristic.append(float(test))
heuristics.append(heuristic)
return heuristics
# visualize plots min, mean & max values for each heuristic
def visualize(data, title, y_label):
_, ax1 = plt.subplots()
ax1.boxplot(data)
plt.title(title)
plt.ylabel(y_label)
plt.xlabel('Heuristic')
if len(data) == 5:
plt.xticks([1, 2, 3, 4, 5], ["manhattan", "nilsson", "outRowCol", "hamming", "euclidean"])
if len(data) == 2:
plt.xticks([1, 2], ["manhattan", "nilsson"])
plt.show()
# main reads .csv & visualizes test output
def main():
try:
solve_time = read_csv('solve_time.csv')
visualize(solve_time, 'Solve time by heuristic', 'Solve Time (Seconds)')
size_complexity = read_csv('size_complexity.csv')
visualize(size_complexity, 'Size complexity by heuristic', 'Size complexity')
time_complexity = read_csv('time_complexity.csv')
visualize(time_complexity, 'Time complexity by heuristic', 'Time complexity')
moves = read_csv('moves.csv')
visualize(moves, 'Moves by heuristic', 'Moves')
except Exception:
print("Error: Failed to visualize data. Is data valid?")
pass
if __name__ == '__main__':
main()