seed = 50 n_target = 50 n_depots = 2 width_area = 2000 height_area = 2000 max_rounds = 5 input_tours_for_drones = 20 len_input_tours_for_drones = 7 np.random.seed(seed) drones = test3(plot=False) drones = drones[:2] aoi = utility.build_random_aoi(width_area, height_area, n_target, n_depots, hovering_time=5, seed=seed) depots = aoi.depots depot_first_drone = depots[0] tours_first_drone = [build_random_tour(aoi, depot_first_drone, np.random.randint(len_input_tours_for_drones - 5,len_input_tours_for_drones + 5)) for i in range(input_tours_for_drones)] depot_second_drone = depots[1] tours_second_drone = [build_random_tour(aoi, depot_second_drone, np.random.randint(len_input_tours_for_drones - 5,len_input_tours_for_drones + 5)) for i in range(input_tours_for_drones)] uavs_to_tours = {drones[0]: tours_first_drone, drones[1]: tours_second_drone model = TotalCoverageModel(aoi, uavs_to_tours, max_rounds, debug=False) model.build() model.optimize() mrs = model.solution assert mrs is not None, "optimal solution not found" print("TC-OPT covers", mrs.coverage_score(), "targets using", mrs.max_rounds, "rounds") mrs.plot("TC-OPT") # for big istances (over 200/300 points) remove this plot mrs.plot_cumulative_coverage_for_round("TC-OPT") 以上为用Gurobi求解最优解问题,请解释以上程序
时间: 2024-03-15 20:42:59 浏览: 62
这段程序主要是使用Gurobi求解一个最优化模型,该模型是一个TotalCoverageModel,其中包括了一个区域AOI,一些无人机UAVs和它们的巡航路径tours,以及一些限制条件,如最大巡航轮次max_rounds等。程序中,首先生成一个随机AOI,包含一些目标点和几个无人机起飞点,然后对于每个无人机,生成一些随机的巡航路径,这些路径将被分配给无人机。接下来,将这些信息传递给TotalCoverageModel,并对其进行构建和优化,最后输出结果,并绘制一些图形以可视化结果。
相关问题
input_tours_for_drones = 20 len_input_tours_for_drones = 7 aoi = utility.build_random_aoi(width_area, height_area, n_target, n_depots, hovering_time=5, seed=seed) depots = aoi.depots depot_first_drone = depots[0] tours_first_drone=[build_random_tour(aoi,depot_first_drone,np.random.randint(len_input_tours_for_drones - 5,len_input_tours_for_drones + 5)) for i in range(input_tours_for_drones)] depot_second_drone = depots[1] tours_second_drone=[build_random_tour(aoi,depot_second_drone,np.random.randint(len_input_tours_for_drones-5, len_input_tours_for_drones + 5)) for i in range(input_tours_for_drones)] uavs_to_tours = {drones[0]: tours_first_drone, drones[1]: tours_second_drone model = TotalCoverageModel(aoi, uavs_to_tours, max_rounds, debug=False) model.build() model.optimize() mrs = model.solution assert mrs is not None, "optimal solution not found" print("TC-OPT covers", mrs.coverage_score(), "targets using", mrs.max_rounds, "rounds") mrs.plot("TC-OPT") # for big istances (over 200/300 points) remove this plot mrs.plot_cumulative_coverage_for_round("TC-OPT") 以上为用Gurobi求解最优解问题,请解释以上程序: depot_first_drone = depots[0] tours_first_drone=[build_random_tour(aoi,depot_first_drone,np.random.randint(len_input_tours_for_drones - 5,len_input_tours_for_drones + 5)) for i in range(input_tours_for_drones)] depot_second_drone = depots[1] tours_second_drone=[build_random_tour(aoi,depot_second_drone,np.random.randint(len_input_tours_for_drones-5, len_input_tours_for_drones + 5)) for i in range(input_tours_for_drones)] uavs_to_tours = {drones[0]: tours_first_drone, drones[1]: tours_second_drone是什么意思
以上程序是一个用 Gurobi 求解最优解的问题,主要包括以下步骤:
1. 定义了一个输入参数 input_tours_for_drones,表示每架无人机需要执行的巡航任务数;定义了一个变量 len_input_tours_for_drones,表示巡航任务的长度。
2. 通过调用 build_random_aoi 函数生成一个随机的区域,包括了 n_target 个目标点和 n_depots 个起飞点,并指定了每个起飞点的停留时间为 5 秒。
3. 从生成的起飞点中选择了第一个起飞点为无人机的起飞点,并通过调用 build_random_tour 函数生成了 tours_first_drone 列表,其中包含了 input_tours_for_drones 个随机生成的巡航任务序列。
4. 同理,选择第二个起飞点为第二架无人机的起飞点,并生成了 tours_second_drone 列表,其中也包含了 input_tours_for_drones 个随机生成的巡航任务序列。
5. 将两架无人机的巡航任务分别保存在字典 uavs_to_tours 中,其中 drones[0] 表示第一架无人机,drones[1] 表示第二架无人机。
6. 定义了一个 TotalCoverageModel 模型,将区域信息和无人机的巡航任务传入模型中,并设置了最大回合数为 max_rounds。
7. 调用 model.build() 方法生成模型。
8. 调用 model.optimize() 方法求解模型的最优解。
9. 将最优解保存在变量 mrs 中,并打印出覆盖目标点的数量和使用的最大回合数。
10. 最后通过调用 mrs.plot() 方法和 mrs.plot_cumulative_coverage_for_round() 方法绘制覆盖率和覆盖率随回合数变化的图表。
input_tours_for_drones = 20 len_input_tours_for_drones = 7 np.random.seed(seed) drones = test3(plot=False) drones = drones[:2] aoi = utility.build_random_aoi(width_area, height_area, n_target, n_depots, hovering_time=5, seed=seed) depots = aoi.depots depot_first_drone = depots[0] tours_first_drone = [build_random_tour(aoi, depot_first_drone, np.random.randint(len_input_tours_for_drones - 5,len_input_tours_for_drones + 5)) for i in range(input_tours_for_drones)] uavs_to_tours = {drones[0]: tours_first_drone, drones[1]: tours_second_drone model = TotalCoverageModel(aoi, uavs_to_tours, max_rounds, debug=False) model.build() model.optimize() mrs = model.solution assert mrs is not None, "optimal solution not found" print("TC-OPT covers", mrs.coverage_score(), "targets using", mrs.max_rounds, "rounds") mrs.plot("TC-OPT") # for big istances (over 200/300 points) remove this plot mrs.plot_cumulative_coverage_for_round("TC-OPT") 以上为用Gurobi求解最优解问题,请解释以上程序,input_tours_for_drones和len_input_tours_for_drones分别是什么意思
在这段程序中,input_tours_for_drones表示每个无人机分配到的巡航路径数量,len_input_tours_for_drones表示每个巡航路径的长度,即对应的目标点数量。在程序中,生成巡航路径时,使用了np.random.randint(len_input_tours_for_drones - 5, len_input_tours_for_drones + 5)来控制每个巡航路径的长度(目标点数量)在一个范围内波动,范围是以len_input_tours_for_drones为中心,左右扩展5个目标点数量。因此,这两个变量的值会影响到巡航路径的数量和长度,从而影响到最终模型的解。
阅读全文