From 09d1d08ed79a32d908b92d355f6f98940e22e483 Mon Sep 17 00:00:00 2001 From: s_ranjbar Date: Wed, 13 Nov 2024 14:15:22 +0100 Subject: [PATCH] fix: small changes in NSGA-II --- .../genetic_algorithm/multi_objective_genetic_algorithm.py | 5 ++--- test.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/energy_system_modelling_package/energy_system_modelling_factories/system_sizing_methods/genetic_algorithm/multi_objective_genetic_algorithm.py b/energy_system_modelling_package/energy_system_modelling_factories/system_sizing_methods/genetic_algorithm/multi_objective_genetic_algorithm.py index 3b460294..142be4e6 100644 --- a/energy_system_modelling_package/energy_system_modelling_factories/system_sizing_methods/genetic_algorithm/multi_objective_genetic_algorithm.py +++ b/energy_system_modelling_package/energy_system_modelling_factories/system_sizing_methods/genetic_algorithm/multi_objective_genetic_algorithm.py @@ -38,7 +38,7 @@ class MultiObjectiveGeneticAlgorithm: operators such as crossover and mutation rates. """ - def __init__(self, population_size=20, generations=20, crossover_rate=0.9, mutation_rate=0.33, + def __init__(self, population_size=100, generations=100, crossover_rate=0.9, mutation_rate=0.1, number_of_selected_solutions=None, optimization_scenario=None): self.population_size = population_size self.population = [] @@ -441,13 +441,11 @@ class MultiObjectiveGeneticAlgorithm: return new_population def solve_ga(self, building, energy_system): - # df = pd.DataFrame() self.initialize_population(building, energy_system) for n in range(self.generations + 1): print(n) progeny_population = [] while len(progeny_population) < self.population_size: - parent1, parent2 = random.choice(self.population), random.choice(self.population) child1, child2 = self.sbx_crossover(parent1, parent2) self.polynomial_mutation(child1.individual, building, energy_system) @@ -457,6 +455,7 @@ class MultiObjectiveGeneticAlgorithm: progeny_population.extend([child1, child2]) self.population.extend(progeny_population) fronts = self.fast_non_dominated_sorting() + print(fronts) crowding_distances = [0] * len(self.population) for front in fronts: self.calculate_crowding_distance(front=front, crowding_distance=crowding_distances) diff --git a/test.py b/test.py index 73be2f09..644d3548 100644 --- a/test.py +++ b/test.py @@ -54,5 +54,5 @@ energy_plus_workflow(city, energy_plus_output_path) random_assignation.call_random(city.buildings, random_assignation.residential_new_systems_percentage) EnergySystemsFactory('montreal_future', city).enrich() for building in city.buildings: - energy_system = building.energy_systems[-1] + energy_system = building.energy_systems[1] MultiObjectiveGeneticAlgorithm(optimization_scenario='energy-consumption_cost').solve_ga(building, energy_system)