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 19:42:59 浏览: 27
这段程序主要是使用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求解最优解问题,请解释如下两个问题: (1)如何选择input_tours_for_drones和len_input_tours_for_drones的值? (2)此程序在运行时如何调参?
(1) input_tours_for_drones和len_input_tours_for_drones的值需要根据实际问题进行调整。其中,input_tours_for_drones表示每个无人机需要完成的巡航任务数量,len_input_tours_for_drones表示每个巡航任务需要经过的目标数量。如果有更多的目标需要被覆盖,就需要增加input_tours_for_drones和len_input_tours_for_drones的值,以便增加巡航次数和目标数量,从而提高覆盖率和效率。
(2) 这个程序使用Gurobi进行求解,Gurobi是一个商业数学规划软件,有很多参数可以调整以优化求解结果。可以通过修改参数来控制求解器的行为,例如设置求解时间限制,选择求解算法,调整优化目标等等。在此程序中,可以通过修改max_rounds参数来控制最大巡航轮数,从而控制求解器的运行时间。同时,可以设置debug参数来查看求解器的详细输出信息,以便进行调试。
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个目标点数量。因此,这两个变量的值会影响到巡航路径的数量和长度,从而影响到最终模型的解。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)