-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.py
27 lines (22 loc) · 1.02 KB
/
tree.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
import matplotlib.pyplot as plt
from tools.draw import draw_tree
from tools.fitness import STANDARD
from tools.main_algorithm import genetic_algorithm
# Костанта задачи
INDIVIDUAL_SIZE = len(STANDARD) # Количетсво генов в хромосове особи
# Константы генетического алгоритма
POPULATION_SIZE = 100 # Количество особей в популяции
MAX_GENERATIONS = 5000 # Максимальное число поколений
best_individual, min_values, mean_values = genetic_algorithm(
speciman_size=INDIVIDUAL_SIZE,
population_size=POPULATION_SIZE,
max_generations=MAX_GENERATIONS,
)
draw_tree(best_individual)
plt.plot(min_values, color='red')
plt.plot(mean_values, color='blue')
plt.xlabel('Поколение')
plt.ylabel('Мин/средняя приспособленность')
plt.title(
'Зависимость минимальной и средней приспособленности от поколения')
plt.show()