Код: Выделить всё
import numpy as np
import funciones
# Differential Evolution algorithm parameters
NP = 50 # Population size
F = 0.3 # Mutation factor
CR = 0.7 # Crossover rate
GEN = 500 # Number of generations
# Function to check if a solution is feasible
def is_feasible(x, problem_id=4):
return all(funciones.restrictions(x, problem_id)
Моя проблема заключается в обращении с равенствами. Я попытался добавить их так, но когда я пробую код, он дает мне «не найдено возможных решений»: < /p>
elif problema_id == 4:
g = np.zeros(5)
g[0] = -x[3] + x[2] - 0.55
g[1] = -x[2] + x[3] - 0.55
h3 = 1000 * np.sin(-x[2] - 0.25) + 1000 * np.sin(-x[3] - 0.25) + 894.8 - x[0]
g[2] = np.abs(h3)
h4 = 1000 * np.sin(x[2] - 0.25) + 1000 * np.sin(x[2] - x[3] - 0.25) + 894.8 - x[1]
g[3] = np.abs(h4)
h5 = 1000 * np.sin(x[3] - 0.25) + 1000 * np.sin(x[3] - x[2] - 0.25) + 1294.8
g[4] = np.abs(h5)
return g
Подробнее здесь: https://stackoverflow.com/questions/795 ... -evolution