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
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
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
Example #4
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
Example #5
0
 def test_search_01(self):
     d2 = self.iterable[1]
     dn, index = search(self.iterable, d2)
     self.assertEqual(dn, self.iterable[1])
     self.assertEqual(index, 1)
Example #6
0
 def test_search_02(self):
     dn, index = search(self.iterable, "d3", key=lambda d: d.name)
     self.assertEqual(dn, self.iterable[2])
     self.assertEqual(index, 2)
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
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