Exemplo n.º 1
0
def RLCSimulation(folderName, inputType, unit, approachName, houseNumber, randomFlag):
    '''
    This method used to construct yaml file and construct the RLC result based on random.
        str, str, int, str, [int, int, ...] => file
    '''
    
    # read CSV input files
    Result = ReadCSV(folderName, inputType)
    requests = list(Result[0])
    
    ideal_type_load = modify_ideal_load(Result[1][-1], unit)
    
    # write load profile files
    getLoadProfileFiles(folderName, unit)
        
    # get house layout and zip_loads
    houseLayout = yamlCalcMethods.getHouseLayout(houseNumber, requests)
    S_ZipList = yamlCalcMethods.getSZipList(len(houseLayout))
    lengthMvList = yamlCalcMethods.getLengthMvList(len(houseLayout))
    
    # get the load, which not perform RLC approach
    original_loads = getOriginalObservedLoad(Result, unit, approachName)
    
    # get the relationship between request name, and its last minute number
    requestNameMinMap = yamlCalcMethods.getRequestNameMinMap(requests) # get the requestNameMinMap
    
    # write yaml file, and return RLC result
    random_observed_loads = writeYamlFileAndReturnRandomProbabilities(Result, houseNumber, requests, unit, folderName, approachName, houseLayout, requestNameMinMap, S_ZipList, lengthMvList)
    
    # write the csv file which save original and RLC loads
    write_output(ideal_type_load, original_loads, random_observed_loads, folderName, inputType, randomFlag)
    
    print 'FINISH Random Output'
Exemplo n.º 2
0
def calcRandStartTime(Result, unit, approachName, houseNumber):
    """
    This method used to get the load information based on random number
    for each request from each 'house'. Then start time of each house in different appliances
        [request,...], int, string, int => {str : [float, float,...], ...}
    """
    
    ideal_shiftable_load = modify_ideal_load(Result[1][-1], unit) # get ideal shift-able load
    signal_load = list(ideal_shiftable_load) # make ideal shift-able load equal to signal load
    
    ## first of all, get requests from reading result
    requests = Result[0]
    
    requests = updateProfile(requests, unit) # update profile
    requests = getProbDistribution(requests, signal_load, unit, approachName) # update probabilities
    requestTypeNumberDict = getEachRequetsTypeNumber(Result[0]) # dict with key-value: requestName to this Type requests Number
    requestTypeGroupDict = getRequestTypeGroupNumber(requestTypeNumberDict) # distribute the request types into four big groups
    requestNameRequestsMap = orderRequests(requests) # use to save request with same request name
    
    for requestTypeGroup in requestTypeGroupDict.keys(): 
        
        if houseNumber <= requestTypeGroupDict.get(requestTypeGroup):
            groupMultiplyMap = {}
        
            for requestTypeGroup in requestTypeGroupDict.keys():
                groupMultiplyMap[requestTypeGroup] = float(houseNumber) / requestTypeGroupDict[requestTypeGroup]
                
                applianceDict = getRandStartTimeGreaterThanHouse(groupMultiplyMap, requestNameRequestsMap, requestTypeNumberDict, unit, houseNumber)
        
        else:
            applianceDict = getRandStartTimeLessThanHouse(requestNameRequestsMap, unit)
    
    return applianceDict
Exemplo n.º 3
0
def getOriginalObservedLoad(Result, unit, approachName):
    '''
    This method used to get the orginial observed load, without perform RLC approach.
        Result, int, str => [[int, int, ]]
    '''
    requests = list(Result[0])
    
    # get the start observed result
    ideal_type_load = modify_ideal_load(Result[1][-1], unit)
    initialResult = initialSituation(ideal_type_load, requests, unit, approachName)
    original_observed_load = initialResult[1] # get the observed load without random approach
    original_loads = [original_observed_load]
    
    return original_loads    
Exemplo n.º 4
0
def main():
    
    ## input information
    folder_name = 'Experiment2_1'
    input_type = 'ideal_shiftable_load'
    unit = 5
    approach_name = 'profile_load'
    random_flag = True
    
    Result = ReadCSV(folder_name, input_type) # read requests information from input csv file
    requests = Result[0]
    ideal_type_load = modify_ideal_load(Result[1][-1], unit)

    initialResult = initialSituation(ideal_type_load, requests, unit, approach_name)
    original_observed_load = initialResult[1] # get the observed load without random approach
    original_loads = [original_observed_load]
    random_observed_load = calcRandLoad(Result, unit, approach_name) # get observed load
    
    ## get output relative parameters
    random_observed_loads = [random_observed_load] 
    
    write_output(ideal_type_load, original_loads, random_observed_loads, folder_name, input_type, random_flag) # output results
    
    print 'Job Done.'
def writeYamlFileWithLargeNumOfHouses(folderName, inputType, unit, approachName, houseNumber):
    """
    This method used to create a yaml file with the large number of houses. In order to save code time, several
    methods will import from 'yamlCalcMethods' and 'yamlWriteMethods'. Consider of the tiny different requirement,
    it is better to write a new python to construct yaml file.
        str, str, int, str, int, float => file
    """

    print "START read request type file"
    RequestTypeDict = CsvToLoad.readExperiment(folderName)

    for RequestType in RequestTypeDict.values():
        load_list = CsvToLoad.extractApplianceProfile(RequestType, unit)
        CsvToLoad.generateLoadTxt(load_list, RequestType.request_name, folderName, unit)

    print "START read requests file"
    Result = ReadCSV(folderName, inputType)  # read requests information from input csv file
    requests = list(Result[0])

    houseLayout = yamlCalcMethods.getHouseLayout(houseNumber, requests)

    requestNameMinMap = yamlCalcMethods.getRequestNameMinMap(requests)  # get the requestNameMinMap

    ideal_shiftable_load = modify_ideal_load(Result[1][-1], unit)  # get ideal shift-able load
    signal_load = list(ideal_shiftable_load)  # make ideal shift-able load equal to signal load

    requests = updateProfile(requests, unit)  # update profile
    requests = getProbDistribution(requests, signal_load, unit, approachName)  # update probabilities

    fileCount = 0
    totalRequestNumber = getTotalRequestNumber(requests)
    restRequestNumber = int(totalRequestNumber)

    while restRequestNumber != 0:

        if restRequestNumber < houseNumber:
            repeatNumber = restRequestNumber

        else:
            repeatNumber = houseNumber

        fileName = "".join(("CSVdata/", folderName, "/resident/" "resident_", folderName, "_", str(fileCount), ".yaml"))

        applianceMap = getApplianceMap(repeatNumber, requests, unit)  # get the start time and request name dict

        requests = setNewRequests(requests)  # delete the request which quantity is zero

        writeFile = open(fileName, "w")

        yamlWriteMethods.writeConstParameters(writeFile)

        yamlWriteMethods.writeHouseLayout(writeFile, houseLayout)

        yamlWriteMethods.writeVariableList(writeFile, houseLayout)

        yamlWriteMethods.writeConstSimulation(writeFile)

        yamlWriteMethods.writeConstNetwork(writeFile)

        yamlWriteMethods.writeConstHeartbeat(writeFile)

        yamlWriteMethods.writeTimeSerialLoop(writeFile, applianceMap, folderName)  # write load / time_series content

        yamlWriteMethods.writeConstBus(writeFile)

        yamlWriteMethods.writeConstGenericgen(writeFile)

        yamlWriteMethods.writeConstLoop(writeFile)

        applianceCount = 0

        yamlWriteMethods.writeAllAppliance(houseLayout, writeFile, applianceMap, applianceCount, requestNameMinMap)

        writeFile.close()

        print "No.",
        print fileCount,
        print "yaml file had constructed"

        fileCount = fileCount + 1
        restRequestNumber = restRequestNumber - repeatNumber

    print "CONSTRUCT ",
    print fileCount,
    print "yaml files"
Exemplo n.º 6
0
def calcRandLoad(Result, unit, approach_name):
    """
    This method used to get the load information based on random number
    for each request from each 'house'. Then get a load result.
        [request,...], int, string => [float, float,...]
    """
    
    ideal_shiftable_load = modify_ideal_load(Result[1][-1], unit) # get ideal shift-able load
    signal_load = list(ideal_shiftable_load) # make ideal shift-able load equal to signal load
    
    ## first of all, get requests from reading result
    requests = Result[0]
    
    requests = updateProfile(requests, unit) # update profile
    requests = getProbDistribution(requests, signal_load, unit, approach_name) # update probabilities
    
    for request in requests:
        
        #print 'before: '
        #print request.request_type.request_name, ' : ', request.probabilities
        
        getPureProbabilities(request) # get the new probabilities
        
        quantitiy = request.quantity

        newProbabilities = [0] * len(request.pure_probabilities)
        
        for count in range(quantitiy):
            
            randomNum = random.random()
            
            if randomNum < request.pure_probabilities[0] or randomNum == request.pure_probabilities[0] :
                newProbabilities[0] = newProbabilities[0] + 1
                continue
            
            elif randomNum > request.pure_probabilities[-1] or randomNum == request.pure_probabilities[-1]:
                newProbabilities[-1] = newProbabilities[-1] + 1
                continue
            
            else:
                
                for probCount in range(len(request.pure_probabilities)):

                    if randomNum > request.pure_probabilities[probCount]:
                        if randomNum < request.pure_probabilities[probCount + 1] or randomNum == request.pure_probabilities[probCount + 1]:
                            newProbabilities[probCount + 1] = newProbabilities[probCount + 1] + 1
                            break
                        else:
                            continue
        
        for count in range(len(newProbabilities)):
            
            newProbabilities[count] = newProbabilities[count] / (quantitiy * 1.0)
        
        request.update_pure_probabilities(newProbabilities)
        
        ## then, modify the actual probabilities
        modifyActualProbabilities(request)
        
        print 'Finish Request: ', request.request_type.request_name
        
        #print 'after: '
        #print request.request_type.request_name, ' : ', request.probabilities
    
    observed_load = calculateExpectedLoad(requests, unit)
    
    return observed_load