示例#1
0
def ffv2(all_time_cloudlets: AllTimeCloudlets,
         devices: Devices) -> AllocationPlan:
    """
    :param all_time_cloudlets: 
    :param devices: 
    :return: 
    """
    allocation_plan = create_blank_allocation_plan(all_time_cloudlets, devices)
    random.shuffle(devices)
    # time : 現在の時間, cloudlets : 現在の各クラウドレット
    for time, cloudlets in enumerate(tqdm(all_time_cloudlets)):
        for device in devices:
            if not (device.startup_time <= time < device.shutdown_time):
                # デバイス(端末)が稼働していない時間の場合
                continue
            # time時間での端末の位置を取得
            pos = device.plan[time - device.startup_time]
            for hop in range(0, 30):
                near = near_cloudlets(cloudlets, pos, d_max=hop, d_min=hop)
                near = list(filter(lambda c: c.can_append_device(device),
                                   near))
                if len(near) == 0:
                    continue
                cloudlet = near[0]
                cloudlet.append_device(device)
                p = get_cloudlet_point_from_cloudlets(cloudlet.name,
                                                      cloudlets=cloudlets)
                allocation_plan[device.name][time] = Allocation(p.x, p.y, hop)
                break
            else:
                # どこにも割当られなかった場合
                allocation_plan[device.name][time] = Allocation(
                    pos.x, pos.y, -1)
    return allocation_plan
示例#2
0
def simple(all_time_cloudlets: AllTimeCloudlets,
           devices: Devices) -> AllocationPlan:
    """
    シンプルなFFアルゴリズムによる割当て
    リソース不足時に周辺のCloudletの探索を行わない
    :param all_time_cloudlets: Cloudletの三次元リスト
    :param devices: Deviceのリスト
    :return: 割り当て計画
    """
    allocation_plan = create_blank_allocation_plan(all_time_cloudlets, devices)
    # time : 現在の時間, cloudlets : 現在の各クラウドレット
    for time, cloudlets in enumerate(all_time_cloudlets):
        for device in devices:
            if not (device.startup_time <= time < device.shutdown_time):
                # デバイス(端末)が稼働していない時間の場合
                continue
            # time時間での端末の位置を取得
            pos = device.plan[time - device.startup_time]
            cloudlet = cloudlets[pos.y][pos.x]
            if cloudlet.can_append_device(device):
                # 割当可能な場合
                cloudlet.append_device(device)
                allocation_plan[device.name][time] = Allocation(
                    pos.x, pos.y, 0)
            else:
                # 割当できない場合
                allocation_plan[device.name][time] = Allocation(
                    pos.x, pos.y, -1)
    return allocation_plan
示例#3
0
 def test_simple_ffd(self):
     ap = oldallocation.decreasing(self.all_time_cloudlets, self.devices)
     self.assertEqual(ap["d1"][0], Allocation(0, 0, 0))
     self.assertEqual(ap["d1"][1], Allocation(0, 1, 0))
     self.assertEqual(ap["d1"][2], Allocation(0, 2, 0))
     self.assertEqual(ap["d2"][0], None)
     self.assertEqual(ap["d2"][1], Allocation(0, 0, 0))
     self.assertEqual(ap["d2"][2], Allocation(0, 1, 0))
     self.assertEqual(ap["d2"][3], Allocation(0, 2, 0))
     self.assertEqual(ap["d4"][0], None)
     self.assertEqual(ap["d4"][1], Allocation(0, 0, -1))
     self.assertEqual(ap["d4"][2], Allocation(0, 1, -1))
     self.assertEqual(ap["d4"][3], Allocation(0, 2, -1))
示例#4
0
def ffdv2_min(all_time_cloudlets: AllTimeCloudlets,
              devices: Devices) -> AllocationPlan:
    """
    FFDアルゴリズムによる割当と、
    リソース不足時に最もリソースの空きの大きい周辺Cloudletを探索を行う
    :param all_time_cloudlets: 
    :param devices: 
    :return: 
    """
    allocation_plan = create_blank_allocation_plan(all_time_cloudlets, devices)
    random.shuffle(devices)
    devices = sorted(devices, key=lambda c: c.use_resource, reverse=True)
    # time : 現在の時間, cloudlets : 現在の各クラウドレット
    for time, cloudlets in enumerate(tqdm(all_time_cloudlets)):
        for device in devices:
            if not (device.startup_time <= time < device.shutdown_time):
                # デバイス(端末)が稼働していない時間の場合
                continue
            # time時間での端末の位置を取得
            pos = device.plan[time - device.startup_time]
            for hop in range(0, 30):
                near = near_cloudlets(cloudlets, pos, d_max=hop, d_min=hop)
                near = list(filter(lambda c: c.can_append_device(device),
                                   near))
                if len(near) == 0:
                    continue
                cloudlet = min(near, key=lambda c: c.empty_resource)
                # 割当可能な場合
                cloudlet.append_device(device)
                p = get_cloudlet_point_from_cloudlets(cloudlet.name,
                                                      cloudlets=cloudlets)
                allocation_plan[device.name][time] = Allocation(p.x, p.y, hop)
                break
            else:
                # どこにも割当られなかった場合
                allocation_plan[device.name][time] = Allocation(
                    pos.x, pos.y, -1)
    return allocation_plan
示例#5
0
 def setUp(self):
     self.allocation_plan = {
         "d1": [Allocation(1, 1, 3), Allocation(1, 1, 3), Allocation(1, 1, 3)],
         "d2": [Allocation(1, 1, 1), Allocation(1, 1, 3), Allocation(1, 1, 5)],
         "d3": [Allocation(1, 1, 1), Allocation(1, 1, 1), Allocation(1, 1, 1)]
     }
示例#6
0
 def setUp(self):
     self.inputdata_file_name = "test/utility/test_data/test_devices_for_json_file.inputdata"
     self.csv_file_name = "test/utility/test_data/test_allocation_plan_to_csv.csv"
     self.all_time_cloudlets = create_all_time_cloudlets(10, 10, 10)
     self.devices = [Device(name="d1"), Device(name="d2"), Device(name="d3")]
     self.allocation_plan = {
         "d1": [Allocation(0, 0, 0), Allocation(0, 0, 1), Allocation(0, 0, 3)],
         "d2": [Allocation(0, 0, 1), Allocation(0, 0, 1), Allocation(0, 0, 3)],
         "d3": [Allocation(0, 0, 3), Allocation(0, 0, 2), Allocation(0, 0, 2)],
         "d4": [Allocation(0, 0, 0), Allocation(0, 0, 4), Allocation(0, 0, 4)]
     }
     data.input_data_to_file(self.all_time_cloudlets, self.devices, self.inputdata_file_name)
示例#7
0
 def test_nearby_searchable_ffd(self):
     for cloudlets in self.all_time_cloudlets:
         for row in cloudlets:
             for index, c in enumerate(row):
                 c.resource = 5 + index
     ap = oldallocation.ffd(self.all_time_cloudlets, self.devices)
     self.assertEqual(self.all_time_cloudlets[0][0][0].empty_resource, 0)
     self.assertEqual(self.all_time_cloudlets[1][1][0].empty_resource, 0)
     self.assertEqual(self.all_time_cloudlets[2][2][0].empty_resource, 0)
     self.assertEqual(self.all_time_cloudlets[1][0][0].empty_resource, 0)
     self.assertEqual(self.all_time_cloudlets[2][1][0].empty_resource, 0)
     self.assertEqual(self.all_time_cloudlets[3][2][0].empty_resource, 0)
     self.assertEqual(self.all_time_cloudlets[1][0][1].empty_resource, 1)
     self.assertEqual(self.all_time_cloudlets[2][0][2].empty_resource, 2)
     self.assertEqual(self.all_time_cloudlets[3][0][3].empty_resource, 3)
     self.assertEqual(self.all_time_cloudlets[1][0][2].empty_resource, 2)
     self.assertEqual(self.all_time_cloudlets[2][1][1].empty_resource, 1)
     self.assertEqual(self.all_time_cloudlets[3][2][1].empty_resource, 1)
     self.assertEqual(ap["d1"][0], Allocation(0, 0, 0))
     self.assertEqual(ap["d1"][1], Allocation(0, 1, 0))
     self.assertEqual(ap["d1"][2], Allocation(0, 2, 0))
     self.assertEqual(ap["d2"][0], None)
     self.assertEqual(ap["d2"][1], Allocation(0, 0, 0))
     self.assertEqual(ap["d2"][2], Allocation(0, 1, 0))
     self.assertEqual(ap["d2"][3], Allocation(0, 2, 0))
     self.assertEqual(ap["d3"][0], None)
     self.assertEqual(ap["d3"][1], Allocation(1, 0, 0))
     self.assertEqual(ap["d3"][2], Allocation(2, 0, 0))
     self.assertEqual(ap["d3"][3], Allocation(3, 0, 0))
     self.assertEqual(ap["d4"][0], None)
     self.assertEqual(ap["d4"][1], Allocation(2, 0, 2))
     self.assertEqual(ap["d4"][2], Allocation(1, 1, 1))
     self.assertEqual(ap["d4"][3], Allocation(1, 2, 1))