コード例 #1
0
def testHeightABR(testHeightsStart):
    elements = testHeightsStart[0]
    rangeElements = testHeightsStart[1]

    arrayHeightABR = []
    resultRandomHeightABR = []
    averageArrayHeightABR = []

    print "\n", "=" * 100
    print "Average heights of Binary Search Trees for random elements. 3 executions. "
    print "Columns: ranges [20, 200, 1000, 10000000]. "
    print "Lines: elements [10, 50, 500, 1000, 10000, 50000]"
    print "=" * 100, "\n"

    for p in elements:
        for i in rangeElements:
            for j in range(3):
                ABRtree = ABR.BinarySearchTree()
                for k in range(p):
                    ABRtree.insert(random.randint(0, i))
                heightABR = ABRtree.getHeight(ABRtree.root)
                arrayHeightABR.append(heightABR)
            averageArrayHeightABR.append(
                sum(arrayHeightABR) / len(arrayHeightABR))
            arrayHeightABR = []

        resultRandomHeightABR.append(averageArrayHeightABR)
        print averageArrayHeightABR
        averageArrayHeightABR = []

    return resultRandomHeightABR
コード例 #2
0
 def __init__(self,testing=False):
     mkdir_if_not_exist(MODEL_PATH)
     self.load_environment()
     self.abr = ABR.Algorithm()  # 加载ABR算法
     self.abr.Initial()
     # self.step_count = 0
     self.episode_count = 0
     self.target_net_update_count = 0
     self.testing = testing
     self.update_target_episode = UPDATE_TARGET_BY_EPISODE_START
     self.update_target_interval = UPDATE_TARGET_BY_EPISODE_START + UPDATE_TARGET_RATE
コード例 #3
0
ファイル: online_test.py プロジェクト: weih14/master_1
def test(user_id):
    #TRAIN_TRACES = '/home/game/test_sim_traces/'   #train trace path setting,
    #video_size_file = '/home/game/video_size_'      #video trace path setting,
    #LogFile_Path = "/home/game/log/"                #log file trace path setting,

    TRAIN_TRACES = './network_trace_2/'  #train trace path setting,
    #video_size_file = './video_trace/AsianCup_China_Uzbekistan/frame_trace_'      #video trace path setting,
    #video_size_file = './video_trace/Fengtimo_2018_11_3/frame_trace_'      #video trace path setting,
    #video_size_file = './video_trace/YYF_2018_08_12/frame_trace_'      #video trace path setting,

    #video_size_file = './video_trace_2/game/frame_trace_'
    video_size_file = './video_trace_2/room/frame_trace_'
    #video_size_file = './video_trace_2/sports/frame_trace_'

    LogFile_Path = "./log/"  #log file trace path setting,
    # Debug Mode: if True, You can see the debug info in the logfile
    #             if False, no log ,but the training speed is high
    DEBUG = False
    # load the trace
    all_cooked_time, all_cooked_bw, all_file_names = load_trace.load_trace(
        TRAIN_TRACES)
    #random_seed
    random_seed = 2
    count = 0
    video_count = 0
    FPS = 25
    frame_time_len = 0.04
    reward_all_sum = 0
    #init
    #setting one:
    #     1,all_cooked_time : timestamp
    #     2,all_cooked_bw   : throughput
    #     3,all_cooked_rtt  : rtt
    #     4,agent_id        : random_seed
    #     5,logfile_path    : logfile_path
    #     6,VIDEO_SIZE_FILE : Video Size File Path
    #     7,Debug Setting   : Debug
    net_env = fixed_env.Environment(all_cooked_time=all_cooked_time,
                                    all_cooked_bw=all_cooked_bw,
                                    random_seed=random_seed,
                                    logfile_path=LogFile_Path,
                                    VIDEO_SIZE_FILE=video_size_file,
                                    Debug=DEBUG)
    abr_return = ABR_RETURN.Algorithm()
    abr_return_init = abr_return.Initial()
    abr = ABR.Algorithm()
    abr_init = abr.Initial()

    BIT_RATE = [500.0, 850.0, 1200.0, 1850.0]  # kpbs
    TARGET_BUFFER = [2.0, 3.0]  # seconds
    # ABR setting
    RESEVOIR = 0.5
    CUSHION = 2

    cnt = 0
    # defalut setting
    last_bit_rate = 0
    bit_rate = 0
    target_buffer = 0
    th_list = [0] * 5
    buffer, cdn_count = 0, 0
    debug_list = [['time','throughput','time_interval', 'send_data_size', 'chunk_len',\
               'rebuf', 'buffer_size', 'play_time_len','end_delay',\
                'cdn_newest_id', 'download_id', 'cdn_has_frame', 'decision_flag',\
                'buffer_flag', 'cdn_flag', 'end_of_video']]
    wr = [[
        'time', 'prediction_bitrate', 'next_segment_rate', 'segment_rate',
        'cdn_list', 'ave_th', 'curr_th', 'th_10', 'th_20', 'th_30', 'th_40',
        'th_50', 'buffer', 'cdn_buffer', 'buffer_flag', 'cdn_flag',
        'cdn_count', 'end_delay', 'cdn_newest_id', 'download_id', 'bit_rate',
        'qoe_label', 'qoe_1', 'qoe_2', 'qoe_3', 'qoe_4'
    ]]
    # QOE setting
    reward_frame = 0
    reward_all = 0
    reward_all_1, reward_all_2, reward_all_3, reward_all_4 = 0, 0, 0, 0
    last_reward_all_1, last_reward_all_2, last_reward_all_3, last_reward_all_4 = 0, 0, 0, 0
    last_segment_reward = 0
    ll_segment_info = [0] * 8
    SMOOTH_PENALTY = 0.02
    REBUF_PENALTY = 1.5
    LANTENCY_PENALTY = 0.005
    # past_info setting
    past_frame_num = 7500
    S_time_interval = [0] * past_frame_num
    S_send_data_size = [0] * past_frame_num
    S_chunk_len = [0] * past_frame_num
    S_rebuf = [0] * past_frame_num
    S_buffer_size = [0] * past_frame_num
    S_end_delay = [0] * past_frame_num
    S_chunk_size = [0] * past_frame_num
    S_play_time_len = [0] * past_frame_num
    S_decision_flag = [0] * past_frame_num
    S_buffer_flag = [0] * past_frame_num
    S_cdn_flag = [0] * past_frame_num
    # params setting

    is_terminated = False
    cnt_segment = 0
    #q_table = pd.read_csv('qtable.csv',names=actions,header=0)
    while True:
        reward_frame = 0
        reward_1, reward_2, reward_3, reward_4 = 0, 0, 0, 0

        # input the train steps
        #if cnt > 5000:
        #plt.ioff()
        #    break
        #actions bit_rate  target_buffer
        # every steps to call the environment
        # time           : physical time
        # time_interval  : time duration in this step
        # send_data_size : download frame data size in this step
        # chunk_len      : frame time len
        # rebuf          : rebuf time in this step
        # buffer_size    : current client buffer_size in this step
        # rtt            : current buffer  in this step
        # play_time_len  : played time len  in this step
        # end_delay      : end to end latency which means the (upload end timestamp - play end timestamp)
        # decision_flag  : Only in decision_flag is True ,you can choose the new actions, other time can't Becasuse the Gop is consist by the I frame and P frame. Only in I frame you can skip your frame
        # buffer_flag    : If the True which means the video is rebuffing , client buffer is rebuffing, no play the video
        # cdn_flag       : If the True cdn has no frame to get
        # end_of_video   : If the True ,which means the video is over.
        time,time_interval, send_data_size, chunk_len,\
               rebuf, buffer_size, play_time_len,end_delay,\
                cdn_newest_id, download_id, cdn_has_frame, decision_flag,\
                buffer_flag, cdn_flag, end_of_video = net_env.get_video_frame(bit_rate,target_buffer)
        if time_interval != 0:
            throughput = send_data_size / time_interval / 1000
        else:
            throughput = 0
        debug_list.append([time,throughput,time_interval, send_data_size, chunk_len,\
               rebuf, buffer_size, play_time_len,end_delay,\
                cdn_newest_id, download_id, cdn_has_frame, decision_flag,\
                buffer_flag, cdn_flag, end_of_video])

        # S_info is sequential order
        S_time_interval.pop(0)
        S_send_data_size.pop(0)
        S_chunk_len.pop(0)
        S_buffer_size.pop(0)
        S_rebuf.pop(0)
        S_end_delay.pop(0)
        S_play_time_len.pop(0)
        S_decision_flag.pop(0)
        S_buffer_flag.pop(0)
        S_cdn_flag.pop(0)

        S_time_interval.append(time_interval)
        S_send_data_size.append(send_data_size)
        S_chunk_len.append(chunk_len)
        S_buffer_size.append(buffer_size)
        S_rebuf.append(rebuf)
        S_end_delay.append(end_delay)
        S_play_time_len.append(play_time_len)
        S_decision_flag.append(decision_flag)
        S_buffer_flag.append(buffer_flag)
        S_cdn_flag.append(cdn_flag)

        # QOE setting
        if not cdn_flag:
            reward_frame = frame_time_len * float(
                BIT_RATE[bit_rate]
            ) / 1000 - REBUF_PENALTY * rebuf - LANTENCY_PENALTY * end_delay
            reward_1 = frame_time_len * float(BIT_RATE[bit_rate]) / 1000
            reward_2 = REBUF_PENALTY * rebuf
            reward_3 = LANTENCY_PENALTY * end_delay
        else:
            reward_frame = -(REBUF_PENALTY * rebuf)
            reward_1 = 0
            reward_2 = REBUF_PENALTY * rebuf
            reward_3 = 0
        if decision_flag or end_of_video:
            cnt_segment += 1
            # reward formate = play_time * BIT_RATE - 4.3 * rebuf - 1.2 * end_delay
            reward_frame += -1 * SMOOTH_PENALTY * (
                abs(BIT_RATE[bit_rate] - BIT_RATE[last_bit_rate]) / 1000)
            reward_4 = 1 * SMOOTH_PENALTY * (
                abs(BIT_RATE[bit_rate] - BIT_RATE[last_bit_rate]) / 1000)
            # last_bit_rate
            #print(len(th_list),th_list)
            reward_temp_1 = -last_reward_all_1 + reward_all_1
            reward_temp_2 = last_reward_all_2 - reward_all_2
            reward_temp_3 = last_reward_all_3 - reward_all_3
            reward_temp_4 = last_reward_all_4 - reward_all_4
            last_bit_rate = bit_rate
            last_reward_all_1 = reward_all_1
            last_reward_all_2 = reward_all_2
            last_reward_all_3 = reward_all_3
            last_reward_all_4 = reward_all_4
            #==================================Q_learning==============================
            """ action = last_bit_rate
            state = cnt_segment - 1
            next_state = cnt_segment
            R = last_segment_reward
            R = R - 0.1*abs(buffer_size-2.35)
                
            
            q_predict = q_table.loc[state, str(action)]
            if end_of_video:#state != stop_count:
                q_target = R + GAMMA * q_table.iloc[next_state, :].max()   # next state is not terminal
            else:
                q_target = R     # next state is terminal
                is_terminated = True    # terminate this episode
            

            
            q_table.loc[state, str(action)] += ALPHA * (q_target - q_predict)
            #q_table.loc[state, str(action)] = R

            if is_terminated:
                #print(q_table)
                q_table.to_csv('qtable.csv')
                break

            state_actions = q_table.iloc[next_state, :]
            if (np.random.uniform() > EPSILON) or ((state_actions == 0).all()):  # act non-greedy or state-action have no value
                action_name = np.random.choice(actions)
            else:   # act greedy
                action_name = state_actions.idxmax()    # replace argmax to idxmax as argmax means a different function in newer version of pandas
            
            #print(state,action,R,next_state,q_table.loc[state, str(action)],action_name)
            #print(q_table)
            #==================================Q_learnign=========================== """

            # -------------------------------------------Your Althgrithom -------------------------------------------
            # which part is the althgrothm part ,the buffer based ,
            # if the buffer is enough ,choose the high quality
            # if the buffer is danger, choose the low  quality
            # if there is no rebuf ,choose the low target_buffer
            th_list, buffer, cdn_count, prediction_bitrate, segment_rate, ave_th, curr_th, next_sg_rate = abr_return.run(
                time, S_time_interval, S_send_data_size, S_chunk_len, S_rebuf,
                S_buffer_size, S_play_time_len, S_end_delay, S_decision_flag,
                S_buffer_flag, S_cdn_flag, end_of_video, cdn_newest_id,
                download_id, cdn_has_frame, abr_init)
            bit_rate, target_buffer = abr.run(
                time, S_time_interval, S_send_data_size, S_chunk_len, S_rebuf,
                S_buffer_size, S_play_time_len, S_end_delay, S_decision_flag,
                S_buffer_flag, S_cdn_flag, end_of_video, cdn_newest_id,
                download_id, cdn_has_frame, abr_init)
            last_segment_info = ll_segment_info + [
                last_segment_reward, reward_temp_1, reward_temp_2,
                reward_temp_3, reward_temp_4
            ]
            #print(end_delay,cdn_newest_id,download_id)
            wr.append(last_segment_info)
            #bit_rate = int(action_name)
            ll_segment_info = [
                time, prediction_bitrate, next_sg_rate, segment_rate,
                cdn_has_frame, ave_th, curr_th, th_list[0], th_list[1],
                th_list[2], th_list[3], th_list[4], buffer,
                end_delay - buffer + 0.04, buffer_flag, cdn_flag, cdn_count,
                end_delay, cdn_newest_id, download_id, bit_rate
            ]
            last_segment_reward = 0

            # ------------------------------------------- End  -------------------------------------------

        if end_of_video:
            q_table.to_csv('qtable.csv')
            print("video count", video_count, reward_all, reward_all_1,
                  reward_all_2, reward_all_3, reward_all_4)
            reward_all_sum += reward_all / 1000
            video_count += 1
            if video_count >= 1:  #len(all_file_names):
                break
            cnt = 0
            last_bit_rate = 0
            reward_all = 0
            reward_all_1, reward_all_2, reward_all_3, reward_all_4 = 0, 0, 0, 0
            bit_rate = 0
            target_buffer = 0

            S_time_interval = [0] * past_frame_num
            S_send_data_size = [0] * past_frame_num
            S_chunk_len = [0] * past_frame_num
            S_rebuf = [0] * past_frame_num
            S_buffer_size = [0] * past_frame_num
            S_end_delay = [0] * past_frame_num
            S_chunk_size = [0] * past_frame_num
            S_play_time_len = [0] * past_frame_num
            S_decision_flag = [0] * past_frame_num
            S_buffer_flag = [0] * past_frame_num
            S_cdn_flag = [0] * past_frame_num

        reward_all += reward_frame
        last_segment_reward += reward_frame
        reward_all_1 += reward_1
        reward_all_2 += reward_2
        reward_all_3 += reward_3
        reward_all_4 += reward_4

    with open('MPC_train.csv', 'w',
              newline='') as f:  # 如果不指定newline='',则每写入一行将有一空行被写入
        writer = csv.writer(f)
        writer.writerows(wr)
    """ with open('debug.csv', 'w', newline='') as d:   # 如果不指定newline='',则每写入一行将有一空行被写入
        writer = csv.writer(d)
        writer.writerows(debug_list) """
    return reward_all_sum
コード例 #4
0
def test(user_id):
    #TRAIN_TRACES = '/home/game/test_sim_traces/'   #train trace path setting,
    #video_size_file = '/home/game/video_size_'      #video trace path setting,
    #LogFile_Path = "/home/game/log/"                #log file trace path setting,

    TRAIN_TRACES = './network_trace_2/'  #train trace path setting,
    #video_size_file = './video_trace/AsianCup_China_Uzbekistan/frame_trace_'      #video trace path setting,
    #video_size_file = './video_trace/Fengtimo_2018_11_3/frame_trace_'      #video trace path setting,
    #video_size_file = './video_trace/YYF_2018_08_12/frame_trace_'      #video trace path setting,

    #video_size_file = './video_trace_2/game/frame_trace_'
    video_size_file = './video_trace_2/room/frame_trace_'
    #video_size_file = './video_trace_2/sports/frame_trace_'

    #video_size_file = './video_trace_3/game_1/frame_trace_'
    #video_size_file = './video_trace_3/room_5/frame_trace_'
    #video_size_file = './video_trace_3/sports_4/frame_trace_'

    LogFile_Path = "./log/"  #log file trace path setting,
    # Debug Mode: if True, You can see the debug info in the logfile
    #             if False, no log ,but the training speed is high
    DEBUG = False
    # load the trace
    all_cooked_time, all_cooked_bw, all_file_names = load_trace.load_trace(
        TRAIN_TRACES)
    #random_seed
    random_seed = 2
    count = 0
    video_count = 0
    FPS = 25
    frame_time_len = 0.04
    reward_all_sum = 0
    #init
    #setting one:
    #     1,all_cooked_time : timestamp
    #     2,all_cooked_bw   : throughput
    #     3,all_cooked_rtt  : rtt
    #     4,agent_id        : random_seed
    #     5,logfile_path    : logfile_path
    #     6,VIDEO_SIZE_FILE : Video Size File Path
    #     7,Debug Setting   : Debug
    net_env = fixed_env.Environment(all_cooked_time=all_cooked_time,
                                    all_cooked_bw=all_cooked_bw,
                                    random_seed=random_seed,
                                    logfile_path=LogFile_Path,
                                    VIDEO_SIZE_FILE=video_size_file,
                                    Debug=DEBUG)

    abr = ABR.Algorithm()
    abr_init = abr.Initial()

    BIT_RATE = [500.0, 850.0, 1200.0, 1850.0]  # kpbs
    TARGET_BUFFER = [2.0, 3.0]  # seconds
    # ABR setting
    RESEVOIR = 0.5
    CUSHION = 2

    cnt = 0
    # defalut setting
    last_bit_rate = 0
    bit_rate = 0
    target_buffer = 0

    # QOE setting
    reward_frame = 0
    reward_all = 0
    SMOOTH_PENALTY = 0.02
    REBUF_PENALTY = 1.5
    LANTENCY_PENALTY = 0.005
    # past_info setting
    past_frame_num = 7500
    S_time_interval = [0] * past_frame_num
    S_send_data_size = [0] * past_frame_num
    S_chunk_len = [0] * past_frame_num
    S_rebuf = [0] * past_frame_num
    S_buffer_size = [0] * past_frame_num
    S_end_delay = [0] * past_frame_num
    S_chunk_size = [0] * past_frame_num
    S_play_time_len = [0] * past_frame_num
    S_decision_flag = [0] * past_frame_num
    S_buffer_flag = [0] * past_frame_num
    S_cdn_flag = [0] * past_frame_num
    # params setting

    while True:
        reward_frame = 0
        # input the train steps
        #if cnt > 5000:
        #plt.ioff()
        #    break
        #actions bit_rate  target_buffer
        # every steps to call the environment
        # time           : physical time
        # time_interval  : time duration in this step
        # send_data_size : download frame data size in this step
        # chunk_len      : frame time len
        # rebuf          : rebuf time in this step
        # buffer_size    : current client buffer_size in this step
        # rtt            : current buffer  in this step
        # play_time_len  : played time len  in this step
        # end_delay      : end to end latency which means the (upload end timestamp - play end timestamp)
        # decision_flag  : Only in decision_flag is True ,you can choose the new actions, other time can't Becasuse the Gop is consist by the I frame and P frame. Only in I frame you can skip your frame
        # buffer_flag    : If the True which means the video is rebuffing , client buffer is rebuffing, no play the video
        # cdn_flag       : If the True cdn has no frame to get
        # end_of_video   : If the True ,which means the video is over.
        time,time_interval, send_data_size, chunk_len,\
               rebuf, buffer_size, play_time_len,end_delay,\
                cdn_newest_id, download_id, cdn_has_frame, decision_flag,\
                buffer_flag, cdn_flag, end_of_video = net_env.get_video_frame(bit_rate,target_buffer)

        # S_info is sequential order
        S_time_interval.pop(0)
        S_send_data_size.pop(0)
        S_chunk_len.pop(0)
        S_buffer_size.pop(0)
        S_rebuf.pop(0)
        S_end_delay.pop(0)
        S_play_time_len.pop(0)
        S_decision_flag.pop(0)
        S_buffer_flag.pop(0)
        S_cdn_flag.pop(0)

        S_time_interval.append(time_interval)
        S_send_data_size.append(send_data_size)
        S_chunk_len.append(chunk_len)
        S_buffer_size.append(buffer_size)
        S_rebuf.append(rebuf)
        S_end_delay.append(end_delay)
        S_play_time_len.append(play_time_len)
        S_decision_flag.append(decision_flag)
        S_buffer_flag.append(buffer_flag)
        S_cdn_flag.append(cdn_flag)

        # QOE setting
        if not cdn_flag:
            reward_frame = frame_time_len * float(
                BIT_RATE[bit_rate]
            ) / 1000 - REBUF_PENALTY * rebuf - LANTENCY_PENALTY * end_delay
        else:
            reward_frame = -(REBUF_PENALTY * rebuf)
        if decision_flag or end_of_video:
            # reward formate = play_time * BIT_RATE - 4.3 * rebuf - 1.2 * end_delay
            reward_frame += -1 * SMOOTH_PENALTY * (
                abs(BIT_RATE[bit_rate] - BIT_RATE[last_bit_rate]) / 1000)
            # last_bit_rate
            last_bit_rate = bit_rate

            # -------------------------------------------Your Althgrithom -------------------------------------------
            # which part is the althgrothm part ,the buffer based ,
            # if the buffer is enough ,choose the high quality
            # if the buffer is danger, choose the low  quality
            # if there is no rebuf ,choose the low target_buffer
            bit_rate, target_buffer = abr.run(
                time, S_time_interval, S_send_data_size, S_chunk_len, S_rebuf,
                S_buffer_size, S_play_time_len, S_end_delay, S_decision_flag,
                S_buffer_flag, S_cdn_flag, end_of_video, cdn_newest_id,
                download_id, cdn_has_frame, abr_init)
            #print(bit_rate,time)
            # ------------------------------------------- End  -------------------------------------------

        if end_of_video:
            print("video count", video_count, reward_all)
            reward_all_sum += reward_all / 1000
            video_count += 1
            if video_count >= len(all_file_names):
                break
            cnt = 0
            last_bit_rate = 0
            reward_all = 0
            bit_rate = 0
            target_buffer = 0

            S_time_interval = [0] * past_frame_num
            S_send_data_size = [0] * past_frame_num
            S_chunk_len = [0] * past_frame_num
            S_rebuf = [0] * past_frame_num
            S_buffer_size = [0] * past_frame_num
            S_end_delay = [0] * past_frame_num
            S_chunk_size = [0] * past_frame_num
            S_play_time_len = [0] * past_frame_num
            S_decision_flag = [0] * past_frame_num
            S_buffer_flag = [0] * past_frame_num
            S_cdn_flag = [0] * past_frame_num

        reward_all += reward_frame

    return reward_all_sum
コード例 #5
0
import json
import pickle

# In[ ]:
#creating a dataframe for maternal mortality rates by country from the WHO data set 'MDG_0000000026'
# values are per 100,000 women
import MatMorRat
MatMorR = MatMorRat.getMMR()
indexed_MatMorR = MatMorR.set_index(['ISO'])
print indexed_MatMorR.head()

# In[42]:
# Creating a dataframe for the adolescent birth rates by country from the WHO data set 'MDG_0000000003'
# values are per 1000 women
import ABR
AdolBR = ABR.getABR()
indexed_AdolBR = AdolBR.set_index(['ISO'])
print indexed_AdolBR.head()

# In[ ]:

# creating a dataframe for Abortion policy from CSV file. Data obtained from this PDF: https://www.reproductiverights.org/sites/crr.civicactions.net/files/documents/AbortionMap_Factsheet_2013.pdf
# scale: 0 (abortion crimminalized, no abortions even to save the mothers life) to 6 (very few enforced restrictions during the entire length of the pregnancy)
import AbortScale
ABScale = AbortScale.getABS()
indexed_ABScale = ABScale.set_index(['ISO'])
print indexed_ABScale.head()

# In[ ]:

# Creating a data frame of life expextancy at birth in WHO countries from WHO data set 'WHOSIS_000001'
コード例 #6
0
ファイル: makeChart.py プロジェクト: udayragakiran/PyCMP
# dataDir = QtGui.QFileDialog.getExistingDirectory (None, caption, directory)
filterStr = ('*.pickle')
# fileList = QtGui.QFileDialog.getOpenFileNames (None, caption, directory, filterStr)
filepath = QtGui.QFileDialog.getOpenFileName(None, caption, dataDir, filterStr)

(dataDir, fileName) = os.path.split(filepath)

r = re.split(' ', fileName)
fileType = r[0]
number = r[1]
print('fileType=', fileType)

# filepath = os.path.join(dataDir, fileName)
print('loading ', filepath)

f = open(filepath, 'rb')
data = pickle.load(f)
f.close()

d = datetime.datetime.now()
timeStr = d.strftime('%Y-%m-%d %H_%M_%S')

if fileType == 'ABR':
    plotName = 'ABR %s %s' % (number, data.note)
    print('saving figure ', plotName)
    
    ABR.saveABRDataFig(data, data.params, dataDir, plotName, timeStr)
    

コード例 #7
0
def test():
    TRAIN_TRACES = '/home/game/test_sim_traces/'  #train trace path setting,
    video_size_file = '/home/game/video_size_'  #video trace path setting,
    LogFile_Path = "/home/game/log/"  #log file trace path setting,
    # Debug Mode: if True, You can see the debug info in the logfile
    #             if False, no log ,but the training speed is high
    DEBUG = True
    DRAW = True
    # load the trace
    all_cooked_time, all_cooked_bw, all_cooked_rtt, _ = load_trace.load_trace(
        TRAIN_TRACES)
    #random_seed
    random_seed = 2
    #init the environment
    #setting one:
    #     1,all_cooked_time : timestamp
    #     2,all_cooked_bw   : throughput
    #     3,all_cooked_rtt  : rtt
    #     4,agent_id        : random_seed
    #     5,logfile_path    : logfile_path
    #     6,VIDEO_SIZE_FILE : Video Size File Path
    #     7,Debug Setting   : Debug
    net_env = env.Environment(all_cooked_time=all_cooked_time,
                              all_cooked_bw=all_cooked_bw,
                              all_cooked_rtt=all_cooked_rtt,
                              random_seed=random_seed,
                              logfile_path=LogFile_Path,
                              VIDEO_SIZE_FILE=video_size_file,
                              Debug=DEBUG)

    cnt = 0
    S_time_interval = []
    S_send_data_size = []
    S_chunk_len = []
    S_rebuf = []
    S_buffer_size = []
    S_end_delay = []
    S_chunk_size = []
    S_rtt = []
    S_play_time = []
    BIT_RATE = [500, 800]  # kpbs
    TARGET_BUFFER = [2, 3]  # seconds
    RESEVOIR = 0.5
    CUSHION = 2
    last_bit_rate = 0
    reward_all = 0
    bit_rate = 0
    target_buffer = 0
    # plot info
    idx = 0
    id_list = []
    bit_rate_record = []
    buffer_record = []
    throughput_record = []
    # plot the real time image
    #if DRAW:
    #    fig = plt.figure()
    #    plt.ion()
    #    plt.xlabel("time")
    #    plt.axis('off')

    while True:
        # input the train steps
        if cnt > 500:
            #plt.ioff()
            break
        #actions bit_rate  target_buffer
        # every steps to call the environment
        # time           : physical time
        # time_interval  : time duration in this step
        # send_data_size : download frame data size in this step
        # chunk_len      : frame time len
        # rebuf          : rebuf time in this step
        # buffer_size    : current client buffer_size in this step
        # rtt            : current buffer  in this step
        # play_time_len  : played time len  in this step
        # end_delay      : end to end latency which means the (upload end timestamp - play end timestamp)
        # decision_flag  : Only in decision_flag is True ,you can choose the new actions, other time can't Becasuse the Gop is consist by the I frame and P frame. Only in I frame you can skip your frame
        # buffer_flag    : If the True which means the video is rebuffing , client buffer is rebuffing, no play the video
        # cdn_flag       : If the True cdn has no frame to get
        # end_of_video   : If the True ,which means the video is over.
        time, time_interval, send_data_size, chunk_len, rebuf, buffer_size, rtt, play_time_len, end_delay, decision_flag, buffer_flag, cdn_flag, end_of_video = net_env.get_video_frame(
            bit_rate, TARGET_BUFFER[target_buffer])
        cnt += 1
        if time_interval != 0:
            # plot bit_rate
            id_list.append(idx)
            idx += time_interval
            bit_rate_record.append(BIT_RATE[bit_rate])
            # plot buffer
            buffer_record.append(buffer_size)
            # plot throughput
            trace_idx = net_env.get_trace_id()
            throughput_record.append(all_cooked_bw[trace_idx][int(idx / 0.5)] *
                                     1000)

        if decision_flag:
            # reward formate = play_time * BIT_RATE - 4.3 * rebuf - 1.2 * end_delay
            reward = sum(S_play_time) * BIT_RATE[bit_rate] - 0.8 * sum(
                S_rebuf) - 0.2 * (end_delay - 3) - abs(BIT_RATE[bit_rate] -
                                                       BIT_RATE[last_bit_rate])
            reward_all += reward

            # last_bit_rate
            last_bit_rate = bit_rate

            # draw setting
            #if DRAW:
            #    ax = fig.add_subplot(311)
            #    plt.ylabel("BIT_RATE")
            #    plt.ylim(300,1000)
            #    plt.plot(id_list,bit_rate_record,'-r')

            #    ax = fig.add_subplot(312)
            #    plt.ylabel("Buffer_size")
            #    plt.ylim(0,7)
            #    plt.plot(id_list,buffer_record,'-b')

            #   ax = fig.add_subplot(313)
            #    plt.ylabel("throughput")
            #    plt.ylim(0,2500)
            #    plt.plot(id_list,throughput_record,'-g')

            #   plt.draw()
            #    plt.pause(0.01)

            # -------------------------------------------Your Althgrithom -------------------------------------------
            # which part is the althgrothm part ,the buffer based ,
            # if the buffer is enough ,choose the high quality
            # if the buffer is danger, choose the low  quality
            # if there is no rebuf ,choose the low target_buffer
            bit_rate, target_buffer = ABR.algorithm(time, time_interval,
                                                    send_data_size, chunk_len,
                                                    rebuf, buffer_size, rtt,
                                                    play_time_len, end_delay,
                                                    decision_flag, buffer_flag,
                                                    cdn_flag, end_of_video)

            # ------------------------------------------- End  -------------------------------------------

            S_time_interval = []
            S_send_data_size = []
            S_chunk_len = []
            S_rebuf = []
            S_buffer_size = []
            S_end_delay = []
            S_rtt = []
            S_play_time = []
            S_chunk_size = []

        S_time_interval.append(time_interval)
        S_send_data_size.append(send_data_size)
        S_chunk_len.append(chunk_len)
        S_buffer_size.append(buffer_size)
        S_rebuf.append(rebuf)
        S_end_delay.append(end_delay)
        S_rtt.append(rtt)
        S_play_time.append(play_time_len)

        # output
    #if DRAW:
    #    plt.show()
    return reward_all
コード例 #8
0
app = QtGui.QApplication(sys.argv)

# dataDir = QtGui.QFileDialog.getExistingDirectory (None, caption, directory)
filterStr = ('*.pickle')
# fileList = QtGui.QFileDialog.getOpenFileNames (None, caption, directory, filterStr)
filepath = QtGui.QFileDialog.getOpenFileName(None, caption, dataDir, filterStr)

(dataDir, fileName) = os.path.split(filepath)

r = re.split(' ', fileName)
fileType = r[0]
number = r[1]
print('fileType=', fileType)

# filepath = os.path.join(dataDir, fileName)
print('loading ', filepath)

f = open(filepath, 'rb')
data = pickle.load(f)
f.close()

d = datetime.datetime.now()
timeStr = d.strftime('%Y-%m-%d %H_%M_%S')

if fileType == 'ABR':
    plotName = 'ABR %s %s' % (number, data.note)
    print('saving figure ', plotName)

    ABR.saveABRDataFig(data, data.params, dataDir, plotName, timeStr)
コード例 #9
0
ファイル: partiel.py プロジェクト: Guennator/algo-epita
        k = k - 1
        if k == 0 or Found:
            A = B
            return (A, 0, True)
        else:
            B.right, k, Found = __nthBST(B.right, k, Found)
    return (B, k, Found)


def nthBST(B, k):
    if B == None:
        return None
    else:
        A, k, Found = __nthBST(B, k, False)
        return A


L = [
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 31, 32, 33, 34, 35, 36, 37, 38, 39, 66, 67,
    68, 69, 70
]
print("L ", L)
B = ABR.Build_balanced_abr(L)
print("list tree ", L)
print("tree B")
bintree.print_tree(B)
A = copywithsize(B)
bintree.print_tree(A)
C = nthBST(A, 3)
print(C.key)
コード例 #10
0
 def ABR_calClick(self):
     if not self.isCollecting:
         ABR.calibrateClick(self)
     else:
         self.doneFlag = True
コード例 #11
0
 def runABRclicked(self):
     if not self.isCollecting:
         ABR.runABR(self)
     else:
         self.doneFlag = True
コード例 #12
0
def testInsertABR(testInsertStart):
    elements = testInsertStart[0]
    rangeElements = testInsertStart[1]

    heightABR = []
    timerABR = []
    resultTimerRandomABR = []

    elementsOrderedABR = (10, 50, 1000, 3000)
    resultTimerOrderedABR = []

    print "\n", "=" * 100
    print "First array: heights of Binary Search Trees for random elements."
    print "Second array: time to insert a larger element than any other already in the tree."
    print "Columns: ranges [30, 1500, 1000000000]. "
    print "Lines: elements [10, 50, 1000, 10000, 50000]"
    print "=" * 100, "\n"

    for p in elements:
        for i in rangeElements:
            ABRtree = ABR.BinarySearchTree()
            for j in range(p):
                ABRtree.insert(random.randint(0, i))

            heightABR.append(ABRtree.getHeight(ABRtree.root))

            start = timer()
            ABRtree.insert(i + 1)
            end = timer()
            timerABR.append(end - start)

        resultTimerRandomABR.append(timerABR)
        print heightABR
        print timerABR
        print
        heightABR = []

    print "\n", "=" * 100
    print "First array: heights of Binary Search Tree for ordered elements."
    print "Second array: time to insert a larger element than any other already in the tree."
    print "Elements: [10, 50, 1000, 3000]"
    print "=" * 100, "\n"

    for p in elementsOrderedABR:
        ABRtree = ABR.BinarySearchTree()
        for j in range(p):
            ABRtree.insert(j)

        heightABR.append(ABRtree.getHeight(ABRtree.root))

        start = timer()
        ABRtree.insert(p + 1)
        end = timer()

        resultTimerOrderedABR.append(end - start)

    print heightABR
    print resultTimerOrderedABR
    print

    return resultTimerRandomABR, resultTimerOrderedABR
コード例 #13
0
ファイル: online.py プロジェクト: L3VTP/L3VTP
def test(user_id):
    # path setting
    TRAIN_TRACES = './network_trace/'   #train trace path setting,
    #video_size_file = './video_trace/AsianCup_China_Uzbekistan/frame_trace_'      #video trace path setting,
    video_size_file = './video_trace/frame_trace_'      #video trace path setting,
    LogFile_Path = "./log/"                #log file trace path setting,
    # Debug Mode: if True, You can see the debug info in the logfile
    #             if False, no log ,but the training speed is high
    DEBUG = False
    DRAW = False
    # load the trace
    all_cooked_time, all_cooked_bw, all_file_names = load_trace.load_trace(TRAIN_TRACES)
    #random_seed 
    random_seed = 2
    video_count = 0
    #FPS = 25
    frame_time_len = 0.04
    reward_all_sum = 0
    #init the environment
    #setting one:
    #     1,all_cooked_time : timestamp
    #     2,all_cooked_bw   : throughput
    #     3,all_cooked_rtt  : rtt
    #     4,agent_id        : random_seed
    #     5,logfile_path    : logfile_path
    #     6,VIDEO_SIZE_FILE : Video Size File Path
    #     7,Debug Setting   : Debug
    net_env = env.Environment(all_cooked_time=all_cooked_time,
    			  all_cooked_bw=all_cooked_bw,
    			  random_seed=random_seed,
    			  logfile_path=LogFile_Path,
    			  VIDEO_SIZE_FILE=video_size_file,
    			  Debug = DEBUG)
    BIT_RATE      = [500.0,1200.0] # kpbs
    # ABR setting
    CUSHION  = 2
    
    cnt = 0
    # defalut setting
    last_bit_rate = 0
    bit_rate = 0
    target_buffer = 1.5
    # QOE setting
    reward_frame = 0
    reward_all = 0
    SMOOTH_PENALTY= 0.02 
    REBUF_PENALTY = 1.5 
    LANTENCY_PENALTY = 0.005 
    
    call_cnt = 0
    call_time = 0
    switch_num = 0
    
    S_time_interval = []
    S_send_data_size = []
    S_frame_type = []
    S_frame_time_len = []
    S_buffer_size = []
    S_end_delay = []
    cdn_has_frame = []
    S_real_quality = []
    rebuf_time = 0
    buffer_flag = 0
    cdn_flag=0
    
    abr = ABR.Algorithm()
    abr.Initial()
    
    while True:
        reward_frame = 0
        # input the train steps
        #if cnt > 1200:
            #plt.ioff()
        #    break
        #actions bit_rate  target_buffer
        # every steps to call the environment
        # time           : physical time 
        # time_interval  : time duration in this step
        # send_data_size : download frame data size in this step
        # chunk_len      : frame time len
        # rebuf          : rebuf time in this step          
        # buffer_size    : current client buffer_size in this step          
        # rtt            : current buffer  in this step          
        # play_time_len  : played time len  in this step          
        # end_delay      : end to end latency which means the (upload end timestamp - play end timestamp)
        # decision_flag  : Only in decision_flag is True ,you can choose the new actions, other time can't Becasuse the Gop is consist by the I frame and P frame. Only in I frame you can skip your frame
        # buffer_flag    : If the True which means the video is rebuffing , client buffer is rebuffing, no play the video
        # cdn_flag       : If the True cdn has no frame to get 
        # end_of_video   : If the True ,which means the video is over.
        time, time_interval, send_data_size, frame_time_len, rebuf, buffer_size, end_delay, cdn_newest_id, downlaod_id, cdn_has_frame, decision_flag, real_quality,buffer_flag,switch,cdn_flag, end_of_video = net_env.get_video_frame(bit_rate,target_buffer)
        cnt += 1
        call_time += time_interval
        switch_num += switch

        S_time_interval.append(time_interval)
        S_buffer_size.append(buffer_size)
        S_send_data_size.append(send_data_size)
        S_frame_time_len.append(frame_time_len)
        S_end_delay.append(end_delay)
        S_real_quality.append(BIT_RATE[real_quality])
        if decision_flag:
            S_frame_type.append(1)
        else:
            S_frame_type.append(0)
        rebuf_time += rebuf

        if not cdn_flag:
            reward_frame = frame_time_len * float(BIT_RATE[bit_rate]) / 1000  - REBUF_PENALTY * rebuf - LANTENCY_PENALTY * end_delay
        else:
            reward_frame = -(REBUF_PENALTY * rebuf)
        if call_time > 0.5 and not end_of_video:
            reward_frame += -(switch_num) * SMOOTH_PENALTY * (1200 - 500) / 1000

            time_start = time_package.time() 
            bit_rate , target_buffer = abr.run(S_time_interval, S_send_data_size,S_frame_time_len,S_frame_type,S_real_quality,S_buffer_size,S_end_delay,\
                                      rebuf_time, cdn_has_frame, cdn_flag, buffer_flag)
            time_end = time_package.time()
            if time_end - time_start > 0.05:
                print("Warning Your decision is time out,This decision is default decision")
                bit_rate = 0
                target_buffer = 1.5
            call_time = 0
            switch_num = 0
            call_cnt += 1

            S_time_interval= []
            S_send_data_size = []
            S_frame_type = []
            S_frame_time_len = []
            S_buffer_size = []
            S_end_delay = []
            S_real_quality = []
            rebuf_time = 0

        # --`----------------------------------------- End  ------------------------------------------- 

        reward_all += reward_frame
        if end_of_video:
            # Narrow the range of results
            print("video count", video_count, reward_all)
            reward_all_sum += reward_all / 100
            video_count += 1
            if video_count >= len(all_file_names):
                break
            cnt = 0
            reward_all = 0
            last_bit_rate = 0
            bit_rate = 0
            target_buffer = 1.5

            S_time_interval = []
            S_send_data_size = []
            S_frame_type = []
            S_frame_time_len = []
            S_buffer_size = []
            S_end_delay = []
            S_real_quality = []
            cdn_has_frame = []
            rebuf_time = 0
            buffer_flag = 0
            cdn_flag=0

            call_cnt = 0
            call_time = 0
            switch_num = 0
    return reward_all_sum
コード例 #14
0
            timeStr = data.timeStamp
            ws = CMPCommon.initExcelSpreadsheet(wb, name, number, timeStr,
                                                data.note)
            CM.saveCMDataXLS(data, data.trialDuration, data.trialReps, ws,
                             saveOpts)
        elif name == 'DPOAE':
            saveOpts.saveMicData = data.mic_data is not None
            saveOpts.saveMicFFT = data.mic_fft_mag is not None

            timeStr = data.timeStamp
            ws = CMPCommon.initExcelSpreadsheet(wb, name, number, timeStr,
                                                data.note)
            DPOAE.saveDPOAEDataXLS(data, data.trialDuration, ws, saveOpts)
        elif name == 'ABR':
            saveOpts.saveTracings = data.tracings is not None

            ABRparams = data.params

            timeStr = data.timeStamp
            ws = CMPCommon.initExcelSpreadsheet(wb, name, number, timeStr,
                                                data.note)
            ABR.saveABRDataXLS(data, ABRparams, ws, saveOpts)
        #print(data.__dict__)
    except Exception as ex:
        traceback.print_exc(file=sys.stdout)

print('closing workbook')
wb.close()
print('done')
コード例 #15
0
ファイル: PyCMP.py プロジェクト: udayragakiran/PyCMP
 def runABRclicked(self):
     if not self.isCollecting:
         ABR.runABR(self)
     else:
         self.doneFlag = True
コード例 #16
0
def test(user_id):

    # -- Configuration variables --
    # Edit these variables to configure the simulator

    # Change which set of network trace to use: 'fixed' 'low' 'medium' 'high'
    NETWORK_TRACE = 'fixed'

    # Change which set of video trace to use.
    VIDEO_TRACE = 'AsianCup_China_Uzbekistan'

    # Turn on and off logging.  Set to 'True' to create log files.
    # Set to 'False' would speed up the simulator.
    DEBUG = True

    # Control the subdirectory where log files will be stored.
    LOG_FILE_PATH = './log/'

    # -- End Configuration --
    # You shouldn't need to change the rest of the code here.

    network_trace_dir = './dataset/network_trace/' + NETWORK_TRACE + '/'
    video_trace_prefix = './dataset/video_trace/' + VIDEO_TRACE + '/frame_trace_'

    # load the trace
    all_cooked_time, all_cooked_bw, all_file_names = load_trace.load_trace(
        network_trace_dir)
    #random_seed
    random_seed = 2
    count = 0
    trace_count = 1
    FPS = 25
    frame_time_len = 0.04
    reward_all_sum = 0
    run_time = 0
    #init
    #setting one:
    #     1,all_cooked_time : timestamp
    #     2,all_cooked_bw   : throughput
    #     3,all_cooked_rtt  : rtt
    #     4,agent_id        : random_seed
    #     5,logfile_path    : logfile_path
    #     6,VIDEO_SIZE_FILE : Video Size File Path
    #     7,Debug Setting   : Debug
    net_env = fixed_env.Environment(all_cooked_time=all_cooked_time,
                                    all_cooked_bw=all_cooked_bw,
                                    random_seed=random_seed,
                                    logfile_path=LOG_FILE_PATH,
                                    VIDEO_SIZE_FILE=video_trace_prefix,
                                    Debug=DEBUG)

    abr = ABR.Algorithm()
    abr_init = abr.Initial()

    BIT_RATE = [500.0, 850.0, 1200.0, 1850.0]  # kpbs
    TARGET_BUFFER = [2.0, 3.0]  # seconds
    # ABR setting
    RESEVOIR = 0.5
    CUSHION = 2

    cnt = 0
    # defalut setting
    last_bit_rate = 0
    bit_rate = 0
    target_buffer = 0
    latency_limit = 7
    publish = 4

    # QOE setting
    reward_frame = 0
    reward_all = 0
    SMOOTH_PENALTY = 0.02
    REBUF_PENALTY = 1.5
    LANTENCY_PENALTY = 0.005
    SKIP_PENALTY = 0.5
    # past_info setting
    past_frame_num = 7500
    S_time_interval = [0] * past_frame_num
    S_send_data_size = [0] * past_frame_num
    S_chunk_len = [0] * past_frame_num
    S_rebuf = [0] * past_frame_num
    S_buffer_size = [0] * past_frame_num
    S_end_delay = [0] * past_frame_num
    S_chunk_size = [0] * past_frame_num
    S_play_time_len = [0] * past_frame_num
    S_decision_flag = [0] * past_frame_num
    S_buffer_flag = [0] * past_frame_num
    S_cdn_flag = [0] * past_frame_num
    # params setting
    call_time_sum = 0
    while True:
        reward_frame = 0
        # input the train steps
        #if cnt > 5000:
        #plt.ioff()
        #    break
        #actions bit_rate  target_buffer
        # every steps to call the environment
        # time           : physical time
        # time_interval  : time duration in this step
        # send_data_size : download frame data size in this step
        # chunk_len      : frame time len
        # rebuf          : rebuf time in this step
        # buffer_size    : current client buffer_size in this step
        # rtt            : current buffer  in this step
        # play_time_len  : played time len  in this step
        # end_delay      : end to end latency which means the (upload end timestamp - play end timestamp)
        # decision_flag  : Only in decision_flag is True ,you can choose the new actions, other time can't Becasuse the Gop is consist by the I frame and P frame. Only in I frame you can skip your frame
        # buffer_flag    : If the True which means the video is rebuffing , client buffer is rebuffing, no play the video
        # cdn_flag       : If the True cdn has no frame to get
        # end_of_video   : If the True ,which means the video is over.
        cnt += 1
        timestamp_start = tm.time()
        time,time_interval, send_data_size, chunk_len,\
               rebuf, buffer_size, play_time_len,end_delay,\
                cdn_newest_id, download_id, cdn_has_frame,skip_frame_time_len, decision_flag,\
                buffer_flag, cdn_flag, skip_flag,end_of_video = net_env.get_video_frame(bit_rate,target_buffer, latency_limit)
        timestamp_end = tm.time()
        call_time_sum += timestamp_end - timestamp_start
        # S_info is sequential order
        S_time_interval.pop(0)
        S_send_data_size.pop(0)
        S_chunk_len.pop(0)
        S_buffer_size.pop(0)
        S_rebuf.pop(0)
        S_end_delay.pop(0)
        S_play_time_len.pop(0)
        S_decision_flag.pop(0)
        S_buffer_flag.pop(0)
        S_cdn_flag.pop(0)

        S_time_interval.append(time_interval)
        S_send_data_size.append(send_data_size)
        S_chunk_len.append(chunk_len)
        S_buffer_size.append(buffer_size)
        S_rebuf.append(rebuf)
        S_end_delay.append(end_delay)
        S_play_time_len.append(play_time_len)
        S_decision_flag.append(decision_flag)
        S_buffer_flag.append(buffer_flag)
        S_cdn_flag.append(cdn_flag)

        # QOE setting
        if not cdn_flag:
            reward_frame = frame_time_len * float(
                BIT_RATE[bit_rate]
            ) / 1000 - REBUF_PENALTY * rebuf - LANTENCY_PENALTY * end_delay - SKIP_PENALTY * skip_frame_time_len
        else:
            reward_frame = -(REBUF_PENALTY * rebuf)
        if decision_flag or end_of_video:
            # reward formate = play_time * BIT_RATE - 4.3 * rebuf - 1.2 * end_delay
            reward_frame += -1 * SMOOTH_PENALTY * (
                abs(BIT_RATE[bit_rate] - BIT_RATE[last_bit_rate]) / 1000)
            # last_bit_rate
            last_bit_rate = bit_rate

            # ----------------- Your Algorithm ---------------------
            # which part is the algorithm part ,the buffer based ,
            # if the buffer is enough ,choose the high quality
            # if the buffer is danger, choose the low  quality
            # if there is no rebuf ,choose the low target_buffer
            bit_rate, target_buffer, latency_limit = abr.run(
                time, S_time_interval, S_send_data_size, S_chunk_len, S_rebuf,
                S_buffer_size, S_play_time_len, S_end_delay, S_decision_flag,
                S_buffer_flag, S_cdn_flag, end_of_video, cdn_newest_id,
                download_id, cdn_has_frame, abr_init)
            # -------------------- End --------------------------------

        if end_of_video:
            print("network traceID, network_reward, avg_call_time",
                  trace_count, reward_all, call_time_sum / cnt)
            reward_all_sum += reward_all
            run_time += call_time_sum / cnt
            trace_count += 1
            if trace_count > len(all_file_names):
                break
            cnt = 0
            call_time_sum = 0
            last_bit_rate = 0
            reward_all = 0
            bit_rate = 0
            target_buffer = 0

            S_time_interval = [0] * past_frame_num
            S_send_data_size = [0] * past_frame_num
            S_chunk_len = [0] * past_frame_num
            S_rebuf = [0] * past_frame_num
            S_buffer_size = [0] * past_frame_num
            S_end_delay = [0] * past_frame_num
            S_chunk_size = [0] * past_frame_num
            S_play_time_len = [0] * past_frame_num
            S_decision_flag = [0] * past_frame_num
            S_buffer_flag = [0] * past_frame_num
            S_cdn_flag = [0] * past_frame_num

        reward_all += reward_frame

    return [reward_all_sum / trace_count, run_time / trace_count]
コード例 #17
0
ファイル: PyCMP.py プロジェクト: udayragakiran/PyCMP
 def ABR_calClick(self):
     if not self.isCollecting:
         ABR.calibrateClick(self)
     else:
         self.doneFlag = True
コード例 #18
0
def test(user_id):

    # -- Configuration variables --
    # Edit these variables to configure the simulator

    # Change which set of network trace to use: 'fixed' 'low' 'medium' 'high'
    NETWORK_TRACE = 'fixed'

    # Change which set of video trace to use.
    VIDEO_TRACE = 'AsianCup_China_Uzbekistan'

    # Turn on and off logging.  Set to 'True' to create log files.
    # Set to 'False' would speed up the simulator.
    DEBUG = False

    # Control the subdirectory where log files will be stored.
    LOG_FILE_PATH = './log/'
    
    # create result directory
    if not os.path.exists(LOG_FILE_PATH):
        os.makedirs(LOG_FILE_PATH)

    # -- End Configuration --
    # You shouldn't need to change the rest of the code here.

    network_trace_dir = './dataset/network_trace/' + NETWORK_TRACE + '/'
    video_trace_prefix = './dataset/video_trace/' + VIDEO_TRACE + '/frame_trace_'

    # load the trace
    """每个文件中的cooked_time和cooked_bw形成一个列表,append到总列表中,网络时延的情况"""
    all_cooked_time, all_cooked_bw, all_file_names = load_trace.load_trace(network_trace_dir)
    # print(len(all_cooked_time))  # 20
    # print(len(all_cooked_time[0]))  # 5880
    # print(len(all_cooked_bw))
    # print(len(all_cooked_bw[0]))
    # print(all_file_names)
    # random_seed
    random_seed = 2
    count = 0
    trace_count = 1  # 正在计算的第几个视频
    FPS = 25
    frame_time_len = 0.04  # 帧速率
    reward_all_sum = 0  # 总奖励
    run_time = 0  # 运行时间
    #init 
    #setting one:
    #     1,all_cooked_time : timestamp
    #     2,all_cooked_bw   : throughput
    #     3,all_cooked_rtt  : rtt
    #     4,agent_id        : random_seed
    #     5,logfile_path    : logfile_path
    #     6,VIDEO_SIZE_FILE : Video Size File Path
    #     7,Debug Setting   : Debug
    net_env = fixed_env.Environment(all_cooked_time=all_cooked_time,
                                  all_cooked_bw=all_cooked_bw,
                                  random_seed=random_seed,
                                  logfile_path=LOG_FILE_PATH,
                                  VIDEO_SIZE_FILE=video_trace_prefix,
                                  Debug = DEBUG)  # 视频相关的环境初始化,把load的所有的网络的数据输进去
    # ctx = try_gpu(0)
    # input_sample = nd.ones((1,11),ctx,dtype=np.float32)
    abr = ABR.Algorithm() # 加载ABR算法
    abr_init = abr.Initial()

    BIT_RATE      = [500.0,850.0,1200.0,1850.0] # kpbs  码率可选择的范围,每一个码率对应的视频的信息数据对视不一样的
    TARGET_BUFFER = [0.5,1.0]   # seconds,目标可选择的buffer的大小
    # ABR setting
    RESEVOIR = 0.5  # ABR算法的配置,现在没有用
    CUSHION  = 2

    cnt = 0
    # defalut setting
    last_bit_rate = 0 # 上一帧的码率
    bit_rate = 0
    target_buffer = 0 # 目标buffer
    latency_limit = 4  # 延迟限制

    # QOE setting
    """
    比特率/帧速率−1.85∗拒绝−W1∗延迟−0.02∗交换机∗abs(比特率−最后一个比特率)−0.5∗跳过时间
    """
    reward_frame = 0
    reward_all = 0
    SMOOTH_PENALTY= 0.02  # 平滑惩罚系数
    REBUF_PENALTY = 1.85  # 重新加载缓冲区的惩罚系数 拒绝
    LANTENCY_PENALTY = 0.005
    SKIP_PENALTY = 0.5  # 跳帧惩罚系数
    # past_info setting
    past_frame_num  = 7500  # 已经过去的帧信息
    S_time_interval = [0] * past_frame_num  # 时间间隔
    S_send_data_size = [0] * past_frame_num  # 发送数据大小
    S_chunk_len = [0] * past_frame_num  #  块长度
    S_rebuf = [0] * past_frame_num  # 重新缓冲,拒绝,保证较少的拒绝事件
    S_buffer_size = [0] * past_frame_num  # 缓冲大小
    S_end_delay = [0] * past_frame_num  # 结束延迟
    S_chunk_size = [0] * past_frame_num  #
    S_play_time_len = [0] * past_frame_num  # 播放时间长度
    S_decision_flag = [0] * past_frame_num  # 决定的标志
    S_buffer_flag = [0] * past_frame_num  # buffer的标志
    S_cdn_flag = [0] * past_frame_num  # cdn的标志
    S_skip_time = [0] * past_frame_num  # 跳帧的时间
    # params setting
    call_time_sum = 0 
    while True:

        reward_frame = 0
        # input the train steps
        #if cnt > 5000:
            #plt.ioff()
        #    break
        #actions bit_rate  target_buffer
        # every steps to call the environment
        # time           : physical time 
        # time_interval  : time duration in this step
        # send_data_size : download frame data size in this step
        # chunk_len      : frame time len
        # rebuf          : rebuf time in this step          
        # buffer_size    : current client buffer_size in this step          
        # rtt            : current buffer  in this step          
        # play_time_len  : played time len  in this step          
        # end_delay      : end to end latency which means the (upload end timestamp - play end timestamp)
        # decision_flag  : Only in decision_flag is True ,you can choose the new actions, other time can't Becasuse the Gop is consist by the I frame and P frame. Only in I frame you can skip your frame
        # buffer_flag    : If the True which means the video is rebuffing , client buffer is rebuffing, no play the video
        # cdn_flag       : If the True cdn has no frame to get 
        # end_of_video   : If the True ,which means the video is over.
        time,time_interval, send_data_size, chunk_len,\
               rebuf, buffer_size, play_time_len,end_delay,\
                cdn_newest_id, download_id, cdn_has_frame,skip_frame_time_len, decision_flag,\
                buffer_flag, cdn_flag, skip_flag,end_of_video = net_env.get_video_frame(bit_rate,target_buffer, latency_limit)
        # 给环境输入码率、目标的缓冲区大小和延迟到的限制得到关于视频播放的信息
        # S_info is sequential order
        # 把之前列表中存储的关于视频播放的信息的数据更新掉
        S_time_interval.pop(0)
        S_send_data_size.pop(0)
        S_chunk_len.pop(0)
        S_buffer_size.pop(0)
        S_rebuf.pop(0)
        S_end_delay.pop(0)
        S_play_time_len.pop(0)
        S_decision_flag.pop(0)
        S_buffer_flag.pop(0)
        S_cdn_flag.pop(0)
        S_skip_time.pop(0)

        S_time_interval.append(time_interval)
        S_send_data_size.append(send_data_size)
        S_chunk_len.append(chunk_len)
        S_buffer_size.append(buffer_size)
        S_rebuf.append(rebuf)  # 拒绝
        S_end_delay.append(end_delay)
        S_play_time_len.append(play_time_len)
        S_decision_flag.append(decision_flag)
        S_buffer_flag.append(buffer_flag)
        S_cdn_flag.append(cdn_flag) 
        S_skip_time.append(skip_frame_time_len)

        # QOE setting
        # 结束延迟小于1的化,延迟的惩罚就为0.005,否则的化惩罚为0.01
        if end_delay <=1.0:
            LANTENCY_PENALTY = 0.005
        else:
            LANTENCY_PENALTY = 0.01
        # CDN flag是什么意思????为什么会影响reward的计算
        if not cdn_flag:
            reward_frame = frame_time_len * float(BIT_RATE[bit_rate]) / 1000  - REBUF_PENALTY * rebuf - LANTENCY_PENALTY  * end_delay - SKIP_PENALTY * skip_frame_time_len 
        else:
            reward_frame = -(REBUF_PENALTY * rebuf)
        if decision_flag or end_of_video:
            # 如果是决策帧,或者是视频结束的时候要将reward加上一个比特率与上一个比特率之间的差值
            # reward formate = play_time * BIT_RATE - 4.3 * rebuf - 1.2 * end_delay
            reward_frame += -1 * SMOOTH_PENALTY * (abs(BIT_RATE[bit_rate] - BIT_RATE[last_bit_rate]) / 1000)
            # last_bit_rate
            last_bit_rate = bit_rate

            # ----------------- Your Algorithm ---------------------
            # which part is the algorithm part ,the buffer based ,
            # 如果缓冲足够,选择高质量的块,如果缓冲不够,选择低质量的块,如果没有rebuf,选择低目标缓冲????
            # if the buffer is enough ,choose the high quality
            # if the buffer is danger, choose the low  quality
            # if there is no rebuf ,choose the low target_buffer
            cnt += 1
            timestamp_start = tm.time()
            # ABR算法运行根据当前时间和历史播放视频的情况输出码率、目标缓冲大小、延迟限制
            bit_rate, target_buffer, latency_limit = abr.run(time,
                    S_time_interval,
                    S_send_data_size,
                    S_chunk_len,
                    S_rebuf,
                    S_buffer_size, 
                    S_play_time_len,
                    S_end_delay,
                    S_decision_flag,
                    S_buffer_flag,
                    S_cdn_flag,
                    S_skip_time,
                    end_of_video, 
                    cdn_newest_id, 
                    download_id,
                    cdn_has_frame,
                    abr_init)
            # print(time)  # float
            # print(len(S_send_data_size))  # 7500
            # print(end_of_video) # boolean
            # print(cdn_newest_id) # int37836
            # print(download_id)  # int37799
            # print(len(cdn_has_frame))  # 5
            # print(len(cdn_has_frame[0]))  # 36,16,24,cdn_newest_id - download_id
            # print(abr_init)  # None
            timestamp_end = tm.time()
            # 算法的计算时间
            call_time_sum += timestamp_end - timestamp_start
            # -------------------- End --------------------------------
            
        if end_of_video:
            print("network traceID, network_reward, avg_running_time", trace_count, reward_all, call_time_sum/cnt)
            reward_all_sum += reward_all
            run_time += call_time_sum / cnt
            if trace_count >= len(all_file_names):  # 所有的视频都运行结束之后跳出循环
                break
            trace_count += 1
            cnt = 0
            
            call_time_sum = 0  # 整个视频的算法计算时间
            last_bit_rate = 0
            reward_all = 0
            bit_rate = 0
            target_buffer = 0

            S_time_interval = [0] * past_frame_num
            S_send_data_size = [0] * past_frame_num
            S_chunk_len = [0] * past_frame_num
            S_rebuf = [0] * past_frame_num
            S_buffer_size = [0] * past_frame_num
            S_end_delay = [0] * past_frame_num
            S_chunk_size = [0] * past_frame_num
            S_play_time_len = [0] * past_frame_num
            S_decision_flag = [0] * past_frame_num
            S_buffer_flag = [0] * past_frame_num
            S_cdn_flag = [0] * past_frame_num
            
        reward_all += reward_frame

    return [reward_all_sum / trace_count, run_time / trace_count]  # 平均奖励,平均运行时间
コード例 #19
0
ファイル: makeXLSdata.py プロジェクト: udayragakiran/PyCMP
            saveOpts.saveTracings = data.tracings is not None
                
            timeStr = data.timeStamp
            ws = CMPCommon.initExcelSpreadsheet(wb, name, number, timeStr, data.note)
            CM.saveCMDataXLS(data, data.trialDuration, data.trialReps, ws, saveOpts)
        elif name == 'DPOAE':
            saveOpts.saveMicData = data.mic_data is not None
            saveOpts.saveMicFFT = data.mic_fft_mag is not None
            
            timeStr = data.timeStamp
            ws = CMPCommon.initExcelSpreadsheet(wb, name, number, timeStr, data.note)
            DPOAE.saveDPOAEDataXLS(data, data.trialDuration, ws, saveOpts)
        elif name == 'ABR':
            saveOpts.saveTracings = data.tracings is not None
            
            ABRparams = data.params
            
            timeStr = data.timeStamp
            ws = CMPCommon.initExcelSpreadsheet(wb, name, number, timeStr, data.note)
            ABR.saveABRDataXLS(data, ABRparams, ws, saveOpts)
        #print(data.__dict__)
    except Exception as ex:
        traceback.print_exc(file=sys.stdout)
        
print('closing workbook')
wb.close()
print('done')
    
    

コード例 #20
0
ファイル: online.py プロジェクト: liulalala/LiveStreamingDemo
def test(user_id):
    #sys.path.append('/home/team/' + user_id + '/submit/')
    import ABR
    #TRAIN_TRACES = '/home/team/network_trace/'   #train trace path setting,
    TRAIN_TRACES = './network_trace/'  #train trace path setting,
    #video_size_file = '/home/team/video_trace/YYF_2018_08_12/frame_trace_'      #video trace path setting,
    video_size_file = './video_trace/Fengtimo_2018_11_3/frame_trace_'  #video trace path setting,
    LogFile_Path = "./log/"  #log file trace path setting,
    # Debug Mode: if True, You can see the debug info in the logfile
    #             if False, no log ,but the training speed is high
    DEBUG = True
    DRAW = True
    # load the trace
    all_cooked_time, all_cooked_bw, _ = load_trace.load_trace(TRAIN_TRACES)
    #random_seed
    random_seed = 2
    #init the environment
    #setting one:
    #     1,all_cooked_time : timestamp
    #     2,all_cooked_bw   : throughput
    #     3,all_cooked_rtt  : rtt
    #     4,agent_id        : random_seed
    #     5,logfile_path    : logfile_path
    #     6,VIDEO_SIZE_FILE : Video Size File Path
    #     7,Debug Setting   : Debug
    net_env = env.Environment(all_cooked_time=all_cooked_time,
                              all_cooked_bw=all_cooked_bw,
                              random_seed=random_seed,
                              logfile_path=LogFile_Path,
                              VIDEO_SIZE_FILE=video_size_file,
                              Debug=DEBUG)

    cnt = 0
    # intial indicator
    # give past 5 min info
    # 7500  * 0.04  =  5 * 60
    past_frame_num = 7500
    S_time_interval = [0] * past_frame_num
    S_send_data_size = [0] * past_frame_num
    S_chunk_len = [0] * past_frame_num
    S_rebuf = [0] * past_frame_num
    S_buffer_size = [0] * past_frame_num
    S_end_delay = [0] * past_frame_num
    S_chunk_size = [0] * past_frame_num
    S_play_time_len = [0] * past_frame_num
    S_decision_flag = [0] * past_frame_num
    S_buffer_flag = [0] * past_frame_num
    S_cdn_flag = [0] * past_frame_num

    BIT_RATE = [500, 850, 1200, 1850]  # kpbs
    TARGET_BUFFER = [2, 3]  # seconds

    last_bit_rate = 0
    reward_all = 0
    bit_rate = 0
    target_buffer = 0
    # plot info
    idx = 0
    id_list = []
    bit_rate_record = []
    buffer_record = []
    throughput_record = []
    # plot the real time image
    #if DRAW:
    #    fig = plt.figure()
    #    plt.ion()
    #    plt.xlabel("time")
    #    plt.axis('off')
    cycle_cnt = 0

    while True:
        # input the train steps
        #actions bit_rate  target_buffer
        # every steps to call the environment
        # time           : physical time
        # time_interval  : time duration in this step
        # send_data_size : download frame data size in this step
        # chunk_len      : frame time len
        # rebuf          : rebuf time in this step
        # buffer_size    : current client buffer_size in this step
        # rtt            : current buffer  in this step
        # play_time_len  : played time len  in this step
        # end_delay      : end to end latency which means the (upload end timestamp - play end timestamp)
        # decision_flag  : Only in decision_flag is True ,you can choose the new actions, other time can't Becasuse the Gop is consist by the I frame and P frame. Only in I frame you can skip your frame
        # buffer_flag    : If the True which means the video is rebuffing , client buffer is rebuffing, no play the video
        # cdn_flag       : If the True cdn has no frame to get
        # end_of_video   : If the True ,which means the video is over.
        time, time_interval, send_data_size, chunk_len, rebuf, buffer_size, play_time_len, end_delay, decision_flag, buffer_flag, cdn_flag, end_of_video = net_env.get_video_frame(
            bit_rate, target_buffer)
        cnt += 1
        # plot bit_rate
        id_list.append(idx)
        idx += time_interval
        bit_rate_record.append(BIT_RATE[bit_rate])
        # plot buffer
        buffer_record.append(buffer_size)
        # plot throughput
        trace_idx = net_env.get_trace_id()
        throughput_record.append(
            all_cooked_bw[trace_idx][int(idx / 0.5) %
                                     len(all_cooked_bw[trace_idx])] * 1000)

        # S_info is sequential order
        S_time_interval.pop(0)
        S_send_data_size.pop(0)
        S_chunk_len.pop(0)
        S_buffer_size.pop(0)
        S_rebuf.pop(0)
        S_end_delay.pop(0)
        S_play_time_len.pop(0)
        S_decision_flag.pop(0)
        S_buffer_flag.pop(0)
        S_cdn_flag.pop(0)

        S_time_interval.append(time_interval)
        S_send_data_size.append(send_data_size)
        S_chunk_len.append(chunk_len)
        S_buffer_size.append(buffer_size)
        S_rebuf.append(rebuf)
        S_end_delay.append(end_delay)
        S_play_time_len.append(play_time_len)
        S_decision_flag.append(decision_flag)
        S_buffer_flag.append(buffer_flag)
        S_cdn_flag.append(cdn_flag)

        cycle_cnt += 1
        params = []
        if decision_flag:
            # reward formate = play_time * BIT_RATE - 4.3 * rebuf - 1.2 * end_delay
            reward = (sum(S_play_time_len[-cycle_cnt:]) *
                      BIT_RATE[bit_rate]) / 1000 - 0.8 * sum(
                          S_rebuf[-cycle_cnt:]) - 0.2 * (end_delay - 3) - abs(
                              BIT_RATE[bit_rate] - BIT_RATE[last_bit_rate])
            reward_all += reward

            # last_bit_rate
            last_bit_rate = bit_rate
            cycle_cnt = 0

            # draw setting
            #if DRAW:
            #    ax = fig.add_subplot(311)
            #    plt.ylabel("BIT_RATE")
            #    plt.ylim(300,1000)
            #    plt.plot(id_list,bit_rate_record,'-r')

            #    ax = fig.add_subplot(312)
            #    plt.ylabel("Buffer_size")
            #    plt.ylim(0,7)
            #    plt.plot(id_list,buffer_record,'-b')

            #   ax = fig.add_subplot(313)
            #    plt.ylabel("throughput")
            #    plt.ylim(0,2500)
            #    plt.plot(id_list,throughput_record,'-g')

            #   plt.draw()
            #    plt.pause(0.01)

            # -------------------------------------------Your Algorithm -------------------------------------------
            # call your ABR
            bit_rate, target_buffer = ABR.algorithm(
                time, S_time_interval, S_send_data_size, S_chunk_len, S_rebuf,
                S_buffer_size, S_play_time_len, S_end_delay, S_decision_flag,
                S_buffer_flag, S_cdn_flag, end_of_video, params)

            # ------------------------------------------- End  -------------------------------------------
        if end_of_video:
            #plt.ioff()
            break

        # output
    #if DRAW:
    #    plt.show()
    return reward_all