Фитнес функция как параметр
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user