def checkNtw(individual, DHN_network_list, DCN_network_list, locator, gv, config, building_names): """ This function calls the distribution routine if necessary :param individual: network configuration considered :param ntwList: list of DHN configurations previously encounterd in the master :param locator: path to the folder :type individual: list :type ntwList: list :type locator: string :return: None :rtype: Nonetype """ DHN_barcode, DCN_barcode, DHN_configuration, DCN_configuration = supportFn.individual_to_barcode( individual, building_names) if not (DHN_barcode in DHN_network_list) and DHN_barcode.count("1") > 0: DHN_network_list.append(DHN_barcode) total_demand = supportFn.createTotalNtwCsv(DHN_barcode, locator) building_names = total_demand.Name.values # Run the substation and distribution routines substation.substation_main(locator, total_demand, building_names, DHN_configuration, DCN_configuration, Flag=True) summarize_network.network_main(locator, total_demand, building_names, config, gv, DHN_barcode) if not (DCN_barcode in DCN_network_list) and DCN_barcode.count("1") > 0: DCN_network_list.append(DCN_barcode) total_demand = supportFn.createTotalNtwCsv(DCN_barcode, locator) building_names = total_demand.Name.values # Run the substation and distribution routines substation.substation_main(locator, total_demand, building_names, DHN_configuration, DCN_configuration, Flag=True) summarize_network.network_main(locator, total_demand, building_names, config, gv, DCN_barcode)
def checkNtw(individual, ntwList, locator, gv): """ This function calls the distribution routine if necessary :param individual: network configuration considered :param ntwList: list of DHN configurations previously encounterd in the master :param locator: path to the folder :type individual: list :type ntwList: list :type locator: string :return: None :rtype: Nonetype """ indCombi = sFn.individual_to_barcode(individual, gv) print indCombi, 2 if not (indCombi in ntwList) and indCombi.count("1") > 0: ntwList.append(indCombi) if indCombi.count("1") == 1: total_demand = pd.read_csv( os.path.join(locator.get_optimization_network_results_folder(), "Total_%(indCombi)s.csv" % locals())) building_names = total_demand.Name.values print "Direct launch of distribution summary routine for", indCombi nM.network_main(locator, total_demand, building_names, gv, indCombi) else: total_demand = sFn.createTotalNtwCsv(indCombi, locator) building_names = total_demand.Name.values # Run the substation and distribution routines print "Re-run the substation routine for new distribution configuration", indCombi sMain.substation_main(locator, total_demand, building_names, gv, indCombi) print "Launch distribution summary routine" nM.network_main(locator, total_demand, building_names, gv, indCombi)
def checkNtw(individual, ntwList, locator, gv): """ Calls the network routine if necessary Parameters ---------- individual : list configuration considered ntwList : list list of DHN configuration previously encountered in the EA locator : string path to folders """ indCombi = sFn.readCombi(individual, gv) print(indCombi) if not (indCombi in ntwList) and indCombi.count("1") > 0: ntwList.append(indCombi) if indCombi.count("1") == 1: total_demand = pd.read_csv(locator.pathNtwRes + "//" + "Total_" + indCombi + ".csv") building_names = total_demand.Name.values print "Direct launch of network summary routine for", indCombi nM.Network_Summary(locator, total_demand, building_names, gv, indCombi) else: total_demand = sFn.createTotalNtwCsv(indCombi, locator) building_names = total_demand.Name.values # Run the substation and network routines print "Re-run the substation routine for new network configuration", indCombi sMain.subsMain(locator, total_demand, building_names, gv, indCombi) print "Launch network summary routine" nM.Network_Summary(locator, total_demand, building_names, gv, indCombi)
def evaluation_main(individual, building_names, locator, solar_features, network_features, gv, config, prices, lca, ind_num, gen): """ This function evaluates an individual :param individual: list with values of the individual :param building_names: list with names of buildings :param locator: locator class :param solar_features: solar features call to class :param network_features: network features call to class :param gv: global variables class :param optimization_constants: class containing constants used in optimization :param config: configuration file :param prices: class of prices used in optimization :type individual: list :type building_names: list :type locator: string :type solar_features: class :type network_features: class :type gv: class :type optimization_constants: class :type config: class :type prices: class :return: Resulting values of the objective function. costs, CO2, prim :rtype: tuple """ # Check the consistency of the individual or create a new one individual = check_invalid(individual, len(building_names), config) # Initialize objective functions costs, CO2 and primary energy costs_USD = 0 GHG_tonCO2 = 0 PEN_MJoil = 0 Q_heating_uncovered_design_W = 0 Q_heating_uncovered_annual_W = 0 # Create the string representation of the individual DHN_barcode, DCN_barcode, DHN_configuration, DCN_configuration = supportFn.individual_to_barcode( individual, building_names) if DHN_barcode.count("1") == gv.num_tot_buildings: network_file_name_heating = "Network_summary_result_all.csv" Q_DHNf_W = pd.read_csv( locator.get_optimization_network_all_results_summary('all'), usecols=["Q_DHNf_W"]).values Q_heating_max_W = Q_DHNf_W.max() elif DHN_barcode.count("1") == 0: network_file_name_heating = "Network_summary_result_all.csv" Q_heating_max_W = 0 else: network_file_name_heating = "Network_summary_result_" + hex( int(str(DHN_barcode), 2)) + ".csv" if not os.path.exists( locator.get_optimization_network_results_summary(DHN_barcode)): total_demand = supportFn.createTotalNtwCsv(DHN_barcode, locator) building_names = total_demand.Name.values # Run the substation and distribution routines substation.substation_main(locator, total_demand, building_names, DHN_configuration, DCN_configuration, Flag=True) summarize_network.network_main(locator, total_demand, building_names, config, gv, DHN_barcode) Q_DHNf_W = pd.read_csv( locator.get_optimization_network_results_summary(DHN_barcode), usecols=["Q_DHNf_W"]).values Q_heating_max_W = Q_DHNf_W.max() if DCN_barcode.count("1") == gv.num_tot_buildings: network_file_name_cooling = "Network_summary_result_all.csv" if individual[ N_HEAT * 2] == 1: # if heat recovery is ON, then only need to satisfy cooling load of space cooling and refrigeration Q_DCNf_W = pd.read_csv( locator.get_optimization_network_all_results_summary('all'), usecols=["Q_DCNf_space_cooling_and_refrigeration_W"]).values else: Q_DCNf_W = pd.read_csv( locator.get_optimization_network_all_results_summary('all'), usecols=[ "Q_DCNf_space_cooling_data_center_and_refrigeration_W" ]).values Q_cooling_max_W = Q_DCNf_W.max() elif DCN_barcode.count("1") == 0: network_file_name_cooling = "Network_summary_result_all.csv" Q_cooling_max_W = 0 else: network_file_name_cooling = "Network_summary_result_" + hex( int(str(DCN_barcode), 2)) + ".csv" if not os.path.exists( locator.get_optimization_network_results_summary(DCN_barcode)): total_demand = supportFn.createTotalNtwCsv(DCN_barcode, locator) building_names = total_demand.Name.values # Run the substation and distribution routines substation.substation_main(locator, total_demand, building_names, DHN_configuration, DCN_configuration, Flag=True) summarize_network.network_main(locator, total_demand, building_names, config, gv, DCN_barcode) if individual[ N_HEAT * 2] == 1: # if heat recovery is ON, then only need to satisfy cooling load of space cooling and refrigeration Q_DCNf_W = pd.read_csv( locator.get_optimization_network_results_summary(DCN_barcode), usecols=["Q_DCNf_space_cooling_and_refrigeration_W"]).values else: Q_DCNf_W = pd.read_csv( locator.get_optimization_network_results_summary(DCN_barcode), usecols=[ "Q_DCNf_space_cooling_data_center_and_refrigeration_W" ]).values Q_cooling_max_W = Q_DCNf_W.max() Q_heating_nom_W = Q_heating_max_W * (1 + Q_MARGIN_FOR_NETWORK) Q_cooling_nom_W = Q_cooling_max_W * (1 + Q_MARGIN_FOR_NETWORK) # Modify the individual with the extra GHP constraint try: check.GHPCheck(individual, locator, Q_heating_nom_W, gv) except: print "No GHP constraint check possible \n" # Export to context master_to_slave_vars = calc_master_to_slave_variables( individual, Q_heating_max_W, Q_cooling_max_W, building_names, ind_num, gen) master_to_slave_vars.network_data_file_heating = network_file_name_heating master_to_slave_vars.network_data_file_cooling = network_file_name_cooling master_to_slave_vars.total_buildings = len(building_names) master_to_slave_vars.DHN_barcode = DHN_barcode master_to_slave_vars.DCN_barcode = DCN_barcode if master_to_slave_vars.number_of_buildings_connected_heating > 1: if DHN_barcode.count("0") == 0: master_to_slave_vars.fNameTotalCSV = locator.get_total_demand() else: master_to_slave_vars.fNameTotalCSV = os.path.join( locator.get_optimization_network_totals_folder(), "Total_%(DHN_barcode)s.csv" % locals()) else: master_to_slave_vars.fNameTotalCSV = locator.get_optimization_substations_total_file( DHN_barcode) if master_to_slave_vars.number_of_buildings_connected_cooling > 1: if DCN_barcode.count("0") == 0: master_to_slave_vars.fNameTotalCSV = locator.get_total_demand() else: master_to_slave_vars.fNameTotalCSV = os.path.join( locator.get_optimization_network_totals_folder(), "Total_%(DCN_barcode)s.csv" % locals()) else: master_to_slave_vars.fNameTotalCSV = locator.get_optimization_substations_total_file( DCN_barcode) # Thermal Storage Calculations; Run storage optimization costs_storage_USD, GHG_storage_tonCO2, PEN_storage_MJoil = storage_main.storage_optimization( locator, master_to_slave_vars, lca, prices, config) costs_USD += costs_storage_USD GHG_tonCO2 += GHG_storage_tonCO2 PEN_MJoil += PEN_storage_MJoil # District Heating Calculations if config.district_heating_network: if DHN_barcode.count("1") > 0: (PEN_heating_MJoil, GHG_heating_tonCO2, costs_heating_USD, Q_heating_uncovered_design_W, Q_heating_uncovered_annual_W ) = heating_main.heating_calculations_of_DH_buildings( locator, master_to_slave_vars, gv, config, prices, lca) else: GHG_heating_tonCO2 = 0 costs_heating_USD = 0 PEN_heating_MJoil = 0 else: GHG_heating_tonCO2 = 0 costs_heating_USD = 0 PEN_heating_MJoil = 0 costs_USD += costs_heating_USD GHG_tonCO2 += GHG_heating_tonCO2 PEN_MJoil += PEN_heating_MJoil # District Cooling Calculations if gv.ZernezFlag == 1: costs_cooling_USD, GHG_cooling_tonCO2, PEN_cooling_MJoil = 0, 0, 0 elif config.district_cooling_network: reduced_timesteps_flag = False (costs_cooling_USD, GHG_cooling_tonCO2, PEN_cooling_MJoil ) = cooling_main.cooling_calculations_of_DC_buildings( locator, master_to_slave_vars, network_features, gv, prices, lca, config, reduced_timesteps_flag) else: costs_cooling_USD, GHG_cooling_tonCO2, PEN_cooling_MJoil = 0, 0, 0 costs_USD += costs_cooling_USD GHG_tonCO2 += GHG_cooling_tonCO2 PEN_MJoil += PEN_cooling_MJoil # District Electricity Calculations (costs_electricity_USD, GHG_electricity_tonCO2, PEN_electricity_MJoil ) = electricity_main.electricity_calculations_of_all_buildings( DHN_barcode, DCN_barcode, locator, master_to_slave_vars, network_features, gv, prices, lca, config) costs_USD += costs_electricity_USD GHG_tonCO2 += GHG_electricity_tonCO2 PEN_MJoil += PEN_electricity_MJoil # Natural Gas Import Calculations. Prices, GHG and PEN are already included in the various sections. # This is to save the files for further processing and plots natural_gas_main.natural_gas_imports(master_to_slave_vars, locator, config) # Capex Calculations print "Add extra costs" (costs_additional_USD, GHG_additional_tonCO2, PEN_additional_MJoil) = cost_model.addCosts( building_names, locator, master_to_slave_vars, Q_heating_uncovered_design_W, Q_heating_uncovered_annual_W, solar_features, network_features, gv, config, prices, lca) costs_USD += costs_additional_USD GHG_tonCO2 += GHG_additional_tonCO2 PEN_MJoil += PEN_additional_MJoil summarize_individual.summarize_individual_main(master_to_slave_vars, building_names, individual, solar_features, locator, config) # Converting costs into float64 to avoid longer values costs_USD = np.float64(costs_USD) GHG_tonCO2 = np.float64(GHG_tonCO2) PEN_MJoil = np.float64(PEN_MJoil) print('Total costs = ' + str(costs_USD)) print('Total CO2 = ' + str(GHG_tonCO2)) print('Total prim = ' + str(PEN_MJoil)) # Saving capacity details of the individual return costs_USD, GHG_tonCO2, PEN_MJoil, master_to_slave_vars, individual
def evaluation_main(individual, building_names, locator, extraCosts, extraCO2, extraPrim, solar_features, network_features, gv, config, prices, lca, ind_num, gen): """ This function evaluates an individual :param individual: list with values of the individual :param building_names: list with names of buildings :param locator: locator class :param extraCosts: costs calculated before optimization of specific energy services (process heat and electricity) :param extraCO2: green house gas emissions calculated before optimization of specific energy services (process heat and electricity) :param extraPrim: primary energy calculated before optimization ofr specific energy services (process heat and electricity) :param solar_features: solar features call to class :param network_features: network features call to class :param gv: global variables class :param optimization_constants: class containing constants used in optimization :param config: configuration file :param prices: class of prices used in optimization :type individual: list :type building_names: list :type locator: string :type extraCosts: float :type extraCO2: float :type extraPrim: float :type solar_features: class :type network_features: class :type gv: class :type optimization_constants: class :type config: class :type prices: class :return: Resulting values of the objective function. costs, CO2, prim :rtype: tuple """ # Check the consistency of the individual or create a new one individual = check_invalid(individual, len(building_names), config) # Initialize objective functions costs, CO2 and primary energy costs = extraCosts CO2 = extraCO2 prim = extraPrim QUncoveredDesign = 0 QUncoveredAnnual = 0 # Create the string representation of the individual DHN_barcode, DCN_barcode, DHN_configuration, DCN_configuration = sFn.individual_to_barcode( individual, building_names) if DHN_barcode.count("1") == gv.num_tot_buildings: network_file_name_heating = "Network_summary_result_all.csv" Q_DHNf_W = pd.read_csv( locator.get_optimization_network_all_results_summary('all'), usecols=["Q_DHNf_W"]).values Q_heating_max_W = Q_DHNf_W.max() elif DHN_barcode.count("1") == 0: network_file_name_heating = "Network_summary_result_all.csv" Q_heating_max_W = 0 else: network_file_name_heating = "Network_summary_result_" + hex( int(str(DHN_barcode), 2)) + ".csv" if not os.path.exists( locator.get_optimization_network_results_summary(DHN_barcode)): total_demand = sFn.createTotalNtwCsv(DHN_barcode, locator) building_names = total_demand.Name.values # Run the substation and distribution routines sMain.substation_main(locator, total_demand, building_names, DHN_configuration, DCN_configuration, Flag=True) nM.network_main(locator, total_demand, building_names, config, gv, DHN_barcode) Q_DHNf_W = pd.read_csv( locator.get_optimization_network_results_summary(DHN_barcode), usecols=["Q_DHNf_W"]).values Q_heating_max_W = Q_DHNf_W.max() if DCN_barcode.count("1") == gv.num_tot_buildings: network_file_name_cooling = "Network_summary_result_all.csv" if individual[ N_HEAT * 2] == 1: # if heat recovery is ON, then only need to satisfy cooling load of space cooling and refrigeration Q_DCNf_W = pd.read_csv( locator.get_optimization_network_all_results_summary('all'), usecols=["Q_DCNf_space_cooling_and_refrigeration_W"]).values else: Q_DCNf_W = pd.read_csv( locator.get_optimization_network_all_results_summary('all'), usecols=[ "Q_DCNf_space_cooling_data_center_and_refrigeration_W" ]).values Q_cooling_max_W = Q_DCNf_W.max() elif DCN_barcode.count("1") == 0: network_file_name_cooling = "Network_summary_result_all.csv" Q_cooling_max_W = 0 else: network_file_name_cooling = "Network_summary_result_" + hex( int(str(DCN_barcode), 2)) + ".csv" if not os.path.exists( locator.get_optimization_network_results_summary(DCN_barcode)): total_demand = sFn.createTotalNtwCsv(DCN_barcode, locator) building_names = total_demand.Name.values # Run the substation and distribution routines sMain.substation_main(locator, total_demand, building_names, DHN_configuration, DCN_configuration, Flag=True) nM.network_main(locator, total_demand, building_names, config, gv, DCN_barcode) if individual[ N_HEAT * 2] == 1: # if heat recovery is ON, then only need to satisfy cooling load of space cooling and refrigeration Q_DCNf_W = pd.read_csv( locator.get_optimization_network_results_summary(DCN_barcode), usecols=["Q_DCNf_space_cooling_and_refrigeration_W"]).values else: Q_DCNf_W = pd.read_csv( locator.get_optimization_network_results_summary(DCN_barcode), usecols=[ "Q_DCNf_space_cooling_data_center_and_refrigeration_W" ]).values Q_cooling_max_W = Q_DCNf_W.max() Q_heating_nom_W = Q_heating_max_W * (1 + Q_MARGIN_FOR_NETWORK) Q_cooling_nom_W = Q_cooling_max_W * (1 + Q_MARGIN_FOR_NETWORK) # Modify the individual with the extra GHP constraint try: cCheck.GHPCheck(individual, locator, Q_heating_nom_W, gv) except: print "No GHP constraint check possible \n" # Export to context master_to_slave_vars = calc_master_to_slave_variables( individual, Q_heating_max_W, Q_cooling_max_W, building_names, ind_num, gen) master_to_slave_vars.network_data_file_heating = network_file_name_heating master_to_slave_vars.network_data_file_cooling = network_file_name_cooling master_to_slave_vars.total_buildings = len(building_names) if master_to_slave_vars.number_of_buildings_connected_heating > 1: if DHN_barcode.count("0") == 0: master_to_slave_vars.fNameTotalCSV = locator.get_total_demand() else: master_to_slave_vars.fNameTotalCSV = os.path.join( locator.get_optimization_network_totals_folder(), "Total_%(DHN_barcode)s.csv" % locals()) else: master_to_slave_vars.fNameTotalCSV = locator.get_optimization_substations_total_file( DHN_barcode) if master_to_slave_vars.number_of_buildings_connected_cooling > 1: if DCN_barcode.count("0") == 0: master_to_slave_vars.fNameTotalCSV = locator.get_total_demand() else: master_to_slave_vars.fNameTotalCSV = os.path.join( locator.get_optimization_network_totals_folder(), "Total_%(DCN_barcode)s.csv" % locals()) else: master_to_slave_vars.fNameTotalCSV = locator.get_optimization_substations_total_file( DCN_barcode) if config.optimization.isheating: if DHN_barcode.count("1") > 0: (slavePrim, slaveCO2, slaveCosts, QUncoveredDesign, QUncoveredAnnual) = sM.slave_main(locator, master_to_slave_vars, solar_features, gv, config, prices, lca) else: slaveCO2 = 0 slaveCosts = 0 slavePrim = 0 else: slaveCO2 = 0 slaveCosts = 0 slavePrim = 0 costs += slaveCosts CO2 += slaveCO2 prim += slavePrim if gv.ZernezFlag == 1: coolCosts, coolCO2, coolPrim = 0, 0, 0 elif config.optimization.iscooling: reduced_timesteps_flag = False (coolCosts, coolCO2, coolPrim) = coolMain.coolingMain(locator, master_to_slave_vars, network_features, gv, prices, lca, config, reduced_timesteps_flag) else: coolCosts, coolCO2, coolPrim = 0, 0, 0 print "Add extra costs" (addCosts, addCO2, addPrim) = eM.addCosts(DHN_barcode, DCN_barcode, building_names, locator, master_to_slave_vars, QUncoveredDesign, QUncoveredAnnual, solar_features, network_features, gv, config, prices, lca) costs += addCosts + coolCosts CO2 += addCO2 + coolCO2 prim += addPrim + coolPrim # Converting costs into float64 to avoid longer values costs = np.float64(costs) CO2 = np.float64(CO2) prim = np.float64(prim) print('Total costs = ' + str(costs)) print('Total CO2 = ' + str(CO2)) print('Total prim = ' + str(prim)) return costs, CO2, prim, master_to_slave_vars, individual