Merge pull request 'optimization' (#17) from optimization into main

Reviewed-on: https://nextgenerations-cities.encs.concordia.ca/gitea/s_ranjbar/energy_system_modelling_workflow/pulls/17
This commit is contained in:
Saeed Ranjbar 2024-08-08 12:26:48 -04:00
commit 1a43e65992
8 changed files with 61 additions and 125 deletions

View File

@ -92,9 +92,8 @@ for building in city.buildings:
fuel_tariffs=['Electricity-D', 'Gas-Energir']).life_cycle
lcc_dataframe.to_csv(cost_analysis_output_path / f'{building.name}_retrofitted_lcc.csv')
retrofitted_life_cycle_cost[f'{building.name}'] = cost_data(building, lcc_dataframe, cost_retrofit_scenario)
for i in range(12):
dhw_consumption = 0
for building in city.buildings:
dhw_consumption += building.domestic_hot_water_consumption[cte.MONTH][i] / 3.6e6
EnergySystemRetrofitReport(city, output_path, 'PV Implementation and System Retrofit',
current_status_energy_consumption, retrofitted_energy_consumption,
current_status_life_cycle_cost, retrofitted_life_cycle_cost).create_report()

View File

@ -1,55 +0,0 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-73.58000127109773,
45.49613461675315
],
[
-73.57962787855432,
45.496524875557746
],
[
-73.57996357265695,
45.49668114195629
],
[
-73.57996427397713,
45.496680342403664
],
[
-73.58034707390021,
45.49625804233725
],
[
-73.58034697395713,
45.496257942524835
],
[
-73.58000127109773,
45.49613461675315
]
]
]
},
"id": 179764,
"properties": {
"name": "01119274",
"address": "rue Guy (MTL) 2157",
"function": "Mixed use",
"mixed_type_1": "commercial",
"mixed_type_1_percentage": 50,
"mixed_type_2": "6000",
"mixed_type_2_percentage": 50,
"height": 62,
"year_of_construction": 1954
}
}
]
}

View File

@ -1,52 +0,0 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-73.58000127109773,
45.49613461675315
],
[
-73.57962787855432,
45.496524875557746
],
[
-73.57996357265695,
45.49668114195629
],
[
-73.57996427397713,
45.496680342403664
],
[
-73.58034707390021,
45.49625804233725
],
[
-73.58034697395713,
45.496257942524835
],
[
-73.58000127109773,
45.49613461675315
]
]
]
},
"id": 179764,
"properties": {
"name": "01119274",
"address": "rue Guy (MTL) 2157",
"function": "Mixed use",
"usages": [{"usage": "commercial", "percentage": 50}, {"usage": "6000", "percentage": 50}],
"height": 62,
"year_of_construction": 1954
}
}
]
}

View File

@ -27,8 +27,8 @@ import numpy as np
data = {}
input_files_path = (Path(__file__).parent / 'input_files')
input_files_path.mkdir(parents=True, exist_ok=True)
# geojson_file = process_geojson(x=-73.58001358793511, y=45.496445294438715, diff=0.0001)
geojson_file_path = input_files_path / 'test_geojson1.geojson'
geojson_file = process_geojson(x=-73.58001358793511, y=45.496445294438715, diff=0.0001)
geojson_file_path = input_files_path / 'output_buildings.geojson'
output_path = (Path(__file__).parent / 'out_files').resolve()
output_path.mkdir(parents=True, exist_ok=True)
energy_plus_output_path = output_path / 'energy_plus_outputs'
@ -45,8 +45,8 @@ city = GeometryFactory(file_type='geojson',
year_of_construction_field='year_of_construction',
function_field='function',
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
# ConstructionFactory('nrcan', city).enrich()
# UsageFactory('nrcan', city).enrich()
ConstructionFactory('nrcan', city).enrich()
UsageFactory('nrcan', city).enrich()
# WeatherFactory('epw', city).enrich()
# energy_plus_workflow(city, energy_plus_output_path)
# data[f'{city.buildings[0].function}'] = city.buildings[0].heating_demand[cte.YEAR][0] / 3.6e9

View File

@ -0,0 +1,26 @@
import random
import numpy as np
import hub.helpers.constants as cte
class EnergySystemOptimizer:
def __init__(self, building, objectives, population_size=20, number_of_generations=100, crossover_rate=0.8,
mutation_rate=0.1):
self.building = building
self.objectives = objectives
self.population_size = population_size
self.num_gen = number_of_generations
self.crossover_rate = crossover_rate
self.mutation_rate = mutation_rate
# Initialize population
def initialize_population(self):
population = []
for _ in range(self.population_size):
individual = [
random.uniform(0.1, 10.0), # hp_size
random.uniform(0.1, 10.0), # boiler_size
random.uniform(0.1, 10.0), # tes_size
random.uniform(40, 60) # cutoff_temp
]
population.append(individual)
return population

View File

@ -0,0 +1,16 @@
# Objective functions
MINIMUM_LCC = 1
MINIMUM_EC = 2
MINIMUM_EMISSIONS = 3
MINIMUM_LCC_MINIMUM_EC = 4
MINIMUM_LCC_MINIMUM_EMISSIONS = 5
MINIMUM_EC_MINIMUM_EMISSIONS = 6
MINIMUM_LCC_MINIMUM_EC_MINIMUM_EMISSIONS = 7
OBJECTIVE_FUNCTIONS = [MINIMUM_LCC,
MINIMUM_EC,
MINIMUM_EMISSIONS,
MINIMUM_LCC_MINIMUM_EC,
MINIMUM_LCC_MINIMUM_EMISSIONS,
MINIMUM_EC_MINIMUM_EMISSIONS,
MINIMUM_LCC_MINIMUM_EC_MINIMUM_EMISSIONS]

View File

@ -28,8 +28,8 @@ residential_systems_percentage = {'system 1 gas': 15,
'system 8 gas': 15,
'system 8 electricity': 35}
residential_new_systems_percentage = {'PV+ASHP+GasBoiler+TES': 100,
'PV+4Pipe+DHW': 0,
residential_new_systems_percentage = {'PV+ASHP+GasBoiler+TES': 0,
'PV+4Pipe+DHW': 100,
'PV+ASHP+ElectricBoiler+TES': 0,
'PV+GSHP+GasBoiler+TES': 0,
'PV+GSHP+ElectricBoiler+TES': 0,

View File

@ -5,7 +5,7 @@ from hub.helpers.monthly_values import MonthlyValues
class Archetype13:
def __init__(self, building, output_path):
def __init__(self, building, output_path, csv_output=True,):
self._building = building
self._name = building.name
self._pv_system = building.energy_systems[0]
@ -25,6 +25,7 @@ class Archetype13:
self._t_out = building.external_temperature[cte.HOUR]
self.results = {}
self.dt = 900
self.csv_output = csv_output
def hvac_sizing(self):
storage_factor = 3
@ -374,10 +375,11 @@ class Archetype13:
MonthlyValues.get_total_month(self._building.domestic_hot_water_consumption[cte.HOUR]))
self._building.domestic_hot_water_consumption[cte.YEAR] = [
sum(self._building.domestic_hot_water_consumption[cte.MONTH])]
file_name = f'energy_system_simulation_results_{self._name}.csv'
with open(self._output_path / file_name, 'w', newline='') as csvfile:
output_file = csv.writer(csvfile)
# Write header
output_file.writerow(self.results.keys())
# Write data
output_file.writerows(zip(*self.results.values()))
if self.csv_output:
file_name = f'energy_system_simulation_results_{self._name}.csv'
with open(self._output_path / file_name, 'w', newline='') as csvfile:
output_file = csv.writer(csvfile)
# Write header
output_file.writerow(self.results.keys())
# Write data
output_file.writerows(zip(*self.results.values()))