def main(config): print('Running decentralized model for buildings with scenario = %s' % config.scenario) locator = cea.inputlocator.InputLocator(config.scenario) total_demand = pd.read_csv(locator.get_total_demand()) detailed_electricity_pricing = config.decentralized.detailed_electricity_pricing prices = Prices(locator, detailed_electricity_pricing) lca = LcaCalculations(locator) disconnected_building_main(locator=locator, total_demand=total_demand, config=config, prices=prices, lca=lca)
def main(config): print('Running decentralized model for buildings with scenario = %s' % config.scenario) locator = cea.inputlocator.InputLocator(config.scenario) supply_systems = SupplySystemsDatabase(locator) total_demand = pd.read_csv(locator.get_total_demand()) prices = Prices(supply_systems) lca = LcaCalculations(supply_systems) disconnected_building_main(locator=locator, total_demand=total_demand, config=config, prices=prices, lca=lca)
def main(config): print('Running decentralized model for buildings with scenario = %s' % config.scenario) locator = cea.inputlocator.InputLocator(config.scenario) total_demand = pd.read_csv(locator.get_total_demand()) building_names = total_demand.Name.values prices = Prices(locator, config) lca = lca_calculations(locator, config) disconnected_building_main(locator=locator, building_names=building_names, config=config, prices=prices, lca=lca)
def moo_optimization(locator, weather_file, gv, config): ''' This function optimizes the conversion, storage and distribution systems of a heating distribution for the case study. It requires that the energy demand, technology potential and thermal networks are simulated, as follows: - energy demand simulation: run cea/demand/demand_main.py - PV potential: run cea/technologies/solar/photovoltaic.py - PVT potential: run cea/technologies/solar/photovoltaic_thermal.py - flat plate solar collector potential: run cea/technologies/solar/solar_collector.py with config.solar.type_scpanel = 'FP' - evacuated tube solar collector potential: run cea/technologies/solar/solar_collector.py with config.solar.type_scpanel = 'ET' - waste water heat recovery: run cea/resources/sewage_heat_exchanger.py - lake water potential: run cea/resources/lake_potential.py - thermal network simulation: run cea/technologies/thermal_network/thermal_network_matrix.py if no network is currently present in the case study, consider running network_layout/main.py first - decentralized building simulation: run cea/optimization/preprocessing/decentralized_building_main.py :param locator: path to input locator :param weather_file: path to weather file :param gv: global variables class :type locator: string :type weather_file: string :type gv: class :returns: None :rtype: Nonetype ''' # read total demand file and names and number of all buildings total_demand = pd.read_csv(locator.get_total_demand()) building_names = total_demand.Name.values gv.num_tot_buildings = total_demand.Name.count() lca = lca_calculations(locator, config) prices = Prices(locator, config) # pre-process information regarding resources and technologies (they are treated before the optimization) # optimize best systems for every individual building (they will compete against a district distribution solution) print "PRE-PROCESSING" extra_costs, extra_CO2, extra_primary_energy, solar_features = preproccessing( locator, total_demand, building_names, weather_file, gv, config, prices, lca) # optimize the distribution and linearize the results(at the moment, there is only a linearization of values in Zug) print "NETWORK OPTIMIZATION" network_features = network_opt_main.network_opt_main(config, locator) # optimize conversion systems print "CONVERSION AND STORAGE OPTIMIZATION" master_main.non_dominated_sorting_genetic_algorithm( locator, building_names, extra_costs, extra_CO2, extra_primary_energy, solar_features, network_features, gv, config, prices, lca)
def main(config): """ run the whole preprocessing routine """ from cea.optimization.prices import Prices as Prices print('Running decentralized model for buildings with scenario = %s' % config.scenario) locator = cea.inputlocator.InputLocator(scenario=config.scenario) total_demand = pd.read_csv(locator.get_total_demand()) building_names = total_demand.Name prices = Prices(locator, config) lca = LcaCalculations(locator, config.optimization.detailed_electricity_pricing) disconnected_buildings_cooling_main(locator, building_names, total_demand, config, prices, lca) print 'test_decentralized_buildings_cooling() succeeded'
def main(config): """ run the whole preprocessing routine """ from cea.optimization.prices import Prices as Prices print("Running decentralized model for buildings with scenario = %s" % config.scenario) locator = cea.inputlocator.InputLocator(scenario=config.scenario) supply_systems = SupplySystemsDatabase(locator) total_demand = pd.read_csv(locator.get_total_demand()) building_names = total_demand.Name prices = Prices(supply_systems) lca = LcaCalculations(supply_systems) disconnected_buildings_cooling_main(locator, building_names, total_demand, config, prices, lca) print("test_decentralized_buildings_cooling() succeeded")
def moo_optimization(locator, weather_file, gv, config): ''' This function optimizes the conversion, storage and distribution systems of a heating distribution for the case study. It requires that solar technologies be calculated in advance and nodes of a distribution should have been already generated. :param locator: path to input locator :param weather_file: path to weather file :param gv: global variables class :type locator: string :type weather_file: string :type gv: class :returns: None :rtype: Nonetype ''' # read total demand file and names and number of all buildings total_demand = pd.read_csv(locator.get_total_demand()) building_names = total_demand.Name.values gv.num_tot_buildings = total_demand.Name.count() lca = lca_calculations(locator, config) prices = Prices(locator, config) # pre-process information regarding resources and technologies (they are treated before the optimization) # optimize best systems for every individual building (they will compete against a district distribution solution) print "PRE-PROCESSING" extra_costs, extra_CO2, extra_primary_energy, solarFeat = preproccessing( locator, total_demand, building_names, weather_file, gv, config, prices, lca) # optimize the distribution and linearize the results(at the moment, there is only a linearization of values in Zug) print "NETWORK OPTIMIZATION" network_features = network_opt.network_opt_main(config, locator) # optimize conversion systems print "CONVERSION AND STORAGE OPTIMIZATION" master.evolutionary_algo_main(locator, building_names, extra_costs, extra_CO2, extra_primary_energy, solarFeat, network_features, gv, config, prices, lca)
def calc_Ctot_cs_district(network_info): """ Calculates the total costs for cooling of the entire district, which includes the cooling networks and disconnected loads & buildings. Maintenance of network neglected, see Documentation Master Thesis Lennart Rogenhofer :param Thermal_Network network_info: an object storing information of the current network :return: """ # read in general values for cost calculation # network_info.config.detailed_electricity_pricing = False # ensure getting the average value network_info.prices = Prices(network_info.supply_systems) network_info.prices.ELEC_PRICE = np.mean(network_info.prices.ELEC_PRICE, dtype=np.float64) # [USD/W] network_info.network_features = NetworkOptimizationFeatures( district_heating_network=network_info.network_type == "DH", district_cooling_network=network_info.network_type == "DC", locator=network_info.locator) cost_storage_df = pd.DataFrame(index=network_info.cost_info, columns=[0]) ## calculate network costs # Network pipes Capex_a_netw = calc_Capex_a_network_pipes(network_info) # Network Pumps Capex_a_pump, Opex_fixed_pump, Opex_var_pump = calc_Ctot_network_pump( network_info) # Centralized plant Opex_fixed_plant, Opex_var_plant, Capex_a_chiller, Capex_a_CT = calc_Ctot_cooling_plants( network_info) if Opex_var_plant < 1: # no heat supplied by centralized plant/network, this makes sure that the network cost is 0. Capex_a_netw = 0 # calculate costs of disconnected loads Ctot_dis_loads, Opex_tot_dis_loads, Capex_a_dis_loads = calc_Ctot_cs_building_scale_loads( network_info) # calculate costs of disconnected buildings Ctot_dis_buildings, Opex_tot_dis_buildings, Capex_a_dis_buildings = calc_Ctot_cs_building_scale_buildings( network_info) # calculate costs of HEX at connected buildings Capex_a_hex, Opex_fixed_hex = calc_Cinv_HEX_hisaka(network_info) # calculate electricity consumption el_price_per_Wh = network_info.prices.ELEC_PRICE el_MWh = (Opex_var_pump + Opex_var_plant) / el_price_per_Wh / 1e6 # store results Capex_a_total = Capex_a_netw + Capex_a_pump + Capex_a_dis_loads + Capex_a_dis_buildings + \ Capex_a_chiller + Capex_a_CT + Capex_a_hex Opex_total = Opex_fixed_pump + Opex_var_pump + Opex_var_plant + Opex_tot_dis_loads + \ Opex_tot_dis_buildings + Opex_fixed_plant + Opex_fixed_hex Costs_total = Capex_a_netw + Capex_a_pump + Capex_a_chiller + Capex_a_CT + Capex_a_hex + \ Opex_fixed_pump + Opex_var_pump + Opex_var_plant + Ctot_dis_loads + Ctot_dis_buildings + \ Opex_fixed_plant + Opex_fixed_hex cost_storage_df.ix['total'][0] = Capex_a_total + Opex_total cost_storage_df.ix['opex'][0] = Opex_total cost_storage_df.ix['capex'][0] = Capex_a_total cost_storage_df.ix['capex_network'][0] = Capex_a_netw cost_storage_df.ix['capex_pump'][0] = Capex_a_pump cost_storage_df.ix['capex_hex'][0] = Capex_a_hex cost_storage_df.ix['capex_dis_loads'][0] = Capex_a_dis_loads cost_storage_df.ix['capex_dis_build'][0] = Capex_a_dis_buildings cost_storage_df.ix['capex_chiller'][0] = Capex_a_chiller cost_storage_df.ix['capex_CT'][0] = Capex_a_CT cost_storage_df.ix['opex_plant'][0] = Opex_fixed_plant + Opex_var_plant cost_storage_df.ix['opex_pump'][0] = Opex_fixed_pump + Opex_var_pump cost_storage_df.ix['opex_hex'][0] = Opex_fixed_hex cost_storage_df.ix['opex_dis_loads'][0] = Opex_tot_dis_loads cost_storage_df.ix['opex_dis_build'][0] = Opex_tot_dis_buildings cost_storage_df.ix['el_network_MWh'][0] = el_MWh return Capex_a_total, Opex_total, Costs_total, cost_storage_df
def preproccessing(locator, total_demand, buildings_heating_demand, buildings_cooling_demand, weather_file, district_heating_network, district_cooling_network): """ This function aims at preprocessing all data for the optimization. :param locator: path to locator function :param total_demand: dataframe with total demand and names of all building in the area :param building_names: dataframe with names of all buildings in the area :param weather_file: path to wather file :type locator: class :type total_demand: list :type building_names: list :type weather_file: string :return: - extraCosts: extra pareto optimal costs due to electricity and process heat ( these are treated separately and not considered inside the optimization) - extraCO2: extra pareto optimal emissions due to electricity and process heat ( these are treated separately and not considered inside the optimization) - extraPrim: extra pareto optimal primary energy due to electricity and process heat ( these are treated separately and not considered inside the optimization) - solar_features: extraction of solar features form the results of the solar technologies calculation. :rtype: float, float, float, float """ print("PRE-PROCESSING 0/4: initialize directory") shutil.rmtree(locator.get_optimization_master_results_folder()) shutil.rmtree(locator.get_optimization_network_results_folder()) shutil.rmtree(locator.get_optimization_slave_results_folder()) shutil.rmtree(locator.get_optimization_substations_folder()) print("PRE-PROCESSING 1/4: weather features") # at first estimate a distribution with all the buildings connected weather_features = WeatherFeatures(weather_file, locator) print("PRE-PROCESSING 2/4: conversion systems database") # at first estimate a distribution with all the buildings connected supply_systems = SupplySystemsDatabase(locator) print("PRE-PROCESSING 3/4: feedstocks systems database") # at first estimate a distribution with all the buildings connected prices = Prices(supply_systems) lca = LcaCalculations(supply_systems) print("PRE-PROCESSING 4/4: network features") # at first estimate a distribution with all the buildings connected if district_heating_network: num_tot_buildings = len(buildings_heating_demand) DHN_barcode = ''.join(str(1) for e in range(num_tot_buildings)) substation.substation_main_heating(locator, total_demand, buildings_heating_demand, DHN_barcode=DHN_barcode) summarize_network.network_main(locator, buildings_heating_demand, weather_features.ground_temp, num_tot_buildings, "DH", DHN_barcode) # "_all" key for all buildings if district_cooling_network: num_tot_buildings = len(buildings_cooling_demand) DCN_barcode = ''.join(str(1) for e in range(num_tot_buildings)) substation.substation_main_cooling(locator, total_demand, buildings_cooling_demand, DCN_barcode=DCN_barcode) summarize_network.network_main(locator, buildings_cooling_demand, weather_features.ground_temp, num_tot_buildings, "DC", DCN_barcode) # "_all" key for all buildings network_features = NetworkOptimizationFeatures(district_heating_network, district_cooling_network, locator) return weather_features, network_features, prices, lca
def moo_optimization(locator, weather_file, config): ''' This function optimizes the conversion, storage and distribution systems of a heating distribution for the case study. It requires that the energy demand, technology potential and thermal networks are simulated, as follows: - energy demand simulation: run cea/demand/demand_main.py - PV potential: run cea/technologies/solar/photovoltaic.py - PVT potential: run cea/technologies/solar/photovoltaic_thermal.py - flat plate solar collector potential: run cea/technologies/solar/solar_collector.py with config.solar.type_scpanel = 'FP' - evacuated tube solar collector potential: run cea/technologies/solar/solar_collector.py with config.solar.type_scpanel = 'ET' - waste water heat recovery: run cea/resources/sewage_heat_exchanger.py - lake water potential: run cea/resources/water_body_potential.py - thermal network simulation: run cea/technologies/thermal_network/thermal_network.py if no network is currently present in the case study, consider running network_layout/main.py first - decentralized building simulation: run cea/optimization/preprocessing/decentralized_building_main.py :param locator: path to input locator :param weather_file: path to weather file :type locator: cea.inputlocator.InputLocator :type weather_file: string :returns: None :rtype: Nonetype ''' t0 = time.clock() # read total demand file and names and number of all buildings total_demand = pd.read_csv(locator.get_total_demand()) building_names_all = list(total_demand.Name.values) # needs to be a list to avoid errors lca = LcaCalculations(locator) prices = Prices(locator, config.optimization.detailed_electricity_pricing) # local flags district_heating_network = config.optimization.district_heating_network district_cooling_network = config.optimization.district_cooling_network #GET NAMES_OF BUILDINGS THAT HAVE HEATING, COOLING AND ELECTRICITY LOAD SEPARATELY buildings_heating_demand = get_building_names_with_load(total_demand, load_name='QH_sys_MWhyr') buildings_cooling_demand = get_building_names_with_load(total_demand, load_name='QC_sys_MWhyr') buildings_electricity_demand = get_building_names_with_load(total_demand, load_name='E_sys_MWhyr') # pre-process information regarding resources and technologies (they are treated before the optimization) # optimize best systems for every individual building (they will compete against a district distribution solution) print("PRE-PROCESSING") network_features = preproccessing(locator, total_demand, buildings_heating_demand, buildings_cooling_demand, weather_file, district_heating_network, district_cooling_network) # optimize conversion systems print("SUPPLY SYSTEMS OPTIMIZATION") master_main.non_dominated_sorting_genetic_algorithm(locator, building_names_all, district_heating_network, district_cooling_network, buildings_heating_demand, buildings_cooling_demand, buildings_electricity_demand, network_features, config, prices, lca) t1 = time.clock() print('Centralized Optimization succeeded after %s seconds' %(t1-t0))
print ('combined euclidean distance = ' + str(combined_euclidean_distance)) print ('spread = ' + str(spread_final)) return combined_euclidean_distance, spread_final if __name__ == "__main__": config = cea.config.Configuration() gv = cea.globalvar.GlobalVariables() locator = cea.inputlocator.InputLocator(scenario=config.scenario) weather_file = config.weather total_demand = pd.read_csv(locator.get_total_demand()) building_names = total_demand.Name.values gv.num_tot_buildings = total_demand.Name.count() lca = lca_calculations(locator, config) prices = Prices(locator, config) extra_costs, extra_CO2, extra_primary_energy, solar_features = preproccessing(locator, total_demand, building_names, weather_file, gv, config, prices, lca) # optimize the distribution and linearize the results(at the moment, there is only a linearization of values in Zug) print "NETWORK OPTIMIZATION" nBuildings = len(building_names) network_features = network_opt_main.network_opt_main(config, locator) non_dominated_sorting_genetic_algorithm(locator, building_names, extra_costs, extra_CO2, extra_primary_energy, solar_features, network_features, gv, config, prices, lca)
def main(config): """ run the whole optimization routine """ gv = cea.globalvar.GlobalVariables() locator = cea.inputlocator.InputLocator(scenario=config.scenario) weather_file = config.weather try: if not demand_files_exist(config, locator): raise ValueError( "Missing demand data of the scenario. Consider running demand script first" ) if not os.path.exists(locator.get_total_demand()): raise ValueError( "Missing total demand of the scenario. Consider running demand script first" ) if not os.path.exists(locator.PV_totals()): raise ValueError( "Missing PV potential of the scenario. Consider running photovoltaic script first" ) if config.district_heating_network: if not os.path.exists(locator.PVT_totals()): raise ValueError( "Missing PVT potential of the scenario. Consider running photovoltaic-thermal script first" ) if not os.path.exists(locator.SC_totals(panel_type='FP')): raise ValueError( "Missing SC potential of panel type 'FP' of the scenario. Consider running solar-collector script first with panel_type as SC1 and t-in-SC as 75" ) if not os.path.exists(locator.SC_totals(panel_type='ET')): raise ValueError( "Missing SC potential of panel type 'ET' of the scenario. Consider running solar-collector script first with panel_type as SC2 and t-in-SC as 150" ) if not os.path.exists(locator.get_sewage_heat_potential()): raise ValueError( "Missing sewage potential of the scenario. Consider running sewage heat exchanger script first" ) if not os.path.exists( locator.get_optimization_network_edge_list_file( config.thermal_network.network_type, '')): raise ValueError( "Missing network edge list. Consider running thermal network script first" ) except ValueError as err: import sys print(err.message) sys.exit(1) # read total demand file and names and number of all buildings total_demand = pd.read_csv(locator.get_total_demand()) building_names = total_demand.Name.values gv.num_tot_buildings = total_demand.Name.count() prices = Prices(locator, config) lca = lca_calculations(locator, config) # pre-process information regarding resources and technologies (they are treated before the optimization) # optimize best systems for every individual building (they will compete against a district distribution solution) extra_costs, extra_CO2, extra_primary_energy, solarFeat = preproccessing( locator, total_demand, building_names, weather_file, gv, config, prices, lca) # optimize the distribution and linearize the results(at the moment, there is only a linearization of values in Zug) network_features = network_opt_main.network_opt_main(config, locator) ## generate individual from config # heating technologies at the centralized plant heating_block = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90.0, 6 ] # FIXME: connect PV to config # cooling technologies at the centralized plant centralized_vcc_size = config.supply_system_simulation.centralized_vcc centralized_ach_size = config.supply_system_simulation.centralized_ach centralized_storage_size = config.supply_system_simulation.centralized_storage cooling_block = [0, 0, 1, 0.3, 1, 0.4, 1, 0.2, 6, 7] cooling_block[2:4] = [1, centralized_vcc_size ] if (centralized_vcc_size != 0) else [0, 0] cooling_block[4:6] = [1, centralized_ach_size ] if (centralized_ach_size != 0) else [0, 0] cooling_block[6:8] = [1, centralized_storage_size ] if (centralized_storage_size != 0) else [0, 0] total_demand = pd.read_csv(locator.get_total_demand()) building_names = total_demand.Name.values # read list of buildings connected to DC from config if len(config.supply_system_simulation.dc_connected_buildings) == 0: dc_connected_buildings = building_names # default, all connected else: dc_connected_buildings = config.supply_system_simulation.dc_connected_buildings # dc_connected_buildings = building_names # default, all connected # buildings connected to networks heating_network = [0] * building_names.size cooling_network = [0] * building_names.size for building in dc_connected_buildings: index = np.where(building_names == building)[0][0] cooling_network[index] = 1 individual = heating_block + cooling_block + heating_network + cooling_network # individual = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0.01,1,0.535812211,0,0,0,0,10,7,1,0,1,1,0,1,0,0,0,0,1,1,1,1,0,1,1,0,1,1] supply_calculation(individual, building_names, total_demand, locator, extra_costs, extra_CO2, extra_primary_energy, solarFeat, network_features, gv, config, prices, lca) print 'Buildings connected to thermal network:', dc_connected_buildings print 'Centralized systems:', centralized_vcc_size, 'VCC', centralized_ach_size, 'ACH', centralized_storage_size print 'Decentralized systems:', config.supply_system_simulation.decentralized_systems print 'supply calculation succeeded!'
def individual_evaluation(generation, level, size, variable_groups): """ :param generation: Generation of the optimization in which the individual evaluation is to be done :type generation: int :param level: Number of the uncertain scenario. For each scenario, the objectives are calculated :type level: int :param size: Total uncertain scenarios developed. See 'uncertainty.csv' :type size: int :return: Function saves the new objectives in a json file """ from cea.optimization.preprocessing.preprocessing_main import preproccessing gv = cea.globalvar.GlobalVariables() scenario_path = gv.scenario_reference locator = cea.inputlocator.InputLocator(scenario_path) config = cea.config.Configuration() weather_file = locator.get_default_weather() with open( locator.get_optimization_master_results_folder() + "\CheckPoint_" + str(generation), "rb") as fp: data = json.load(fp) pop = data['population'] ntwList = data['networkList'] # # Uncertainty Part row = [] with open(locator.get_uncertainty_results_folder() + '\uncertainty.csv') as f: reader = csv.reader(f) for i in xrange(size + 1): row.append(next(reader)) j = level + 1 for i in xrange(len(row[0]) - 1): setattr(gv, row[0][i + 1], float(row[j][i + 1])) total_demand = pd.read_csv(locator.get_total_demand()) building_names = total_demand.Name.values gv.num_tot_buildings = total_demand.Name.count() lca = lca_calculations(locator, config) prices = Prices(locator, config) extra_costs, extra_CO2, extra_primary_energy, solarFeat = preproccessing( locator, total_demand, building_names, weather_file, gv) network_features = network_opt.network_opt_main() def objective_function(ind, ind_num): (costs, CO2, prim) = evaluation.evaluation_main( ind, building_names, locator, solarFeat, network_features, gv, config, prices, lca, ind_num, generation) # print (costs, CO2, prim) return (costs, CO2, prim) fitness = [] for i in xrange(gv.initialInd): evaluation.checkNtw(pop[i], ntwList, locator, gv) fitness.append(objective_function(pop[i], i)) with open(locator.get_uncertainty_checkpoint(level), "wb") as fp: cp = dict(population=pop, uncertainty_level=level, population_fitness=fitness) json.dump(cp, fp)