Esempio n. 1
0
def GHPCheck(individual, pathRaw, Qnom, gv):
    """
    Computes the geothermal availability and modifies the individual to 
    comply with it
    
    Parameters
    ----------
    individual : list
    pathRaw : float
    Qnom : float
        Nominal installed capacity in the district heating plant
    
    """
    areaArray = np.array(
        pd.read_csv(pathRaw + "/Geothermal.csv", usecols=["Area_geo"]))
    buildArray = np.array(
        pd.read_csv(pathRaw + "/Geothermal.csv", usecols=["Name"]))

    buildList = sFn.extractList(pathRaw + "/Total.csv")
    indCombi = sFn.readCombi(individual)

    Qallowed = 0

    for index, buildName in zip(indCombi, buildList):
        if index == "1":
            areaAvail = areaArray[np.where(buildArray == buildName)[0][0]][0]
            Qallowed += np.ceil(
                areaAvail / gv.GHP_A) * gv.GHP_HmaxSize  #[W_th]

    print Qallowed, "Qallowed"
    if Qallowed < individual[11] * Qnom:
        print "GHP share modified !"

        if Qallowed < 1E-3:
            oldValue = individual[11]
            shareLoss = individual[11]
            individual[10] = 0
            individual[11] = 0

        else:
            oldValue = individual[11]
            shareLoss = oldValue - Qallowed / Qnom
            individual[11] = Qallowed / Qnom

        # Adapt the other shares
        nPlant = 0
        for i in range(gv.nHeat - 1):
            if individual[2 * i] > 0:
                nPlant += 1
                individual[2 * i +
                           1] += individual[2 * i + 1] * shareLoss / (1 -
                                                                      oldValue)

        if nPlant == 0:  # there was only the GHP --> replaced by only NG Boiler
            individual[2] = 1
            individual[3] = 1 - individual[11]
def GHPCheck(individual, pathRaw, Qnom, gv):
    """
    Computes the geothermal availability and modifies the individual to 
    comply with it
    
    Parameters
    ----------
    individual : list
    pathRaw : float
    Qnom : float
        Nominal installed capacity in the district heating plant
    
    """
    areaArray = np.array( pd.read_csv( pathRaw + "/Geothermal.csv", usecols=["Area_geo"] ) )
    buildArray = np.array( pd.read_csv( pathRaw + "/Geothermal.csv", usecols=["Name"] ) )
    
    buildList = sFn.extractList(pathRaw + "/Total.csv")
    indCombi = sFn.readCombi(individual)
    
    Qallowed = 0

    for index, buildName in zip(indCombi, buildList):
        if index == "1":
            areaAvail = areaArray[ np.where(buildArray == buildName)[0][0] ][0]
            Qallowed += np.ceil(areaAvail/gv.GHP_A) * gv.GHP_HmaxSize #[W_th]
    
    print Qallowed, "Qallowed"
    if Qallowed < individual[11] * Qnom:
        print "GHP share modified !"
        
        if Qallowed < 1E-3:
            oldValue = individual[11]
            shareLoss = individual[11]
            individual[10] =0
            individual[11] =0
        
        else:
            oldValue = individual[11]
            shareLoss = oldValue - Qallowed / Qnom
            individual[11] = Qallowed / Qnom
        
        # Adapt the other shares
        nPlant = 0
        for i in range(gv.nHeat - 1):
            if individual[2*i] > 0:
                nPlant += 1
                individual[2*i+1] += individual[2*i+1] * shareLoss / (1-oldValue)
        
        if nPlant == 0: # there was only the GHP --> replaced by only NG Boiler
            individual[2] = 1
            individual[3] = 1-individual[11]
def decentralizeCosts(individual, pathX, gV):
    indCombi = sFn.readCombi(individual, gV)
    buildList = sFn.extractList(pathX.pathRaw + "/Total.csv")
    costsDisc = 0

    for i in range(len(indCombi)):
        if indCombi[i] == "0": # Decentralized building
            buildName = buildList[i]
            DecentFile = pathX.pathDiscRes + "/DiscOp_" + buildName + "_result.csv"

            df = pd.read_csv(DecentFile)
            dfBest = df[df["Best configuration"] == 1]

            costsDisc += dfBest["Annualized Investment Costs [CHF]"].iloc[0]

    print costsDisc, "costsDisc"
    return costsDisc
Esempio n. 4
0
def decentralizeCosts(individual, pathX, gV):
    indCombi = sFn.readCombi(individual, gV)
    buildList = sFn.extractList(pathX.pathRaw + "/Total.csv")
    costsDisc = 0

    for i in range(len(indCombi)):
        if indCombi[i] == "0":  # Decentralized building
            buildName = buildList[i]
            DecentFile = pathX.pathDiscRes + "/DiscOp_" + buildName + "_result.csv"

            df = pd.read_csv(DecentFile)
            dfBest = df[df["Best configuration"] == 1]

            costsDisc += dfBest["Annualized Investment Costs [CHF]"].iloc[0]

    print costsDisc, "costsDisc"
    return costsDisc
Esempio n. 5
0
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 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)
Esempio n. 7
0
def evalInd(individual, buildList, locator, extraCosts, extraCO2, extraPrim,
            solarFeat, ntwFeat, gv):
    """
    Evaluates an individual
    
    Parameters
    ----------
    individual : list
    buildList : list of buildings in the district
    pahthX : string
    extraX : float
        parameters previously computed
    solarFeat / ntwFeat : class solarFeatures / ntwFeatures
    
    Returns
    -------
    (costs, CO2, Prim) : tuple of floats
    
    """
    print "Evaluate an individual"
    print individual, "\n"

    print "Check the individual"
    nBuildings = len(buildList)
    cCheck.controlCheck(individual, nBuildings, gv)

    indCombi = sFn.readCombi(individual, gv)
    costs = extraCosts
    CO2 = extraCO2
    prim = extraPrim
    QUncoveredDesign = 0
    QUncoveredAnnual = 0

    print indCombi.count("0")
    print indCombi.count("1")

    if indCombi.count("0") == 0:
        fNameNtw = "Network_summary_result_all.csv"
    else:
        fNameNtw = "Network_summary_result_" + indCombi + ".csv"

    if indCombi.count("1") > 0:
        Qheatmax = sFn.calcQmax(fNameNtw, locator.pathNtwRes, gv)
    else:
        Qheatmax = 0

    print Qheatmax, "Qheatmax in network"
    Qnom = Qheatmax * (1 + gv.Qmargin_ntw)

    # Modify the individual with the extra GHP constraint
    try:
        cCheck.GHPCheck(individual, locator.pathRaw, Qnom, gv)
        print "GHP constraint checked \n"
    except:
        print "No GHP constraint check possible \n"

    # Export to context
    dicoSupply = readInd(individual, Qheatmax, locator, gv)
    dicoSupply.NETWORK_DATA_FILE = fNameNtw

    if dicoSupply.nBuildingsConnected > 1:
        if indCombi.count("0") == 0:
            dicoSupply.fNameTotalCSV = locator.pathRaw + "/Total.csv"
        else:
            dicoSupply.fNameTotalCSV = locator.pathTotalNtw + "/Total_" + indCombi + ".csv"
    else:
        dicoSupply.fNameTotalCSV = locator.pathSubsRes + "/Total_" + indCombi + ".csv"

    if indCombi.count("1") > 0:
        #print "Dummy evaluation of", dicoSupply.configKey
        #(slavePrim, slaveCO2, slaveCosts, QUncoveredDesign, QUncoveredAnnual) = sFn.dummyevaluate(individual)

        print "Slave routine on", dicoSupply.configKey
        (slavePrim, slaveCO2, slaveCosts, QUncoveredDesign,
         QUncoveredAnnual) = sM.slaveMain(locator, fNameNtw, dicoSupply,
                                          solarFeat, gv)
        print slaveCosts, slaveCO2, slavePrim, "slaveCosts, slaveCO2, slavePrim \n"

        costs += slaveCosts
        CO2 += slaveCO2
        prim += slavePrim

    else:
        print "No buildings connected to network \n"

    print "Add extra costs"
    (addCosts, addCO2, addPrim) = eM.addCosts(indCombi, buildList, locator,
                                              dicoSupply, QUncoveredDesign,
                                              QUncoveredAnnual, solarFeat,
                                              ntwFeat, gv)
    print addCosts, addCO2, addPrim, "addCosts, addCO2, addPrim \n"

    if gv.ZernezFlag == 1:
        coolCosts, coolCO2, coolPrim = 0, 0, 0
    else:
        (coolCosts, coolCO2, coolPrim) = coolMain.coolingMain(
            locator, dicoSupply.configKey, ntwFeat,
            dicoSupply.WasteServersHeatRecovery, gv)

    print coolCosts, coolCO2, coolPrim, "coolCosts, coolCO2, coolPrim \n"

    costs += addCosts + coolCosts
    CO2 += addCO2 + coolCO2
    prim += addPrim + coolPrim

    print "Evaluation of", dicoSupply.configKey, "done"
    print costs, CO2, prim, " = costs, CO2, prim \n"
    return (costs, CO2, prim)
Esempio n. 8
0
def readInd(individual, Qmax, locator, gv):
    """
    Reads the list encoding a configuration and implementes the corresponding
    for the slave routine's to use
    
    Parameters
    ----------
    individual : list
        configuration from the Master routine
    Qmax : float
        peak heating demand
    locator : string
        path to raw files
    
    Returns
    -------
    dicoSupply : class MasterSlaveVariables
    
    """
    dicoSupply = MSVar.MasterSlaveVariables()
    dicoSupply.configKey = "".join(str(e)[0:4] for e in individual)

    indCombi = sFn.readCombi(individual, gv)
    dicoSupply.nBuildingsConnected = indCombi.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:
            dicoSupply.Furnace_on = 1
            dicoSupply.Furnace_Q_max = max(individual[1] * Qnom,
                                           gv.QminShare * Qnom)
            print dicoSupply.Furnace_Q_max, "Furnace wet"
            dicoSupply.Furn_Moist_type = "wet"
        elif gv.CC_allowed == 1:
            dicoSupply.CC_on = 1
            dicoSupply.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 dicoSupply.CC_GT_SIZE, "CC NG"
            dicoSupply.gt_fuel = "NG"

    #CHP units with BG& furnace with biomass dry
    if individual[0] == 2 or individual[0] == 4:
        if gv.Furnace_allowed == 1:
            dicoSupply.Furnace_on = 1
            dicoSupply.Furnace_Q_max = max(individual[1] * Qnom,
                                           gv.QminShare * Qnom)
            print dicoSupply.Furnace_Q_max, "Furnace dry"
            dicoSupply.Furn_Moist_type = "dry"
        elif gv.CC_allowed == 1:
            dicoSupply.CC_on = 1
            dicoSupply.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 dicoSupply.CC_GT_SIZE, "CC BG"
            dicoSupply.gt_fuel = "BG"

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

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

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

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

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

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

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

    # heat recovery servers and compresor
    irank = gv.nHeat * 2
    dicoSupply.WasteServersHeatRecovery = individual[irank]
    dicoSupply.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(indCombi)):
        index = indCombi[i]
        if index == "1":
            areaAvail += roof_area[i][0]
        totalArea += roof_area[i][0]

    shareAvail = areaAvail / totalArea

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

    return dicoSupply
def readInd(individual, Qmax, locator, gv):
    """
    Reads the list encoding a configuration and implementes the corresponding
    for the slave routine's to use
    
    Parameters
    ----------
    individual : list
        configuration from the Master routine
    Qmax : float
        peak heating demand
    locator : string
        path to raw files
    
    Returns
    -------
    dicoSupply : class MasterSlaveVariables
    
    """
    dicoSupply = MSVar.MasterSlaveVariables()
    dicoSupply.configKey = "".join(str(e)[0:4] for e in individual)
    
    indCombi = sFn.readCombi(individual, gv)
    dicoSupply.nBuildingsConnected = indCombi.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:
            dicoSupply.Furnace_on = 1
            dicoSupply.Furnace_Q_max = max(individual[1] * Qnom, gv.QminShare * Qnom)
            print dicoSupply.Furnace_Q_max, "Furnace wet"
            dicoSupply.Furn_Moist_type = "wet"
        elif gv.CC_allowed == 1:
            dicoSupply.CC_on = 1
            dicoSupply.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 dicoSupply.CC_GT_SIZE, "CC NG"
            dicoSupply.gt_fuel = "NG"
     
    #CHP units with BG& furnace with biomass dry       
    if individual[0] == 2 or individual[0] == 4:
        if gv.Furnace_allowed == 1:
            dicoSupply.Furnace_on = 1
            dicoSupply.Furnace_Q_max = max(individual[1] * Qnom, gv.QminShare * Qnom)
            print dicoSupply.Furnace_Q_max, "Furnace dry"
            dicoSupply.Furn_Moist_type = "dry"
        elif gv.CC_allowed == 1:
            dicoSupply.CC_on = 1
            dicoSupply.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 dicoSupply.CC_GT_SIZE, "CC BG"
            dicoSupply.gt_fuel = "BG"

    # Base boiler NG 
    if individual[2] == 1:
        dicoSupply.Boiler_on = 1
        dicoSupply.Boiler_Q_max = max(individual[3] * Qnom, gv.QminShare * Qnom)
        print dicoSupply.Boiler_Q_max, "Boiler base NG"
        dicoSupply.BoilerType = "NG"
    
    # Base boiler BG    
    if individual[2] == 2:
        dicoSupply.Boiler_on = 1
        dicoSupply.Boiler_Q_max = max(individual[3] * Qnom, gv.QminShare * Qnom)
        print dicoSupply.Boiler_Q_max, "Boiler base BG"
        dicoSupply.BoilerType = "BG"
    
    # peak boiler NG         
    if individual[4] == 1:
        dicoSupply.BoilerPeak_on = 1
        dicoSupply.BoilerPeak_Q_max = max(individual[5] * Qnom, gv.QminShare * Qnom)
        print dicoSupply.BoilerPeak_Q_max, "Boiler peak NG"
        dicoSupply.BoilerPeakType = "NG"
    
    # peak boiler BG   
    if individual[4] == 2:
        dicoSupply.BoilerPeak_on = 1
        dicoSupply.BoilerPeak_Q_max = max(individual[5] * Qnom, gv.QminShare * Qnom)
        print dicoSupply.BoilerPeak_Q_max, "Boiler peak BG"
        dicoSupply.BoilerPeakType = "BG"
    
    # lake - heat pump
    if individual[6] == 1  and gv.HPLake_allowed == 1:
        dicoSupply.HP_Lake_on = 1
        dicoSupply.HPLake_maxSize = max(individual[7] * Qnom, gv.QminShare * Qnom)
        print dicoSupply.HPLake_maxSize, "Lake"
    
    # sewage - heatpump    
    if individual[8] == 1 and gv.HPSew_allowed == 1:
        dicoSupply.HP_Sew_on = 1
        dicoSupply.HPSew_maxSize = max(individual[9] * Qnom, gv.QminShare * Qnom)
        print dicoSupply.HPSew_maxSize, "Sewage"
    
    # Gwound source- heatpump
    if individual[10] == 1 and gv.GHP_allowed == 1:
        dicoSupply.GHP_on = 1
        GHP_Qmax = max(individual[11] * Qnom, gv.QminShare * Qnom)
        dicoSupply.GHP_number = GHP_Qmax / gv.GHP_HmaxSize
        print GHP_Qmax, "GHP"
    
    # heat recovery servers and compresor
    irank = gv.nHeat * 2
    dicoSupply.WasteServersHeatRecovery = individual[irank]
    dicoSupply.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(indCombi) ):
        index = indCombi[i]
        if index == "1":
            areaAvail += roof_area[i][0]
        totalArea += roof_area[i][0]

    shareAvail = areaAvail / totalArea    
    
    irank = gv.nHeat * 2 + gv.nHR
    dicoSupply.SOLAR_PART_PV = max(individual[irank] * individual[irank + 1] * individual[irank + 6] * shareAvail,0)
    print dicoSupply.SOLAR_PART_PV, "PV"
    dicoSupply.SOLAR_PART_PVT = max(individual[irank + 2] * individual[irank + 3] * individual[irank + 6] * shareAvail,0)
    print dicoSupply.SOLAR_PART_PVT, "PVT"
    dicoSupply.SOLAR_PART_SC = max(individual[irank + 4] * individual[irank + 5] * individual[irank + 6] * shareAvail,0)
    print dicoSupply.SOLAR_PART_SC, "SC"
    
    return dicoSupply
def evalInd(individual, buildList, locator, extraCosts, extraCO2, extraPrim, solarFeat, ntwFeat, gv):
    """
    Evaluates an individual
    
    Parameters
    ----------
    individual : list
    buildList : list of buildings in the district
    pahthX : string
    extraX : float
        parameters previously computed
    solarFeat / ntwFeat : class solarFeatures / ntwFeatures
    
    Returns
    -------
    (costs, CO2, Prim) : tuple of floats
    
    """
    print "Evaluate an individual"
    print individual, "\n"
    
    print "Check the individual"
    nBuildings = len(buildList)
    cCheck.controlCheck(individual, nBuildings, gv)
    
    indCombi = sFn.readCombi(individual, gv)
    costs = extraCosts
    CO2 = extraCO2
    prim = extraPrim
    QUncoveredDesign = 0
    QUncoveredAnnual = 0

    print indCombi.count("0")
    print indCombi.count("1")
    
    if indCombi.count("0") == 0:
        fNameNtw = "Network_summary_result_all.csv"
    else:
        fNameNtw = "Network_summary_result_" + indCombi + ".csv"
    
    if indCombi.count("1") > 0:    
        Qheatmax = sFn.calcQmax(fNameNtw, locator.pathNtwRes, gv)
    else:
        Qheatmax = 0
    
    print Qheatmax, "Qheatmax in network"
    Qnom = Qheatmax * (1+gv.Qmargin_ntw)
    
    # Modify the individual with the extra GHP constraint
    try:
        cCheck.GHPCheck(individual, locator.pathRaw, Qnom, gv)
        print "GHP constraint checked \n"
    except:
        print "No GHP constraint check possible \n"

    
    # Export to context
    dicoSupply = readInd(individual, Qheatmax, locator, gv)
    dicoSupply.NETWORK_DATA_FILE = fNameNtw
    
    
    if dicoSupply.nBuildingsConnected > 1:
        if indCombi.count("0") == 0:
            dicoSupply.fNameTotalCSV = locator.pathRaw + "/Total.csv"
        else:
            dicoSupply.fNameTotalCSV = locator.pathTotalNtw + "/Total_" + indCombi + ".csv"
    else:
        dicoSupply.fNameTotalCSV = locator.pathSubsRes + "/Total_" + indCombi + ".csv"
    
    if indCombi.count("1") > 0:
        #print "Dummy evaluation of", dicoSupply.configKey
        #(slavePrim, slaveCO2, slaveCosts, QUncoveredDesign, QUncoveredAnnual) = sFn.dummyevaluate(individual)
        
        print "Slave routine on", dicoSupply.configKey
        (slavePrim, slaveCO2, slaveCosts, QUncoveredDesign, QUncoveredAnnual) = sM.slaveMain(locator, fNameNtw, dicoSupply, solarFeat, gv)
        print slaveCosts, slaveCO2, slavePrim, "slaveCosts, slaveCO2, slavePrim \n"
        
        costs += slaveCosts
        CO2 += slaveCO2
        prim += slavePrim
    
    else:
        print "No buildings connected to network \n"


    print "Add extra costs"
    (addCosts, addCO2, addPrim) = eM.addCosts(indCombi, buildList, locator, dicoSupply, QUncoveredDesign, QUncoveredAnnual, solarFeat, ntwFeat, gv)
    print addCosts, addCO2, addPrim, "addCosts, addCO2, addPrim \n"
    
    if gv.ZernezFlag == 1:
         coolCosts, coolCO2, coolPrim = 0,0,0
    else:
        (coolCosts, coolCO2, coolPrim) = coolMain.coolingMain(locator, dicoSupply.configKey, ntwFeat, dicoSupply.WasteServersHeatRecovery, gv)
        
    print coolCosts, coolCO2, coolPrim, "coolCosts, coolCO2, coolPrim \n"
    
    costs += addCosts + coolCosts
    CO2 += addCO2 + coolCO2
    prim += addPrim + coolPrim
    
    
    print "Evaluation of", dicoSupply.configKey, "done"
    print costs, CO2, prim, " = costs, CO2, prim \n"
    return (costs, CO2, prim)
Esempio n. 11
0
def mcda_indicators(individual, pathX, plot = 0):
    """
    Computes the specific operational costs and the share of local resources
    
    """
    configKey = "".join(str(e)[0:4] for e in individual)
    print configKey
    buildList = sFn.extractList(pathX.pathRaw + "/Total.csv")
    gV = glob.globalVariables()
    
    # Recover data from the PP activation file
    resourcesFile = pathX.pathSlaveRes + "/" + configKey + "PPActivationPattern.csv"
    resourcesdf = pd.read_csv(resourcesFile, usecols=["ESolarProducedPVandPVT", "Q_AddBoiler", "Q_BoilerBase", "Q_BoilerPeak", "Q_CC", "Q_GHP", \
                                                        "Q_HPLake", "Q_HPSew", "Q_primaryAddBackupSum", "Q_uncontrollable"])
                                                        
    Electricity_Solar = resourcesdf.ESolarProducedPVandPVT.sum()
    Q_AddBoiler = resourcesdf.Q_AddBoiler.sum()
    Q_BoilerBase = resourcesdf.Q_BoilerBase.sum()
    Q_BoilerPeak = resourcesdf.Q_BoilerPeak.sum()
    Q_CC = resourcesdf.Q_CC.sum()
    Q_GHP = resourcesdf.Q_GHP.sum()
    Q_HPLake = resourcesdf.Q_HPLake.sum()
    Q_HPSew = resourcesdf.Q_HPSew.sum()
    Q_storage_missmatch = resourcesdf.Q_primaryAddBackupSum.sum()
    Q_uncontrollable = resourcesdf.Q_uncontrollable.sum()

    # Recover data from the Storage Operation file
    resourcesFile = pathX.pathSlaveRes + "/" + configKey + "StorageOperationData.csv"
    resourcesdf = pd.read_csv(resourcesFile, usecols=["Q_SCandPVT_coldstream"])
    Q_fromSolar = resourcesdf.Q_SCandPVT_coldstream.sum()


    # Recover heating needs for decentralized buildings
    indCombi = sFn.readCombi(individual, gV)
    QfromNG = 0
    QfromBG = 0
    QfromGHP = 0
    
    for i in range(len(indCombi)):
        if indCombi[i] == "0": # Decentralized building
            buildName = buildList[i]
            DescentFile = pathX.pathDiscRes + "/DiscOp_" + buildName + "_result.csv"
        
            df = pd.read_csv(DescentFile)
            dfBest = df[ df["Best configuration"] == 1 ]
               
            QfromNG += dfBest["QfromNG"].iloc[0]
            QfromBG += dfBest["QfromBG"].iloc[0]
            QfromGHP += dfBest["QfromGHP"].iloc[0]

    # Recover electricity and cooling needs
    totalFile = pathX.pathRaw + "/Total.csv"
    df = pd.read_csv(totalFile, usecols=["Ealf", "Eauxf", "Ecaf", "Edataf", "Epf"])
    arrayTotal = np.array(df)
    totalElec = np.sum(arrayTotal) * 1E6 # [Wh]

    df = pd.read_csv(totalFile, usecols=["Qcdataf", "Qcicef", "Qcpf", "Qcsf"])
    arrayTotal = np.array(df)
    if individual[12] == 0:
        totalCool = ( np.sum((arrayTotal)[:,:-1]) + np.sum((arrayTotal)[:,-1:]) * (1+gV.DCNetworkLoss) ) * 1E6 # [Wh]
    else:
        totalCool = ( np.sum((arrayTotal)[:,1:-1]) + np.sum((arrayTotal)[:,-1:]) * (1+gV.DCNetworkLoss) ) * 1E6 # [Wh]
    
    
    # Computes the specific operational costs
    totalEnergy = Q_AddBoiler + Q_BoilerBase + Q_BoilerPeak + Q_CC + Q_GHP + Q_HPLake + \
                  Q_HPSew  + Q_uncontrollable + totalElec + totalCool + \
                  QfromNG + QfromBG + QfromGHP# + Q_storage_missmatch
                  
    shareCC_NG = individual[0] % 2 * Q_CC / totalEnergy
    shareCC_BG = ( individual[0] + 1 ) % 2 * Q_CC / totalEnergy
    shareBB_NG = individual[2] % 2 * Q_BoilerBase / totalEnergy
    shareBB_BG = ( individual[2] + 1 ) % 2 * Q_BoilerBase / totalEnergy
    shareBP_NG = individual[4] % 2 * Q_BoilerPeak / totalEnergy
    shareBP_BG = ( individual[4] + 1 ) % 2 * Q_BoilerPeak / totalEnergy
    shareHPLake = Q_HPLake / totalEnergy
    shareHPSew = Q_HPSew / totalEnergy
    shareGHP = Q_GHP / totalEnergy
    shareExtraNG = (Q_AddBoiler + Q_storage_missmatch) / totalEnergy
    shareHR = (Q_uncontrollable - Q_fromSolar) / totalEnergy
    shareHeatSolar = Q_fromSolar / totalEnergy
    shareDecentralizedNG = QfromNG / totalEnergy
    shareDecentralizedBG = QfromBG / totalEnergy
    shareDecentralizedGHP = QfromGHP / totalEnergy
    shareElecGrid = (totalElec - Electricity_Solar) / totalEnergy
    shareElecSolar = Electricity_Solar / totalEnergy
    shareCoolLake = totalCool / totalEnergy
    
    printout = 1
    if printout:
        print 'CC_NG', individual[0] % 2 * Q_CC
        print 'CC_BG', ( individual[0] + 1 ) % 2 * Q_CC
        print 'BB_NG', individual[2] % 2 * Q_BoilerBase
        print 'BB_BG', ( individual[2] + 1 ) % 2 * Q_BoilerBase
        print 'BP_NG', individual[4] % 2 * Q_BoilerPeak
        print 'BP_BG', ( individual[4] + 1 ) % 2 * Q_BoilerPeak
        print 'HPLake', Q_HPLake
        print 'HPSew', Q_HPSew
        print 'GHP', Q_GHP
        print 'ExtraNG', (Q_AddBoiler + Q_storage_missmatch)
        print 'HR', (Q_uncontrollable - Q_fromSolar)
        print 'HeatSolar', Q_fromSolar
        print 'DecentralizedNG', QfromNG
        print 'DecentralizedBG', QfromBG
        print 'DecentralizedGHP', QfromGHP
        print 'ElecGrid', (totalElec - Electricity_Solar)
        print 'ElecSolar', Electricity_Solar
        print 'CoolLake', totalCool

        print 'shareCC_NG', shareCC_NG*100 
        print 'shareCC_BG', shareCC_BG*100
        print 'shareBB_NG', shareBB_NG*100
        print 'shareBB_BG',  shareBB_BG*100
        print 'shareBP_NG', shareBP_NG*100
        print 'shareBP_BG', shareBP_BG*100 
        print 'shareHPLake', shareHPLake*100 
        print 'shareHPSew', shareHPSew*100 
        print 'shareGHP', shareGHP*100 
        print 'shareExtraNG', shareExtraNG*100 
        print 'shareHR', shareHR*100
        print 'shareHeatSolar', shareHeatSolar*100
        print 'shareDecentralizedNG', shareDecentralizedNG*100
        print 'shareDecentralizedBG', shareDecentralizedBG*100 
        print 'shareDecentralizedGHP', shareDecentralizedGHP*100
        print 'shareElecGrid' ,shareElecGrid*100 
        print 'shareElecSolar', shareElecSolar*100 
        print 'shareCoolLake', shareCoolLake*100

    specificCosts = gV.ELEC_PRICE * shareElecGrid + \
                    gV.NG_PRICE * (shareCC_NG + shareBB_NG + shareBP_NG + shareExtraNG + shareDecentralizedNG) + \
                    gV.BG_PRICE * (shareCC_BG + shareBB_BG + shareBP_BG + shareDecentralizedBG)
    
    # Computes the share of local resources
    shareLocal = shareHPLake + shareHPSew + shareGHP + shareHR + shareHeatSolar + shareDecentralizedGHP + shareElecSolar + shareCoolLake
    
    # Plots the pie chart for energy resources use
    if plot == 1:
        fig = plt.figure()
        subplot = fig.add_subplot(111, adjustable = 'box', aspect = 1, title = 'Energy mix')
        
        labels = ['Lake', 'Solar', 'HR', 'Ground', 'Gas', 'Grid']
        shareLake = shareHPLake + shareCoolLake
        shareSolar = shareHeatSolar + shareElecSolar
        shareHRAll = shareHPSew + shareHR
        shareGround = shareGHP + shareDecentralizedGHP
        shareGas = 1 - shareLake - shareSolar - shareHRAll - shareGround - shareElecGrid
        
        fracs = [ shareLake, shareSolar, shareHRAll, shareGround, shareGas, shareElecGrid ]
        colors = ['RoyalBlue', 'Gold', 'LightGreen', 'SandyBrown', 'OrangeRed', 'Gray']
        
        zipper = [ (l,f,c) for (l,f,c) in zip(labels,fracs,colors) if f > 0.001 ]
        labelsPlot, fracsPlot, colorsPlot = map( list, zip(*zipper) )
        subplot.pie(fracsPlot, labels = labelsPlot, colors = colorsPlot, startangle = 90, autopct='%1.1f%%', pctdistance = 0.65)
        
        plt.show()
    
    return specificCosts, shareLocal