From 48f12b025ef455316d48ce26f843b29c03090e6f Mon Sep 17 00:00:00 2001 From: miraaitsaada Date: Fri, 19 Jul 2019 17:28:58 +0200 Subject: [PATCH] correction of EA and GA for nondeterministic fitness functions --- Solid/EvolutionaryAlgorithm.py | 2 +- Solid/GeneticAlgorithm.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Solid/EvolutionaryAlgorithm.py b/Solid/EvolutionaryAlgorithm.py index bdedd72..d077de8 100644 --- a/Solid/EvolutionaryAlgorithm.py +++ b/Solid/EvolutionaryAlgorithm.py @@ -132,7 +132,7 @@ def _select_n(self, n): shuffle(self.population) total_fitness = sum(self.fitnesses) if total_fitness != 0: - probs = list([self._fitness(x) / total_fitness for x in self.population]) + probs = list([self.fitnesses[i] / total_fitness for i in range(len(self.population))]) else: return self.population[0:n] res = [] diff --git a/Solid/GeneticAlgorithm.py b/Solid/GeneticAlgorithm.py index 01affd2..16c5f30 100644 --- a/Solid/GeneticAlgorithm.py +++ b/Solid/GeneticAlgorithm.py @@ -133,7 +133,7 @@ def _select_n(self, n): shuffle(self.population) total_fitness = sum(self.fitnesses) if total_fitness != 0: - probs = list([self._fitness(x) / total_fitness for x in self.population]) + probs = list([self.fitnesses[i] / total_fitness for i in range(len(self.population))]) else: return self.population[0:n] res = []