-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaverage_fitness_plot.py
42 lines (29 loc) · 1.18 KB
/
average_fitness_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
import json
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["figure.figsize"] = (10, 4)
average_instance = []
for i in range(1, 10):
average = 0
for j in range(0, 30):
json_file = open("file_{}/fistness_history_test_{}.json".format(i, j))
json_obj = json.load(json_file)
history = json_obj["history"]
average += history[len(history)-1]
average_instance.append(int(average/30))
print(average_instance)
# plt.plot(average_instance)
# optimal = [24381, 59312, 120130, 23064, 59187, 117726, 21946, 56693, 115868]
X = ['File 1', 'File 2', 'File 3', 'File 4', 'File 5', "File 6", "File 7", "File 8", "File 9"]
Y_optimal = [24381, 59312, 120130, 23064, 59187, 117726, 21946, 56693, 115868]
Y_GA = average_instance
X_axis = np.arange(len(X))
plt.bar(X_axis - 0.2, Y_GA, 0.4, label='Average Fitness', color="royalblue")
plt.bar(X_axis + 0.2, Y_optimal, 0.4, label='Optimal value', color='firebrick')
plt.xticks(X_axis, X)
plt.xlabel("Instances", fontsize=13)
plt.ylabel("Fitness (#)", fontsize=13)
plt.title("Best individual average fitness", fontsize=13)
plt.legend()
plt.savefig("best_chromo_fitness_average.png", bbox_inches="tight")
plt.show()