I really don't understand what is going wrong so I'm going to try to outline everything. So I have this class called SortingNetwork which has def __init__(self):
It generates different random numbers every time it compiles
Then I have this in another file:
from sorting_network import SortingNetwork
POPULATION_SIZE = 20 #MUST BE DIVISIBLE BY 2
class Individual:
def __init__(self):
self.network = SortingNetwork()
self.fitness = 0.0
class Population:
def __init__(self):
self.individuals = [Individual() for i in range(POPULATION_SIZE)]
def evaluate(self):
for i in range(0,POPULATION_SIZE):
self.individuals[i].fitness=self.individuals[i].network.evaluate()
def run_genetic_algorithm():
population = Population()
population.evaluate()
print(population)
Every individual has the same network and same fitness. Each time I run it though the network and fitness are different from before but all 20 are still the same network and fitness.
Aucun commentaire:
Enregistrer un commentaire