From 2abe115f47f81cd9867dc1a62b459eae35b98e22 Mon Sep 17 00:00:00 2001 From: LebedevIlyaG Date: Sat, 27 Apr 2024 22:35:04 +0300 Subject: [PATCH] Fixed examples of optimizing the launch of a genetic algorithm --- .../TSP/_1D/Problems/ga_tsp_vary_mutation.py | 4 ++-- examples/Genetic_algorithm/TSP/_2D/Problems/ga_tsp_2d.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/Genetic_algorithm/TSP/_1D/Problems/ga_tsp_vary_mutation.py b/examples/Genetic_algorithm/TSP/_1D/Problems/ga_tsp_vary_mutation.py index 0037a3c5..4c9ddef3 100644 --- a/examples/Genetic_algorithm/TSP/_1D/Problems/ga_tsp_vary_mutation.py +++ b/examples/Genetic_algorithm/TSP/_1D/Problems/ga_tsp_vary_mutation.py @@ -58,10 +58,10 @@ def calculate(self, point: Point, function_value: FunctionValue) -> FunctionValu :param function_value: объект хранения значения целевой функции в точке """ mutation_prob = point.float_variables[0] - ga_tsp = GA_TSP(func=self.calc_total_distance, + ga_tsp = GA_TSP(func=lambda x: self.calc_total_distance(x), n_dim=self.n_dim, size_pop=self.populationSize, max_iter=self.numberOfIterations, prob_mut=mutation_prob) best_points, best_distance = ga_tsp.run() function_value.value = best_distance[0] # print(best_distance[0]) - return function_value + return function_value \ No newline at end of file diff --git a/examples/Genetic_algorithm/TSP/_2D/Problems/ga_tsp_2d.py b/examples/Genetic_algorithm/TSP/_2D/Problems/ga_tsp_2d.py index d7ad9093..c948f7b6 100644 --- a/examples/Genetic_algorithm/TSP/_2D/Problems/ga_tsp_2d.py +++ b/examples/Genetic_algorithm/TSP/_2D/Problems/ga_tsp_2d.py @@ -72,10 +72,10 @@ def calculate(self, point: Point, function_value: FunctionValue) -> FunctionValu if num_population % 2 != 0: num_population -= 1 - ga_tsp = GA_TSP(func=self.calc_total_distance, + ga_tsp = GA_TSP(func=lambda x: self.calc_total_distance(x), n_dim=self.n_dim, size_pop=num_population, max_iter=int(self.numberOfIterations), prob_mut=mutation_prob) best_points, best_distance = ga_tsp.run() function_value.value = best_distance[0] - print(best_distance[0]) + #print(best_distance[0]) return function_value