示例#1
0
def calc_master_to_slave_variables(individual, Q_heating_max_W,
                                   Q_cooling_max_W, building_names, ind_num,
                                   gen):
    """
    This function reads the list encoding a configuration and implements the corresponding
    for the slave routine's to use
    :param individual: list with inidividual
    :param Q_heating_max_W:  peak heating demand
    :param locator: locator class
    :param gv: global variables class
    :type individual: list
    :type Q_heating_max_W: float
    :type locator: string
    :type gv: class
    :return: master_to_slave_vars : class MasterSlaveVariables
    :rtype: class
    """
    # initialise class storing dynamic variables transfered from master to slave optimization
    master_to_slave_vars = slave_data.SlaveData()
    configkey = "".join(str(e)[0:4] for e in individual)

    DHN_barcode, DCN_barcode, DHN_configuration, DCN_configuration = supportFn.individual_to_barcode(
        individual, building_names)
    configkey = configkey[:-2 * len(DHN_barcode)] + hex(
        int(str(DHN_barcode), 2)) + hex(int(str(DCN_barcode), 2))
    master_to_slave_vars.configKey = configkey
    master_to_slave_vars.number_of_buildings_connected_heating = DHN_barcode.count(
        "1")  # counting the number of buildings connected in DHN
    master_to_slave_vars.number_of_buildings_connected_cooling = DCN_barcode.count(
        "1")  # counting the number of buildings connectedin DCN
    master_to_slave_vars.individual_number = ind_num
    master_to_slave_vars.generation_number = gen

    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)

    # Heating systems

    #CHP units with NG & furnace with biomass wet
    if individual[0] == 1 or individual[0] == 3:
        if FURNACE_ALLOWED == True:
            master_to_slave_vars.Furnace_on = 1
            master_to_slave_vars.Furnace_Q_max_W = max(
                individual[1] * Q_heating_nom_W, Q_MIN_SHARE * Q_heating_nom_W)
            master_to_slave_vars.Furn_Moist_type = "wet"
        elif CC_ALLOWED == True:
            master_to_slave_vars.CC_on = 1
            master_to_slave_vars.CC_GT_SIZE_W = max(
                individual[1] * Q_heating_nom_W * 1.3,
                Q_MIN_SHARE * Q_heating_nom_W * 1.3)
            #1.3 is the conversion factor between the GT_Elec_size NG and Q_DHN
            master_to_slave_vars.gt_fuel = "NG"

    #CHP units with BG& furnace with biomass dry
    if individual[0] == 2 or individual[0] == 4:
        if FURNACE_ALLOWED == True:
            master_to_slave_vars.Furnace_on = 1
            master_to_slave_vars.Furnace_Q_max_W = max(
                individual[1] * Q_heating_nom_W, Q_MIN_SHARE * Q_heating_nom_W)
            master_to_slave_vars.Furn_Moist_type = "dry"
        elif CC_ALLOWED == True:
            master_to_slave_vars.CC_on = 1
            master_to_slave_vars.CC_GT_SIZE_W = max(
                individual[1] * Q_heating_nom_W * 1.5,
                Q_MIN_SHARE * Q_heating_nom_W * 1.5)
            #1.5 is the conversion factor between the GT_Elec_size BG and Q_DHN
            master_to_slave_vars.gt_fuel = "BG"

    # Base boiler NG
    if individual[2] == 1:
        master_to_slave_vars.Boiler_on = 1
        master_to_slave_vars.Boiler_Q_max_W = max(
            individual[3] * Q_heating_nom_W, Q_MIN_SHARE * Q_heating_nom_W)
        master_to_slave_vars.BoilerType = "NG"

    # Base boiler BG
    if individual[2] == 2:
        master_to_slave_vars.Boiler_on = 1
        master_to_slave_vars.Boiler_Q_max_W = max(
            individual[3] * Q_heating_nom_W, Q_MIN_SHARE * Q_heating_nom_W)
        master_to_slave_vars.BoilerType = "BG"

    # peak boiler NG
    if individual[4] == 1:
        master_to_slave_vars.BoilerPeak_on = 1
        master_to_slave_vars.BoilerPeak_Q_max_W = max(
            individual[5] * Q_heating_nom_W, Q_MIN_SHARE * Q_heating_nom_W)
        master_to_slave_vars.BoilerPeakType = "NG"

    # peak boiler BG
    if individual[4] == 2:
        master_to_slave_vars.BoilerPeak_on = 1
        master_to_slave_vars.BoilerPeak_Q_max_W = max(
            individual[5] * Q_heating_nom_W, Q_MIN_SHARE * Q_heating_nom_W)
        master_to_slave_vars.BoilerPeakType = "BG"

    # lake - heat pump
    if individual[6] == 1 and HP_LAKE_ALLOWED == True:
        master_to_slave_vars.HP_Lake_on = 1
        master_to_slave_vars.HPLake_maxSize_W = max(
            individual[7] * Q_heating_nom_W, Q_MIN_SHARE * Q_heating_nom_W)

    # sewage - heatpump
    if individual[8] == 1 and HP_SEW_ALLOWED == True:
        master_to_slave_vars.HP_Sew_on = 1
        master_to_slave_vars.HPSew_maxSize_W = max(
            individual[9] * Q_heating_nom_W, Q_MIN_SHARE * Q_heating_nom_W)

    # Gwound source- heatpump
    if individual[10] == 1 and GHP_ALLOWED == True:
        master_to_slave_vars.GHP_on = 1
        GHP_Qmax = max(individual[11] * Q_heating_nom_W,
                       Q_MIN_SHARE * Q_heating_nom_W)
        master_to_slave_vars.GHP_number = GHP_Qmax / GHP_HMAX_SIZE

    # heat recovery servers and compresor
    irank = N_HEAT * 2
    master_to_slave_vars.WasteServersHeatRecovery = individual[irank]
    master_to_slave_vars.WasteCompressorHeatRecovery = 0

    # Solar systems
    shareAvail = 1  # all buildings in the neighborhood are connected to the solar potential

    irank = N_HEAT * 2 + N_HR

    heating_block = N_HEAT * 2 + N_HR + N_SOLAR * 2 + INDICES_CORRESPONDING_TO_DHN
    master_to_slave_vars.DHN_supplyunits = DHN_configuration
    # cooling systems

    # Lake Cooling
    if individual[heating_block] == 1 and LAKE_COOLING_ALLOWED is True:
        master_to_slave_vars.Lake_cooling_on = 1
        master_to_slave_vars.Lake_cooling_size_W = max(
            individual[heating_block + 1] * Q_cooling_nom_W,
            Q_MIN_SHARE * Q_cooling_nom_W)

    # VCC Cooling
    if individual[heating_block + 2] == 1 and VCC_ALLOWED is True:
        master_to_slave_vars.VCC_on = 1
        master_to_slave_vars.VCC_cooling_size_W = max(
            individual[heating_block + 3] * Q_cooling_nom_W,
            Q_MIN_SHARE * Q_cooling_nom_W)

    # Absorption Chiller Cooling
    if individual[heating_block +
                  4] == 1 and ABSORPTION_CHILLER_ALLOWED is True:
        master_to_slave_vars.Absorption_Chiller_on = 1
        master_to_slave_vars.Absorption_chiller_size_W = max(
            individual[heating_block + 5] * Q_cooling_nom_W,
            Q_MIN_SHARE * Q_cooling_nom_W)

    # Storage Cooling
    if individual[heating_block + 6] == 1 and STORAGE_COOLING_ALLOWED is True:
        if (individual[heating_block + 2] == 1 and VCC_ALLOWED is True) or (
                individual[heating_block + 4] == 1
                and ABSORPTION_CHILLER_ALLOWED is True):
            master_to_slave_vars.storage_cooling_on = 1
            master_to_slave_vars.Storage_cooling_size_W = max(
                individual[heating_block + 7] * Q_cooling_nom_W,
                Q_MIN_SHARE * Q_cooling_nom_W)
            if master_to_slave_vars.Storage_cooling_size_W > STORAGE_COOLING_SHARE_RESTRICTION * Q_cooling_nom_W:
                master_to_slave_vars.Storage_cooling_size_W = STORAGE_COOLING_SHARE_RESTRICTION * Q_cooling_nom_W

    master_to_slave_vars.DCN_supplyunits = DCN_configuration
    master_to_slave_vars.SOLAR_PART_PV = max(
        individual[irank] * individual[irank + 1] * shareAvail, 0)
    master_to_slave_vars.SOLAR_PART_PVT = max(
        individual[irank + 2] * individual[irank + 3] * shareAvail, 0)
    master_to_slave_vars.SOLAR_PART_SC_ET = max(
        individual[irank + 4] * individual[irank + 5] * shareAvail, 0)
    master_to_slave_vars.SOLAR_PART_SC_FP = max(
        individual[irank + 6] * individual[irank + 7] * shareAvail, 0)

    return master_to_slave_vars
def calc_master_to_slave_variables(
    locator,
    gen,
    ind_num,
    individual_with_names_dict,
    building_names,
    DHN_barcode,
    DCN_barcode,
    network_file_name_heating,
    network_file_name_cooling,
    Q_heating_nom_W,
    Q_cooling_nom_W,
    Q_wasteheat_datacentre_nom_W,
    district_heating_network,
    district_cooling_network,
    technologies_heating_allowed,
    technologies_cooling_allowed,
    building_names_heating,
    building_names_cooling,
    building_names_electricity,
):
    """
    This function reads the list encoding a configuration and implements the corresponding
    for the slave routine's to use
    :param individual_with_names_dict: list with inidividual
    :param Q_heating_max_W:  peak heating demand
    :param locator: locator class
    :type individual_with_names_dict: list
    :type Q_heating_max_W: float
    :type locator: string
    :return: master_to_slave_vars : class MasterSlaveVariables
    :rtype: class
    """

    # calculate local variables
    num_total_buildings = len(building_names)

    # initialise class storing dynamic variables transfered from master to slave optimization
    master_to_slave_vars = slave_data.SlaveData()
    master_to_slave_vars = slave_data.SlaveData()

    # Store information aobut individual regarding the configuration of the network and curstomers connected
    if district_heating_network and DHN_barcode.count("1") > 0:
        master_to_slave_vars.DHN_exists = True
    if district_cooling_network and DCN_barcode.count("1") > 0:
        master_to_slave_vars.DCN_exists = True

    # store how many buildings are connected to district heating or cooling
    master_to_slave_vars.number_of_buildings_connected_heating = DHN_barcode.count(
        "1")
    master_to_slave_vars.number_of_buildings_connected_cooling = DCN_barcode.count(
        "1")

    # store the names of the buildings connected to district heating or district cooling
    master_to_slave_vars.buildings_connected_to_district_heating = calc_connected_names(
        building_names_heating, DHN_barcode)
    master_to_slave_vars.buildings_connected_to_district_cooling = calc_connected_names(
        building_names_cooling, DCN_barcode)

    # store the name of the file where the network configuration is stored
    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.technologies_heating_allowed = technologies_heating_allowed
    master_to_slave_vars.technologies_cooling_allowed = technologies_cooling_allowed

    # store the barcode which identifies which buildings are connected and disconencted
    master_to_slave_vars.DHN_barcode = DHN_barcode
    master_to_slave_vars.DCN_barcode = DCN_barcode

    # store the total number of buildings in the district (independent of district cooling or heating)
    master_to_slave_vars.num_total_buildings = num_total_buildings

    # store the name of all buildings in the district (independent of district cooling or heating)
    master_to_slave_vars.building_names_all = building_names

    # store the name used to didentified the individual (this helps to know where is inside)
    master_to_slave_vars.building_names_heating = building_names_heating
    master_to_slave_vars.building_names_cooling = building_names_cooling
    master_to_slave_vars.building_names_electricity = building_names_electricity
    master_to_slave_vars.individual_with_names_dict = individual_with_names_dict

    # Store the number of the individual and the generation to which it belongs
    master_to_slave_vars.individual_number = ind_num
    master_to_slave_vars.generation_number = gen

    # Store useful variables to know where to save the results of the individual
    master_to_slave_vars.date = pd.read_csv(
        locator.get_demand_results_file(building_names[0])).DATE.values

    # Store inforamtion about which units are activated
    master_to_slave_vars = master_to_slave_electrical_technologies(
        individual_with_names_dict,
        locator,
        master_to_slave_vars,
        district_heating_network,
        district_cooling_network,
    )

    if master_to_slave_vars.DHN_exists:
        master_to_slave_vars.Q_heating_nom_W = Q_heating_nom_W
        master_to_slave_vars = master_to_slave_district_heating_technologies(
            Q_heating_nom_W, Q_wasteheat_datacentre_nom_W,
            individual_with_names_dict, locator, master_to_slave_vars)

    if master_to_slave_vars.DCN_exists:
        master_to_slave_vars.Q_cooling_nom_W = Q_cooling_nom_W
        master_to_slave_vars = master_to_slave_district_cooling_technologies(
            Q_cooling_nom_W, individual_with_names_dict, master_to_slave_vars)

    return master_to_slave_vars
示例#3
0
def calc_master_to_slave_variables(individual, Qmax, locator, gv):
    """
    This function reads the list encoding a configuration and implements the corresponding
    for the slave routine's to use

    :param individual: list with inidividual
    :param Qmax:  peak heating demand
    :param locator: locator class
    :param gv: global variables class
    :type individual: list
    :type Qmax: float
    :type locator: string
    :type gv: class
    :return: master_to_slave_vars : class MasterSlaveVariables
    :rtype: class
    """
    # initialise class storing dynamic variables transfered from master to slave optimization
    master_to_slave_vars = slave_data.SlaveData()
    master_to_slave_vars.configKey = "".join(str(e)[0:4] for e in individual)

    individual_barcode = sFn.individual_to_barcode(individual, gv)
    master_to_slave_vars.nBuildingsConnected = individual_barcode.count(
        "1")  # counting the number of buildings connected

    Qnom = Qmax * (1 + gv.Qmargin_ntw)

    # Heating systems

    #CHP units with NG & furnace with biomass wet
    if individual[0] == 1 or individual[0] == 3:
        if gv.Furnace_allowed == 1:
            master_to_slave_vars.Furnace_on = 1
            master_to_slave_vars.Furnace_Q_max = max(individual[1] * Qnom,
                                                     gv.QminShare * Qnom)
            print master_to_slave_vars.Furnace_Q_max, "Furnace wet"
            master_to_slave_vars.Furn_Moist_type = "wet"
        elif gv.CC_allowed == 1:
            master_to_slave_vars.CC_on = 1
            master_to_slave_vars.CC_GT_SIZE = max(individual[1] * Qnom * 1.3,
                                                  gv.QminShare * Qnom * 1.3)
            #1.3 is the conversion factor between the GT_Elec_size NG and Q_DHN
            print master_to_slave_vars.CC_GT_SIZE, "CC NG"
            master_to_slave_vars.gt_fuel = "NG"

    #CHP units with BG& furnace with biomass dry
    if individual[0] == 2 or individual[0] == 4:
        if gv.Furnace_allowed == 1:
            master_to_slave_vars.Furnace_on = 1
            master_to_slave_vars.Furnace_Q_max = max(individual[1] * Qnom,
                                                     gv.QminShare * Qnom)
            print master_to_slave_vars.Furnace_Q_max, "Furnace dry"
            master_to_slave_vars.Furn_Moist_type = "dry"
        elif gv.CC_allowed == 1:
            master_to_slave_vars.CC_on = 1
            master_to_slave_vars.CC_GT_SIZE = max(individual[1] * Qnom * 1.5,
                                                  gv.QminShare * Qnom * 1.5)
            #1.5 is the conversion factor between the GT_Elec_size BG and Q_DHN
            print master_to_slave_vars.CC_GT_SIZE, "CC BG"
            master_to_slave_vars.gt_fuel = "BG"

    # Base boiler NG
    if individual[2] == 1:
        master_to_slave_vars.Boiler_on = 1
        master_to_slave_vars.Boiler_Q_max = max(individual[3] * Qnom,
                                                gv.QminShare * Qnom)
        print master_to_slave_vars.Boiler_Q_max, "Boiler base NG"
        master_to_slave_vars.BoilerType = "NG"

    # Base boiler BG
    if individual[2] == 2:
        master_to_slave_vars.Boiler_on = 1
        master_to_slave_vars.Boiler_Q_max = max(individual[3] * Qnom,
                                                gv.QminShare * Qnom)
        print master_to_slave_vars.Boiler_Q_max, "Boiler base BG"
        master_to_slave_vars.BoilerType = "BG"

    # peak boiler NG
    if individual[4] == 1:
        master_to_slave_vars.BoilerPeak_on = 1
        master_to_slave_vars.BoilerPeak_Q_max = max(individual[5] * Qnom,
                                                    gv.QminShare * Qnom)
        print master_to_slave_vars.BoilerPeak_Q_max, "Boiler peak NG"
        master_to_slave_vars.BoilerPeakType = "NG"

    # peak boiler BG
    if individual[4] == 2:
        master_to_slave_vars.BoilerPeak_on = 1
        master_to_slave_vars.BoilerPeak_Q_max = max(individual[5] * Qnom,
                                                    gv.QminShare * Qnom)
        print master_to_slave_vars.BoilerPeak_Q_max, "Boiler peak BG"
        master_to_slave_vars.BoilerPeakType = "BG"

    # lake - heat pump
    if individual[6] == 1 and gv.HPLake_allowed == 1:
        master_to_slave_vars.HP_Lake_on = 1
        master_to_slave_vars.HPLake_maxSize = max(individual[7] * Qnom,
                                                  gv.QminShare * Qnom)
        print master_to_slave_vars.HPLake_maxSize, "Lake"

    # sewage - heatpump
    if individual[8] == 1 and gv.HPSew_allowed == 1:
        master_to_slave_vars.HP_Sew_on = 1
        master_to_slave_vars.HPSew_maxSize = max(individual[9] * Qnom,
                                                 gv.QminShare * Qnom)
        print master_to_slave_vars.HPSew_maxSize, "Sewage"

    # Gwound source- heatpump
    if individual[10] == 1 and gv.GHP_allowed == 1:
        master_to_slave_vars.GHP_on = 1
        GHP_Qmax = max(individual[11] * Qnom, gv.QminShare * Qnom)
        master_to_slave_vars.GHP_number = GHP_Qmax / gv.GHP_HmaxSize
        print GHP_Qmax, "GHP"

    # heat recovery servers and compresor
    irank = gv.nHeat * 2
    master_to_slave_vars.WasteServersHeatRecovery = individual[irank]
    master_to_slave_vars.WasteCompressorHeatRecovery = individual[irank + 1]

    # Solar systems
    roof_area = np.array(
        pd.read_csv(locator.get_total_demand(), usecols=["Aroof_m2"]))

    areaAvail = 0
    totalArea = 0
    for i in range(len(individual_barcode)):
        index = individual_barcode[i]
        if index == "1":
            areaAvail += roof_area[i][0]
        totalArea += roof_area[i][0]

    shareAvail = areaAvail / totalArea

    irank = gv.nHeat * 2 + gv.nHR
    master_to_slave_vars.SOLAR_PART_PV = max(
        individual[irank] * individual[irank + 1] * individual[irank + 6] *
        shareAvail, 0)
    print master_to_slave_vars.SOLAR_PART_PV, "PV"
    master_to_slave_vars.SOLAR_PART_PVT = max(
        individual[irank + 2] * individual[irank + 3] * individual[irank + 6] *
        shareAvail, 0)
    print master_to_slave_vars.SOLAR_PART_PVT, "PVT"
    master_to_slave_vars.SOLAR_PART_SC = max(
        individual[irank + 4] * individual[irank + 5] * individual[irank + 6] *
        shareAvail, 0)
    print master_to_slave_vars.SOLAR_PART_SC, "SC"

    return master_to_slave_vars