fix: small changes in NSGA-II
This commit is contained in:
parent
7944a36dbf
commit
09d1d08ed7
@ -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)
|
||||
|
2
test.py
2
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)
|
||||
|
Loading…
Reference in New Issue
Block a user