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
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
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]) else: if random.randint(0, 1) == 0:
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: d.append_app(