Пример #1
0
def set_device_set_pri2(atcs: AllTimeCloudlets, cong_map: List[List[int]], t: int, devices: Devices,
                       x_len: int, y_len: int, scope: int):
    ds = list(filter(lambda d: d.is_poweron(t), devices))
    d_num = 0
    i=0
    for d in ds:
        app_name = d.app_name()
        app_num = [0,0,0]
        pos = d.get_pos(t)
        pts = near_points(pos, scope, Point(x_len - 1, y_len - 1), Point(0, 0))
        for p in pts:
            cloud = atcs[p.y][p.x][0]
            if cloud.is_operatable_application("1"):
                app_num[0] += 1
                i += 1
            if cloud.is_operatable_application("2"):
                app_num[1] += 1
                i += 1
            if cloud.is_operatable_application("3"):
                app_num[2] += 1
                i += 1

        max_len = [0,0,0]
        for i in range(0,3):
            max_len[i] = str(np.argmax(app_num) + 1)
            app_num[int(max_len[i]) - 1] = 0

        if app_name == max_len[2]:
            pri_num = int(cong_map[pos.y][pos.x] + 2)
        elif app_name == max_len[1]:
            pri_num = int(cong_map[pos.y][pos.x] + 1)
        else:
            pri_num = int(cong_map[pos.y][pos.x])
        #pri_num = app_num
        d.set_ds_pri(value=pri_num)
Пример #2
0
def simple_use_plan(kwargs) -> AllocationPlan:
    atcs = kwargs["atcs"]
    devices = kwargs["ds"]
    max_hop = kwargs["max_hop"]
    congestion_scope = kwargs["congestion_scope"]

    t_len = len(atcs)
    y_len = len(atcs[0])
    x_len = len(atcs[0][0])
    allocation_plan = create_blank_allocation_plan(atcs, devices)
    for time, cloudlets in enumerate(tqdm(atcs)):
        ds = list(filter(lambda d: d.is_poweron(time), devices))
        tempallocation = create_tempallocation(time, ds, max_hop)
        congestion_map = create_congestion_map(time, x_len, y_len, ds, congestion_scope, tempallocation)
        print_congestion(congestion_map, x_len, y_len)
        ds = sorted(ds, key=lambda d: congestion_map[tempallocation[d.name].y][tempallocation[d.name].x], reverse=True)
        for d in ds:
            pos = tempallocation[d.name]
            for hop in range(0, 30):
                nps = near_points(pos, hop, Point(x_len - 1, y_len - 1), Point(0, 0))
                nps = sorted(nps, key=lambda p: distance(p, d.get_pos(time)))
                tp, index = search(nps, True, key=lambda p: cloudlets[p.y][p.x].can_append_device(d))
                if index == -1:
                    continue
                allocate(d, time, tp, allocation_plan, cloudlets)
                break
            else:
                # どこにも割当られなかった場合
                allocation = Allocation(pos.x, pos.y, -1)
                allocation_plan[d.name][time] = allocation
                d.set_allocation_point(time, allocation)
                print("allocation failed", d.name, time)
    return allocation_plan
Пример #3
0
def simple_use_plan_03(kwargs) -> AllocationPlan:
    atcs = kwargs["atcs"]
    devices = kwargs["ds"]
    max_hop = kwargs["max_hop"]
    congestion_scope = kwargs["congestion_scope"]
    reqapp=["1", "2", "3"]
    t_len = len(atcs)
    y_len = len(atcs[0])
    x_len = len(atcs[0][0])
    # cloudlets の空計画の作成
    allocation_plan = create_blank_allocation_plan(atcs, devices)
    for time, cloudlets in enumerate(tqdm(atcs)):
        # ds 終了していないデバイスを集める
        ds = list(filter(lambda d: d.is_poweron(time), devices))
        congestion_map = simple_create_congestion_map(time, x_len, y_len, ds, congestion_scope)
        cong_app_ds = []
        congestion_map1 = [[1,3,4,5,6,7,10],[2,4,5,12,5,3,11],[2,1,3,1,6,7,8]]
        dsa1 = list(filter(lambda d: d.appret(reqapp[0]), max_congest_ds))
        dsa2 = list(filter(lambda d: d.appret(reqapp[1]), max_congest_ds))
        dsa3 = list(filter(lambda d: d.appret(reqapp[2]), max_congest_ds))
        dsa = dsa2 + dsa1 + dsa3
            #cong_app_ds.extend(dsa)
            #print ("a")
        for d in ds:
            # step1 前回と同じ場所に置くことが適切かどうか判定し、適切なら配置を試行する
            now_pos = d.get_pos(time)
            if d.startup_time != time:
                prev_pos = d.get_allocation_point(time - 1)
                if distance(prev_pos, now_pos) <= max_hop:
                    # 前回と同じ場所に置くことを試行する
                    if cloudlets[prev_pos.y][prev_pos.x].can_append_device(d, True):
                        allocate(d, time, prev_pos, allocation_plan, cloudlets)
                        continue
            # step2
            if d.is_poweron(time + max_hop):
                next_pos = d.get_pos(time + max_hop)
            else:
                next_pos = d.get_pos(d.shutdown_time - 1)
            for hop in range(max_hop, 30):
                nps = near_points(now_pos, hop, Point(x_len - 1, y_len - 1), Point(0, 0))
                nps = sorted(nps, key=lambda p: distance(p, next_pos))
                tp, index = search(nps, True, key=lambda p: cloudlets[p.y][p.x].can_append_device(d, True))
                if index == -1:
                    continue
                allocate(d, time, tp, allocation_plan, cloudlets)
                break
            else:
                # どこにも割当られなかった場合
                allocation = Allocation(now_pos.x, now_pos.y, -1)
                allocation_plan[d.name][time] = allocation
                d.set_allocation_point(time, allocation)
                print("allocation failed", d.name, time)

    return allocation_plan
Пример #4
0
def set_device_set_pri(atcs: AllTimeCloudlets, cong_map: List[List[int]], t: int, devices: Devices,
                       x_len: int, y_len: int, scope: int):
    ds = list(filter(lambda d: d.is_poweron(t), devices))
    d_num = 0
    for d in ds:
        app_name = d.app_name()
        app_num = 0
        pos = d.get_pos(t)
        pts = near_points(pos, scope, Point(x_len - 1, y_len - 1), Point(0, 0))
        for p in pts:
            cloud = atcs[p.y][p.x][0]
            if cloud.is_operatable_application(app_name):
                app_num += 1
        pri_num = int(cong_map[pos.y][pos.x]) #/ app_num) #+ cong_map[pos.y][pos.x])
        #pri_num = app_num
        d.set_ds_pri(value=pri_num)
Пример #5
0
def simple_use_plan_07(kwargs) -> AllocationPlan:
    atcs = kwargs["atcs"]
    devices = kwargs["ds"]
    max_hop = kwargs["max_hop"]
    congestion_scope = kwargs["congestion_scope"]

    t_len = len(atcs)
    y_len = len(atcs[0])
    x_len = len(atcs[0][0])
    allocation_plan = create_blank_allocation_plan(atcs, devices)
    for time, cloudlets in enumerate(tqdm(atcs)):
        ds = list(filter(lambda d: d.is_poweron(time), devices))
        congestion_map = simple_create_congestion_map(time, x_len, y_len, ds, congestion_scope)
        # print_congestion(congestion_map, x_len, y_len)
        ds = sorted(ds, key=lambda d: congestion_map[d.get_pos(time).y][d.get_pos(time).x], reverse=True)
        for d in ds:
            # step1 前回と同じ場所に置くことが適切かどうか判定し、適切なら配置を試行する
            now_pos = d.get_pos(time)
            if d.startup_time != time:
                prev_pos = d.get_allocation_point(time - 1)
                if distance(prev_pos, now_pos) <= max_hop:
                    # 前回と同じ場所に置くことを試行する
                    if cloudlets[prev_pos.y][prev_pos.x].can_append_device(d, True):
                        allocate(d, time, prev_pos, allocation_plan, cloudlets)
                        continue
            # step2
            if d.is_poweron(time + max_hop):
                next_pos = d.get_pos(time + max_hop)
            else:
                next_pos = d.get_pos(d.shutdown_time - 1)
            for hop in range(max_hop, 30):
                nps = near_points(now_pos, hop, Point(x_len - 1, y_len - 1), Point(0, 0))
                nps = sorted(nps, key=lambda p: distance(p, next_pos))
                tp, index = search(nps, True, key=lambda p: cloudlets[p.y][p.x].can_append_device(d, True))
                if index == -1:
                    continue
                allocate(d, time, tp, allocation_plan, cloudlets)
                break
            else:
                # どこにも割当られなかった場合
                allocation = Allocation(now_pos.x, now_pos.y, -1)
                allocation_plan[d.name][time] = allocation
                d.set_allocation_point(time, allocation)
                print("allocation failed", d.name, time)
    return allocation_plan
Пример #6
0
def simple_create_congestion_map(t: int, x_len: int, y_len: int, devices: Devices, scope: int) -> List[List[int]]:
    """
    仮割り当てを用いて混雑度マップを生成する
    :param t: 混雑度マップを生成する時間
    :param x_len: xの長さ?
    :param y_len: yの長さ?
    :param devices: デバイス集合
    :param scope: 端末位置からどの程度はなれた範囲まで混雑度を加算するかを示す値
    :return: 
    """
    ret = [[0 for x in range(x_len)] for y in range(y_len)]
    ds = list(filter(lambda d: d.is_poweron(t), devices))
    for d in ds:
        pos = d.get_pos(t)
        pts = near_points(pos, scope, Point(x_len - 1, y_len - 1), Point(0, 0))
        for p in pts:
            ret[p.y][p.x] += d.use_resource
    return ret
Пример #7
0
def congestion_priority(kwards) -> AllocationPlan:
    """
    混雑Cloudletの直轄地にあるデバイスを優先して割り当てる方式
    :param atcs: すべての時間のCloudlet集合
    :param devices: すべてのデバイス集合
    :return: 
    """
    atcs = kwards["atcs"]
    devices = kwards["ds"]

    t_len = len(atcs)
    y_len = len(atcs[0])
    x_len = len(atcs[0][0])
    allocation_plan = create_blank_allocation_plan(atcs, devices)
    for time, cloudlets in enumerate(tqdm(atcs)):
        ds = list(filter(lambda d: d.is_poweron(time), devices))
        requests = create_congestion_map(time, len(cloudlets[0]),
                                         len(cloudlets), ds, 3)
        ds = sorted(
            ds,
            key=lambda d: requests[d.get_pos(time).y][d.get_pos(time).x],
            reverse=True)
        for d in ds:
            pos = d.get_pos(time)
            for hop in range(0, 30):
                nps = near_points(pos, hop, Point(x_len - 1, y_len - 1),
                                  Point(0, 0))
                tp, index = search(
                    nps,
                    True,
                    key=lambda p: cloudlets[p.y][p.x].can_append_device(d))
                if index == -1:
                    continue
                cloudlets[tp.y][tp.x].append_device(d)
                allocation = Allocation(tp.x, tp.y, distance(pos, tp))
                allocation_plan[d.name][time] = allocation
                d.set_allocation_point(time, Point(allocation.x, allocation.y))
                break
            else:
                # どこにも割当られなかった場合
                allocation = Allocation(pos.x, pos.y, -1)
                allocation_plan[d.name][time] = allocation
                d.set_allocation_point(time, Point(allocation.x, allocation.y))
    return allocation_plan
Пример #8
0
def create_app_cong_map(t: int, x_len: int, y_len: int, devices: Devices, scope: int,
                          tempallocation: Dict[str, Point]) -> List[List[int]]:
    """
    仮割り当てを用いてアプリ用混雑度マップを生成する
    :param t: アプリ用混雑度マップを生成する時間
    :param x_len: xの長さ?
    :param y_len: yの長さ?
    :param devices: デバイス集合
    :param scope: 端末位置からどの程度はなれた範囲まで混雑度を加算するかを示す値
    :return:
    """
    ret = [[0 for x in range(x_len)] for y in range(y_len)]
    ds = list(filter(lambda d: d.is_poweron(t), devices))
    for d in ds:
        pos = tempallocation[d.name]
        pts = near_points(pos, scope, Point(x_len - 1, y_len - 1), Point(0, 0))
        for p in pts:
            ret[p.y][p.x] += d.use_resource

    return ret
Пример #9
0
def simple_use_plan_06(kwargs) -> AllocationPlan:
    atcs = kwargs["atcs"]
    devices = kwargs["ds"]
    max_hop = kwargs["max_hop"]
    congestion_scope = kwargs["congestion_scope"]

    t_len = len(atcs)
    y_len = len(atcs[0])
    x_len = len(atcs[0][0])
    allocation_plan = create_blank_allocation_plan(atcs, devices)
    for time, cloudlets in enumerate(tqdm(atcs)):
        ds = list(filter(lambda d: d.is_poweron(time), devices))
        reqapp = ["1","2","3"]
        # reqapp ごとにデバイスを分ける
        dsa1 = list(filter(lambda d: d.appret(reqapp[0]), ds))
        dsa2 = list(filter(lambda d: d.appret(reqapp[1]), ds))
        dsa3 = list(filter(lambda d: d.appret(reqapp[2]), ds))
        # 要求数が多い順番を特定
        ds_app_len = [
            len(dsa1),
            len(dsa2),
            len(dsa3)
        ]
        max_len = [0,0,0]
        for i in range(0,3):
            max_len[i] = str(np.argmax(ds_app_len))
            ds_app_len[int(max_len[i])] = 0

        # app ごとの混雑度を計測
        congestion_mapa1 = simple_create_congestion_map(time, x_len, y_len, dsa1, congestion_scope)
        congestion_mapa2 = simple_create_congestion_map(time, x_len, y_len, dsa2, congestion_scope)
        congestion_mapa3 = simple_create_congestion_map(time, x_len, y_len, dsa3, congestion_scope)
        # app ごとの混雑度と近傍の利用可能cloudletの
        set_app_pri(atcs, congestion_mapa1, time, dsa1, x_len, y_len, max_len, congestion_scope)
        set_app_pri(atcs, congestion_mapa2, time, dsa2, x_len, y_len, max_len, congestion_scope)
        set_app_pri(atcs, congestion_mapa3, time, dsa3, x_len, y_len, max_len, congestion_scope)

        ds = sorted(ds, key=lambda d: d.ds_pri, reverse=False)

        for d in ds:
            # step1 前回と同じ場所に置くことが適切かどうか判定し、適切なら配置を試行する
            now_pos = d.get_pos(time)
            if d.startup_time != time:
                prev_pos = d.get_allocation_point(time - 1)
                if distance(prev_pos, now_pos) <= max_hop:
                    # 前回と同じ場所に置くことを試行する
                    if cloudlets[prev_pos.y][prev_pos.x].can_append_device(d, True):
                        allocate(d, time, prev_pos, allocation_plan, cloudlets)
                        continue
            # step2
            if d.is_poweron(time + max_hop):
                next_pos = d.get_pos(time + max_hop)
            else:
                next_pos = d.get_pos(d.shutdown_time - 1)
            for hop in range(max_hop, 30):
                nps = near_points(now_pos, hop, Point(x_len - 1, y_len - 1), Point(0, 0))
                nps = sorted(nps, key=lambda p: distance(p, next_pos))
                tp, index = search(nps, True, key=lambda p: cloudlets[p.y][p.x].can_append_device(d, True))
                if index == -1:
                    continue
                allocate(d, time, tp, allocation_plan, cloudlets)
                break
            else:
                # どこにも割当られなかった場合
                allocation = Allocation(now_pos.x, now_pos.y, -1)
                allocation_plan[d.name][time] = allocation
                d.set_allocation_point(time, allocation)
                print("allocation failed", d.name, time)
    return allocation_plan
Пример #10
0
def simple_use_plan_02(kwargs) -> AllocationPlan:
    atcs = kwargs["atcs"]
    devices = kwargs["ds"]
    max_hop = kwargs["max_hop"]
    congestion_scope = kwargs["congestion_scope"]
    reqapp=["1", "2", "3"]
    t_len = len(atcs)
    y_len = len(atcs[0])
    x_len = len(atcs[0][0])
    # cloudlets の空計画の作成
    allocation_plan = create_blank_allocation_plan(atcs, devices)
    for time, cloudlets in enumerate(tqdm(atcs)):
        # ds 終了していないデバイスを集める
        ds = list(filter(lambda d: d.is_poweron(time), devices))
        #ds = sorted(ds,lambda d: d.app_name,reversed=True)
        dsa1 = list(filter(lambda d: d.appret(reqapp[0]), ds))
        dsa2 = list(filter(lambda d: d.appret(reqapp[1]), ds))
        dsa3 = list(filter(lambda d: d.appret(reqapp[2]), ds))
        a1_len = len(dsa1)
        a2_len = len(dsa2)
        a3_len = len(dsa3)
        # # 混雑度マップの作成
        congestion_mapa1 = simple_create_congestion_map(time, x_len, y_len, dsa1, congestion_scope)
        congestion_mapa2 = simple_create_congestion_map(time, x_len, y_len, dsa2, congestion_scope)
        congestion_mapa3 = simple_create_congestion_map(time, x_len, y_len, dsa3, congestion_scope)
        # # # # print_congestion(congestion_map, x_len, y_len)
        dsa1 = sorted(dsa1, key=lambda d: congestion_mapa1[d.get_pos(time).y][d.get_pos(time).x], reverse=True)
        dsa2 = sorted(dsa2, key=lambda d: congestion_mapa2[d.get_pos(time).y][d.get_pos(time).x], reverse=True)
        dsa3 = sorted(dsa3, key=lambda d: congestion_mapa3[d.get_pos(time).y][d.get_pos(time).x], reverse=True)
        # if(a1_len > a2_len):
        #     if(a1_len > a3_len):
        #         if(a2_len > a3_len):
        #             ds = dsa2 + dsa1 + dsa3
        #         else:
        #             ds = dsa3 + dsa1 + dsa2
        #     else:
        #         ds = dsa1 + dsa3 + dsa2
        # else:
        #     if(a1_len > a3_len):
        #         ds = dsa1 + dsa2 + dsa3
        #     else:
        #         if(a2_len > a3_len):
        #             ds = dsa2 + dsa3 + dsa1
        #         else:
        #             ds = dsa3 + dsa2 + dsa1

        #ds = dsa2 + dsa1 + dsa3
        ds = dsa1 + dsa3 + dsa2
        # congestion_map = simple_create_congestion_map(time, x_len, y_len, ds, congestion_scope)
        # ds_high = list(filter(lambda d: congestion_map[d.get_pos(time).y][d.get_pos(time).x] > 3), ds)
        # ds_low = list(filter(lambda d: congestion_map[d.get_pos(time).y][d.get_pos(time).x] < 3), ds)
        # ds = ds_high + ds_low

        for d in ds:
            # step1 前回と同じ場所に置くことが適切かどうか判定し、適切なら配置を試行する
            now_pos = d.get_pos(time)
            if d.startup_time != time:
                prev_pos = d.get_allocation_point(time - 1)
                if distance(prev_pos, now_pos) <= max_hop:
                    # 前回と同じ場所に置くことを試行する
                    if cloudlets[prev_pos.y][prev_pos.x].can_append_device(d, True):
                        allocate(d, time, prev_pos, allocation_plan, cloudlets)
                        continue
            # step2 
            if d.is_poweron(time + max_hop):
                next_pos = d.get_pos(time + max_hop)
            else:
                next_pos = d.get_pos(d.shutdown_time - 1)
            for hop in range(max_hop, 30):
                nps = near_points(now_pos, hop, Point(x_len - 1, y_len - 1), Point(0, 0))
                nps = sorted(nps, key=lambda p: distance(p, next_pos))
                tp, index = search(nps, True, key=lambda p: cloudlets[p.y][p.x].can_append_device(d, True))
                if index == -1:
                    continue
                allocate(d, time, tp, allocation_plan, cloudlets)
                break
            else:
                # どこにも割当られなかった場合
                allocation = Allocation(now_pos.x, now_pos.y, -1)
                allocation_plan[d.name][time] = allocation
                d.set_allocation_point(time, allocation)
                print("allocation failed", d.name, time)

    return allocation_plan