diff --git a/py/ga_optimized_random_generator.py b/py/ga_optimized_random_generator.py index a9c000e..5c28c26 100644 --- a/py/ga_optimized_random_generator.py +++ b/py/ga_optimized_random_generator.py @@ -31,6 +31,7 @@ self.pool = self.mutate() self.pool = self.crossover_all() best_parent = self.__find_best_parents(1)[0] + print('s', self.__calc_dist_cost(best_parent, self.trials)) print(best_parent, ' ', self.calculate_tl_ratio(best_parent, self.n)) return best_parent @@ -55,14 +56,20 @@ sorted_pool = sorted(self.pool, key=lambda ss: self.fitness(ss)) return sorted_pool[:count] - def __dist_fitness(self, seq, trials): + def __calc_dist_cost(self, seq, trials): """ Calculate fitness according to the similarity to the desired uniform distribution. - :param seq: + :param seq: a string :param trials: :return: """ - pass + costs = {} + for c in list(seq): + if costs.__contains__(c): + costs[c] += 1.0 + else: + costs.setdefault(c, 1.0) + return max(list(costs.values())) def fitness(self, seq): """