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:
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") d.use_resource = 1 #d.append_app(app) devices.append(d) header = { "device_num": d_num, "t_length": t_len, "x_length": x_len, "y_length": y_len, }
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