Esempio n. 1
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. 2
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. 3
0
def create_devices(p_min: Point, p_max: Point, t_max: int, npt: int,
                   move: int):
    ds = []  # type: Devices
    for t in tqdm(range(t_max)):
        for n in range(npt):
            d = Device(startup_time=t)
            d.use_resource = 1
            start, goal = random_two_point(move, p_min, p_max)
            d.plan = route(start, goal)
            ds.append(d)
    return ds
Esempio n. 4
0
def create_devices(max_time: int,
                   x_length: int,
                   y_length: int,
                   low_limit: int,
                   high_limit: int,
                   min_coincident: int,
                   max_coincident: int,
                   min_use_resource: int,
                   max_use_resource: int,
                   num: int = None) -> Devices:
    """
    端末群を生成する
    :param max_time: 最大時間
    :param x_length: x座標の最大値
    :param y_length: y座標の最大値
    :param low_limit: 移動時間の下限
    :param high_limit: 移動時間の上限
    :param min_coincident: 最少同時発生数
    :param max_coincident: 最大同時発生数
    :param min_use_resource: 最小消費リソース
    :param max_use_resource: 最大消費リソース
    :param num: 端末数
    :return: 端末群
    """
    if num is None:
        num = max_coincident * max_time
    devices = []  # type:Devices
    count = 0  # type:int
    for t in range(max_time):
        create_num = random.randint(min_coincident, max_coincident)
        for i in range(create_num):
            device = Device()
            device.startup_time = t
            move = random.randint(low_limit, high_limit)
            start, goal = random_two_point(move, Point(0, 0),
                                           Point(x_length - 1, y_length - 1))
            device.plan = route(start, goal)
            device.use_resource = random.randint(min_use_resource,
                                                 max_use_resource)
            devices.append(device)
            count += 1
            if count == num:
                return devices
    return devices
 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])
         else:
             if random.randint(0, 1) == 0:
                 if road[0] < 30:
                     d.plan = route(Point(i, left_side.y), right_side)
                 else:
                     d.plan = route(Point(left_side.x, i), right_side)
             else:
                 if road[0] < 30:
Esempio n. 6
0
            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:
        #app = Application(name="a2")
        d.use_resource = 1
    else:
        #app = Application(name="a3")
Esempio n. 7
0
                da_num[1] += 1
            elif n1 == c_sur[2]:
                d.append_app(app3)
                da_num[2] += 1
            """


            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:
                    if road[0] < 30:
                        # 左右のルート
                        d.plan = route(Point(i, side_a.y), r[goal])
                    else:
                        # 上下のルート
                        d.plan = route(Point(side_a.x, i), r[goal])
                else:
                    if road[0] < 30:
                        # 左右のルート
                        d.plan = route(Point(x_len - 1 - i, side_a.y), r[goal])
                    else:
                        # 上下のルート
                        d.plan = route(Point(side_a.y, y_len - 1 - i), r[goal])
            else:
                if random.randint(0, 1) == 0:
                    # aからbへ
                    if road[0] < 30:
                        d.plan = route(Point(i, side_a.y), side_b)
Esempio n. 8
0
 def test_route_01(self):
     p1 = Point(0, 0)
     p2 = Point(2, 2)
     r = point.route(p1, p2)
     self.assertTrue(point.continuity(r))
     self.assertEqual(5, len(r))
Esempio n. 9
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