コード例 #1
0
def ClearList(pList):
    global thputList, delayList
    copydata.Show(pList)
    copydata.Show(thputList)
    pList.append(round(pList[GetIndexToMaxThput()], 2))
    thputList = []
    delayList = []
コード例 #2
0
def AppendParameter(PARAMETER, p_temp):
    if PARAMETER == parameter.FLAG_EXIT:
        copydata.Show("append parameter failure! because PARAMETER = FLAG_EXIT.")
        sys.exit(0)

    path = GetCurrentPath()
    if path == 0:
        copydata.Show("Get current path failure!")
        return
    
    if PARAMETER == parameter.FLAG_GAMMA:
        gammaList.append(round(p_temp, 2))
        thput, delay = avgthputdelay.GetThputDelay(path, p_temp, parameter.INIT_T, parameter.INIT_WINDOW, parameter.INIT_DELTA)
    elif PARAMETER == parameter.FLAG_T:
        tList.append(round(p_temp, 2))
        copydata.Show("t =", p_temp)
        thput, delay = avgthputdelay.GetThputDelay(path, gammaList[-1], p_temp, parameter.INIT_WINDOW, parameter.INIT_DELTA)
    elif PARAMETER == parameter.FLAG_WINDOW:
        windowList.append(round(p_temp, 2))
        copydata.Show("window =", p_temp)
        thput, delay = avgthputdelay.GetThputDelay(path, gammaList[-1], tList[-1], p_temp, parameter.INIT_DELTA)
    else:
        deltaList.append(round(p_temp, 2))
        copydata.Show("delta =", p_temp)
        thput, delay = avgthputdelay.GetThputDelay(path, gammaList[-1], tList[-1], windowList[-1], p_temp)
        
    thputList.append(round(thput, 2))
    delayList.append(round(delay, 2))
コード例 #3
0
def GetThputDelay(path, _gamma, _t, _window, _delta):
    bwList = []
    delayList = []
    copydata.Show("_gamma =", _gamma, "_t =", _t, "_window =", _window,
                  "_delta =", _delta)
    for files in os.listdir(path):
        if files.endswith('.sum'):
            gamma = float(files.split('-')[-6])
            t = float(files.split('-')[-5])
            window = float(files.split('-')[-3])
            delta = float(files.split('-')[-2])
            #t = int(files.split('-')[-4])
            if gamma == _gamma and t == _t and _window == window and _delta == delta:
                files = os.path.join(path, files)
                #print files
                for line in open(files):
                    odom = line.split()
                    #if int(odom[1]) > 2000000:
                    #	continue
                    bwList.append(float(odom[0]))
                    delayList.append(float(odom[1]))
                copydata.Show("sum bandwidth =", sum(bwList),
                              "sum file length =", len(bwList))

    if sum(bwList) == 0 or sum(delayList) == 0:
        copydata.Show("File is NULL!")
        sys.exit(0)
    avgThput = round(float(sum(bwList) / len(bwList)), 2)
    avgDelay = round(float(sum(delayList) / len(delayList)), 2)
    copydata.Show("avg throughput =", avgThput, "avg delay =", avgDelay)

    return avgThput, avgDelay
コード例 #4
0
def UpdateWindow(newThput, delay, bdLevel, oldThput, oldWindow, newWindow):

    if delay > parameter.THRESHOLD:
        newWindow = float((oldWindow + newWindow) / 2)
        copydata.Show("delay is more than THRESHOLD!")
        return round(newWindow, 2)
    elif newThput - oldThput > 0:
        deltaThput = newThput - oldThput
        oldWindow = newWindow
        #because T's incremental is large, such as deltaT = 5000 or deltaT = 15000,
        #but gamma's incremental is small, such as deltagamma = 0.1 or deltagamma = 0.2,
        #MS_US = 1000 and UNIT = 100
        step = round(
            float(deltaThput) / ((bdLevel + 1) * 100) * parameter.MS_US *
            parameter.MS_US, 2)
        if abs(step) < 10000.0:
            return parameter.FLAG_DELTA
        copydata.Show("window step =", step)
        newWindow = float(oldWindow + step)
        return round(newWindow, 2)
    elif newThput - oldThput < 0:
        newWindow = float((oldWindow + newWindow) / 2)
        step = round(float(oldWindow - newWindow), 2)
        copydata.Show("new throughput is less than old throughput!")
        if abs(step) < 10000.0:
            return parameter.FLAG_DELTA
        copydata.Show("window step =", step)
        return round(newWindow, 2)
    else:
        copydata.Show("Iteration is done!")
        return parameter.FLAG_DELTA
コード例 #5
0
def UpdateGamma(newThput, delay, bdLevel, oldThput, oldGamma, newGamma):

    #print oldGamma, newGamma
    if delay > parameter.THRESHOLD:
        newGamma = (oldGamma + newGamma) / 2
        copydata.Show("delay is more than THRESHOLD!")
        return round(newGamma, 2)
    elif newThput > oldThput:
        deltaThput = newThput - oldThput
        oldGamma = newGamma
        step = round(float(deltaThput) / ((bdLevel + 1) * 100), 2)
        if abs(step) < 0.001:
            return parameter.FLAG_T
        newGamma = oldGamma + step
        copydata.Show("gamma step =", step)
        return round(newGamma, 2)
    elif newThput < oldThput:
        newGamma = (oldGamma + newGamma) / 2
        step = round(float(oldGamma - newGamma), 2)
        if abs(step) < 0.001:
            return parameter.FLAG_T
        copydata.Show("step =", step)
        copydata.Show("new throughput is less than old throughput!")
        return round(newGamma, 2)
    else:
        copydata.Show("gamma's iteration is done!")
        return parameter.FLAG_T
コード例 #6
0
def UpdateParameter(newThput, delay, bdLevel, PARAMETER):
    if PARAMETER == parameter.FLAG_GAMMA:
        copydata.Show("gamma history", gammaList)
        return update.UpdateGamma(newThput, delay, bdLevel, thputList[-2], gammaList[-2], gammaList[-1])
    elif PARAMETER == parameter.FLAG_T:
        copydata.Show("tList history", tList)
        return update.UpdateT(newThput, delay, bdLevel, thputList[-2], tList[-2], tList[-1])
    elif PARAMETER == parameter.FLAG_WINDOW:
        copydata.Show("windowList history", windowList)
        return update.UpdateWindow(newThput, delay, bdLevel, thputList[-2], windowList[-2], windowList[-1])
    else:
        copydata.Show("deltaList history", deltaList)
        return update.UpdateDelta(newThput, delay, bdLevel, thputList[-2], deltaList[-2], deltaList[-1])
コード例 #7
0
def InitialFunc(PARAMETER):
    if PARAMETER == parameter.FLAG_EXIT:
        copydata.Show("initial failure! because PARAMETER = FLAG_EXIT.")

    #fix T, WINDOW, delta, adjust gamma
    if PARAMETER == parameter.FLAG_GAMMA:
        Initial(PARAMETER, parameter.INIT_GAMMA)
        Initial(PARAMETER, parameter.SEC_GAMMA, parameter.SEC_GAMMA)
            
    #fix gamma, WINDOW, delta, adjust T
    elif PARAMETER == parameter.FLAG_T:
        ClearList(gammaList)
        AppendParameter(PARAMETER, parameter.INIT_T)
        Initial(PARAMETER, parameter.SEC_T, gammaList[-1], parameter.SEC_T)

    #fix gamma, T, delta, adjust WINDOW
    elif PARAMETER == parameter.FLAG_WINDOW:
        ClearList(tList)
        AppendParameter(PARAMETER, parameter.INIT_WINDOW)
        Initial(PARAMETER, parameter.SEC_WINDOW, gammaList[-1], tList[-1], parameter.SEC_WINDOW)

    #fix gamma, T, WINDOW, adjust delta
    elif PARAMETER == parameter.FLAG_DELTA:
        ClearList(windowList)
        AppendParameter(PARAMETER, parameter.INIT_DELTA)
        Initial(PARAMETER, parameter.SEC_DELTA, gammaList[-1], 
                tList[-1], windowList[-1], parameter.SEC_DELTA)
コード例 #8
0
def UpdateData():
    sPath = GetCurrentPath()
    if sPath == 0:
        copydata.Show("Get current path failure!")
    dirName = sPath.split('/')[-1]
    dPath = copydata.MakeDir(savePath, dirName)
    copydata.FindFiles(dPath, sPath)
    shutil.rmtree(sPath)
コード例 #9
0
def ChangeParameter(p_temp, PARAMETER):
    if isinstance(p_temp, float):
        copydata.Show("p_temp is a float number!")
        return False
    if p_temp != PARAMETER:
        return True
    else:
        return False
コード例 #10
0
def RunFunction(p_temp, PARAMETER):
    if PARAMETER == parameter.FLAG_EXIT:
        copydata.Show("run failure! because PARAMETER = parameter.FLAG_EXIT.")
        sys.exit(0)
    if PARAMETER == parameter.FLAG_GAMMA:
        RunMulThread(p_temp, parameter.INIT_T, parameter.INIT_WINDOW, parameter.INIT_DELTA)
    elif PARAMETER == parameter.FLAG_T:
        RunMulThread(gammaList[-1], p_temp, parameter.INIT_WINDOW, parameter.INIT_DELTA)
    elif PARAMETER == parameter.FLAG_WINDOW:
        RunMulThread(gammaList[-1], tList[-1], p_temp, parameter.INIT_DELTA)
    else :
        RunMulThread(gammaList[-1], tList[-1], windowList[-1], p_temp)
コード例 #11
0
    if sPath == 0:
        copydata.Show("Get current path failure!")
    dirName = sPath.split('/')[-1]
    dPath = copydata.MakeDir(savePath, dirName)
    copydata.FindFiles(dPath, sPath)
    shutil.rmtree(sPath)

if __name__ == "__main__":

    while 1:
        InitialFunc(PARAMETER)

        while not stopIteration():
            path = GetCurrentPath()
            if path == 0:
                copydata.Show("Get current path failure!")
            bdLevel = int(item[0].split('_')[-1])
            #temp can be gamma, T, window, delta
            temp = UpdateParameter(thputList[-1], delayList[-1], bdLevel/100000, PARAMETER)
            if ChangeParameter(temp, PARAMETER):
                WriteResult(temp)
                copydata.Show ("temp = ", temp, "PARAMETER = ", PARAMETER)
                PARAMETER = temp
                break
            RunFunction(temp, PARAMETER)
            #copydata.Show("gamma =", p_temp)
            AppendParameter(PARAMETER, temp)

        if IteraterExit(PARAMETER):
            copydata.Show("iterater done!")
            break