Фитнес функция как параметр

This commit is contained in:
2025-09-11 11:06:19 +03:00
parent a1a53ef749
commit 1732a1dbb6
3 changed files with 33 additions and 19 deletions

View File

@@ -1,11 +1,19 @@
import math
import os
from gen import GARunConfig, genetic_algorithm
def target_function(x: float) -> float:
"""f(x) = sin(x)/x^2"""
return math.sin(x) / (x * x)
# Запуск эксперимента с генетическим алгоритмом
config = GARunConfig(
x_min=3.1,
x_max=20.0,
fitness_func=target_function,
precision_digits=3,
pop_size=15,
pc=0.7,