def allocate(device: Device, time, allocate_pos: Point, allocation_plan, cloudlets: List[List[Cloudlet]]) -> None:
    cloudlets[allocate_pos.y][allocate_pos.x].append_device(device)
    d_pos = device.get_pos(time) #ある時刻のデバイスの座標を取得
    #distanceは2点間の座標の距離を返す関数, Allocation()で割り当て計画の定義
    allocation = Allocation(allocate_pos.x, allocate_pos.y, distance(d_pos, allocate_pos))
    allocation_plan[device.name][time] = allocation #デバイス名と時間からなる2次元リストに割り当て計画を代入
    device.set_allocation_point(time, Point(allocation.x, allocation.y)) #割り当て
Esempio n. 2
0
def single_cross(p_min: Point,
                 p_max: Point,
                 t_max: int,
                 ur_min: int = 0,
                 ur_max: int = 3) -> Devices:
    ds = []
    for t in range(t_max + 1):
        num = t + 1
        if t > ur_max:
            num = ur_max
        for n in range(num):
            d1 = Device()
            p1_start = Point(int((p_max.x + p_min.x) / 2), 0)
            p1_goal = Point(int((p_max.x + p_min.x) / 2), p_max.y)
            d1.plan = route(p1_start, p1_goal)
            d1.use_resource = random.randint(ur_min, ur_max)
            d1.startup_time = t

            d2 = Device()
            p2_start = Point(0, int((p_min.y + p_max.y) / 2))
            p2_goal = Point(p_max.y, int((p_min.y + p_max.y) / 2))
            d2.plan = route(p2_start, p2_goal)
            d2.use_resource = random.randint(ur_min, ur_max)
            d2.startup_time = t
            ds.append(d1)
            ds.append(d2)
    return ds
Esempio n. 3
0
 def setUp(self):
     self.devices = [
         Device("d1", plan=[Point(0, 0)]),
         Device("d2", plan=[Point(2, 1)])
     ]
     self.devices[0].use_resource = 2
     self.devices[1].use_resource = 3
     pass
Esempio n. 4
0
def cross(p_min: Point,
          p_max: Point,
          t_max: int,
          ur_min: int = 0,
          ur_max: int = 3,
          r_num: int = 6,
          density: int = 1,
          upr: int = 3) -> Devices:
    """
    
    :param p_min: 
    :param p_max: 
    :param t_max: 
    :param ur_min: 
    :param ur_max: max of use resource
    :param r_num: number of road
    :param density: 集密度?
    :param upr: unit par roads
    :return: 
    """
    ds = []
    for t in range(t_max + 1):
        for i in range(int(r_num / 2)):
            offset = density
            div = int(r_num / 2) - 1 + (2 * density)
            for j in range(upr):
                d1 = Device()
                p1_start = Point(0,
                                 int((p_min.y + p_max.y) / div) * (offset + i))
                p1_goal = Point(p_max.x,
                                int((p_min.y + p_max.y) / div) * (offset + i))
                d1.plan = route(p1_start, p1_goal)
                d1.use_resource = random.randint(ur_min, ur_max)
                d1.startup_time = t
                ds.append(d1)
            for j in range(upr):
                d2 = Device()
                p2_start = Point(
                    int((p_min.x + p_max.x) / div) * (offset + i), 0)
                p2_goal = Point(
                    int((p_min.x + p_max.x) / div) * (offset + i), p_max.y)
                d2.plan = route(p2_start, p2_goal)
                d2.use_resource = random.randint(ur_min, ur_max)
                d2.startup_time = t

                ds.append(d2)
    Device.num = 0
    random.shuffle(ds)
    return ds
Esempio n. 5
0
 def setUp(self):
     self.cloudlet = Cloudlet(5, Point3D(0, 0, 0), name="d1")
     self.d01 = Device(name="d1")
     self.app01 = Application(name="a1")
     self.app02 = Application(name="a2")
     self.dapp01 = Application(name="a1", use_resource=1)
     self.d01.apps = [self.dapp01]
     self.cloudlet.apps_append(self.app02)
     self.cloudlet.apps_append(self.app01)
Esempio n. 6
0
 def setUp(self):
     self.iterable = [Device(name="d1"), Device(name="d2"), Device(name="d3"), Device(name="d4")]
]

min_road_device_num = 1
max_road_device_num = 1
min_use_resource = 1
max_use_resource = 1

for road in setup_roads:
    road_num = road[0]
    left_side = road[1]
    right_side = road[2]
    for i in range(x_len):
        n = random.randint(min_road_device_num, max_road_device_num)
        for j in range(n):
            d_name = "d{0}{1:05}".format(road_num, d_num)
            d = Device(name=d_name)
            d.use_resource = random.randint(min_use_resource, max_use_resource)
            d.startup_time = 0
            if random.randint(0, 3) == 0:
                roads = list(filter(lambda r: r != road, setup_roads))
                r = roads[random.randint(0, len(roads) - 1)]
                if random.randint(0, 1) == 0:
                    if road[0] < 30:
                        d.plan = route(Point(i, left_side.y), r[1])
                    else:
                        d.plan = route(Point(left_side.x, i), r[1])
                else:
                    if road[0] < 30:
                        d.plan = route(Point(x_len - 1 - i, left_side.y), r[1])
                    else:
                        d.plan = route(Point(left_side.y, y_len - 1- i), r[1])
Esempio n. 8
0
for x in range(x_len):
    for y in range(y_len):
        for t in range(t_len):
            n = random.randint(0, 2)
            if n == 0:
                #app = Application(name="a1")
            elif n == 1:
                #app = Application(name="a2")
            else:
                #app = Application(name="a3")
            #atcs[x][y][t].apps_append(app)
"""
devices = []  # type:List[Device]
d_num = 100
for i in range(d_num):
    d = Device(name="d{}".format(i))
    d.startup_time = 0
    n = random.randint(0, 3)
    if n == 0:
        d.plan = route(Point(0, 0), Point(x_len, y_len))
    if n == 1:
        d.plan = route(Point(x_len, y_len), Point(0, 0))
    if n == 2:
        d.plan = route(Point(0, y_len), Point(x_len, 0))
    if n == 3:
        d.plan = route(Point(y_len, 0), Point(0, x_len))
    n = random.randint(0, 2)
    if n == 0:
        #app = Application(name="a1")
        d.use_resource = 1
    elif n == 1:
Esempio n. 9
0
app3 = Application(name="3", use_resource=3)#random.randint(min_use_resource, max_use_resource))
#app4 = Application(name="4", use_resource=3)#random.randint(min_use_resource, max_use_resource))
#app5 = Application(name="5", use_resource=3)#random.randint(min_use_resource, max_use_resource))
app_resourse = [app1.use_resource, app2.use_resource, app3.use_resource]
n = 90
dnum = 1
for road in setup_roads:
    road_num = road[0]
    side_a = road[1]
    side_b = road[2]
    for i in range(x_len):
        #n = random.randint(min_road_device_num, max_road_device_num)

        for j in range(n):
            d_name = "d{0}{1:05}".format(road_num, d_num)
            d = Device(name=d_name)
            d.startup_time = 0
            #偏り有り

            #n1 = random.randint(1, d_random_num)
            if dnum == 13:
                d.append_app(Application(name="1", use_resource=random.randint(min_use_resource, max_use_resource)))
                da_num[2] += 1
                dnum = 1
            elif dnum % 2 == 0:
                d.append_app(Application(name="2", use_resource=random.randint(min_use_resource, max_use_resource)))
                da_num[0] += 1
            else:
                d.append_app(Application(name="3", use_resource=random.randint(min_use_resource, max_use_resource)))
                da_num[1] += 1
            dnum += 1
Esempio n. 10
0
 def test_can_append_device_04(self):
     d2 = Device(name="d2")
     d2.append_app(Application(name="a2", use_resource=1))
     self.assertFalse(self.cloudlet.can_append_device(d2, app_check=True))
Esempio n. 11
0
 def test_can_append_device_03(self):
     d2 = Device(name="d2")
     d2.append_app(Application(name="a2", use_resource=1))
     self.assertTrue(self.cloudlet.can_append_device(d2))
Esempio n. 12
0
min_road_device_num = 3
max_road_device_num = 9
min_use_resource = 1
max_use_resource = 3
c_resource = 5

for road in setup_roads:
    road_num = road[0]
    side_a = road[1]
    side_b = road[2]
    for i in range(x_len):
        n = random.randint(min_road_device_num, max_road_device_num)
        for j in range(n):
            d_name = "d{0}{1:05}".format(road_num, d_num)
            d = Device(name=d_name)
            d.use_resource = random.randint(min_use_resource, max_use_resource)
            d.startup_time = 0
            if n == 0:
                app = Application(name="a1")
            elif n == 1:
                app = Application(name="a2")
            else:
                app = Application(name="a3")

            if random.randint(0, 3) == 0:
                # 別サイドをゴールにする
                roads = list(filter(lambda r: r[0] / 30 != road[0] / 30, setup_roads))
                r = roads[random.randint(0, len(roads) - 1)]
                goal = random.randint(1, 2)
                if random.randint(0, 1) == 0:
Esempio n. 13
0
    name="3",
    use_resource=3)  #random.randint(min_use_resource, max_use_resource))
#app4 = Application(name="4", use_resource=1)#random.randint(min_use_resource, max_use_resource))
#app5 = Application(name="5", use_resource=1)#random.randint(min_use_resource, max_use_resource))
app_resourse = [app1.use_resource, app2.use_resource, app3.use_resource]
n = 110
for road in setup_roads:
    road_num = road[0]
    side_a = road[1]
    side_b = road[2]
    for i in range(x_len):
        #n = random.randint(min_road_device_num, max_road_device_num)

        for j in range(n):
            d_name = "d{0}{1:05}".format(road_num, d_num)
            d = Device(name=d_name)
            d.startup_time = 0
            #偏り有り
            """
            n1 = random.randint(1, d_random_num)
            if n1 % d_sur[0] == 0:
                d.append_app(app1)
                da_num[0] += 1
            elif n1 % d_sur[1] == 0:
                d.append_app(app2)
                da_num[1] += 1
            else:
                d.append_app(app3)
                da_num[2] += 1
            """
            #偏りなし
Esempio n. 14
0
app3 = Application(name="3", use_resource=3)
app_resourse = [app1.use_resource, app2.use_resource,
                app3.use_resource]  #アプリケーションが使えるリソース量のリスト

print(x_len)
n = 90
dnum = 1  #デバイス数
for road in setup_roads:
    road_num = road[0]  #setup_roadsの1列目
    side_a = road[1]  #setup_roadsの2列目(x軸が始点 or y軸が始点)
    #print(side_a)
    side_b = road[2]  #setup_roadsの3列目(x軸が終点 or y軸が終点)
    for i in range(x_len):
        for j in range(n):
            d_name = "d{0}{1:05}".format(road_num, d_num)
            d = Device(name=d_name)  #デバイスのオブジェクトに名前を代入してインスタンス作成
            d.startup_time = 0  #デバイスのインスタンスに起動時間を代入
            if dnum == 13:
                d.append_app(
                    Application(name="1",
                                use_resource=random.randint(
                                    min_use_resource, max_use_resource)))
                da_num[2] += 1
                dnum = 1
            elif dnum % 2 == 0:
                d.append_app(
                    Application(name="2",
                                use_resource=random.randint(
                                    min_use_resource, max_use_resource)))
                da_num[0] += 1
            else:
Esempio n. 15
0
t_len = 10
x_len = 30
y_len = 30
atcs = create_all_time_cloudlets(t_len, x_len, y_len)

devices = []  # type:List[Device]

# device name is 10000 - 10999[
r_num = 10
r_pos = Point(10, 0)
d_num = 0
for i in range(x_len):
    n = random.randint(5)
    for j in range(n):
        d = Device(name="d10{0:03}".format(d_num))
        d.use_resource = random.randint(3)
        d.startup_time = 0
        d.plan = route(Point(r_pos.x + i, r_pos.y), Point(x_len - 1, r_pos.y))
        devices.append(d)
        d_num += 1
for t in range(t_len):
    n = random.randint(5)
    for i in range(n):
        d = Device(name="d10{0:03}".format(d_num))
        d.use_resource = random.randint(3)
        d.startup_time = 0
        d.plan = route(r_pos, Point(x_len - 1, r_pos.y))
        d_num += 1

# device name is