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是什么意思
时间: 2023-08-28 08:05:21 浏览: 103
以上程序是一个用 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() 方法绘制覆盖率和覆盖率随回合数变化的图表。
阅读全文