diff --git a/GA/main_parallel.py b/GA/main_parallel.py index 98135f0..0ad0363 100644 --- a/GA/main_parallel.py +++ b/GA/main_parallel.py @@ -30,9 +30,9 @@ if __name__ == "__main__": # 重要:在 Windows 上必须加这一行 # --------------------------- # 需要修改的超参数 # --------------------------- - R = 3 + R = 1 C = 1 - params_file = 'params2' + params_file = 'params3' batch_size = 60 # 控制一次最多并行多少个任务 with open(params_file + '.yml', 'r', encoding='utf-8') as file: diff --git a/GA/sa_finetune.py b/GA/sa_finetune.py index fc5bbcb..b5e1db6 100644 --- a/GA/sa_finetune.py +++ b/GA/sa_finetune.py @@ -5,7 +5,7 @@ import yaml class SA_FineTuner: - def __init__(self, initial_row_cuts, initial_col_cuts, car_paths, max_iterations=1000, initial_temp=100, cooling_rate=0.95): + def __init__(self, params_file, initial_row_cuts, initial_col_cuts, car_paths, max_iterations=1000, initial_temp=100, cooling_rate=0.95): """ 初始化模拟退火算法 :param initial_row_cuts: 初始行切分比例列表,例如 [0.1, 0.3, 0.7] @@ -16,7 +16,7 @@ class SA_FineTuner: :param cooling_rate: 温度下降速率 """ # 读取参数 - with open('params3.yml', 'r', encoding='utf-8') as file: + with open(params_file + '.yml', 'r', encoding='utf-8') as file: params = yaml.safe_load(file) self.H = params['H'] @@ -137,9 +137,9 @@ class SA_FineTuner: second_point = car_path[i + 1] car_time += math.dist( rectangles[first_point]['center'], rectangles[second_point]['center']) * self.car_time_factor - car_time += math.dist(rectangles[0]['center'], + car_time += math.dist(rectangles[car_path[0]]['center'], [self.H / 2, self.W / 2]) * self.car_time_factor - car_time += math.dist(rectangles[-1]['center'], + car_time += math.dist(rectangles[car_path[-1]]['center'], [self.H / 2, self.W / 2]) * self.car_time_factor mortorcade_time_lt.append(max(car_time + flight_time, bs_time)) @@ -206,15 +206,16 @@ if __name__ == "__main__": # --------------------------- # 需要修改的超参数 # --------------------------- - file_path = r"solutions\trav_ga_params2_parallel.json" + solution_path = r"solutions\mtkl_params2.json" + params_file = r"params2" max_iterations=10000 initial_temp=100 cooling_rate=0.95 initial_row_cuts, initial_col_cuts, car_paths = load_initial_solution( - file_path) + solution_path) - sa = SA_FineTuner(initial_row_cuts, initial_col_cuts, car_paths, max_iterations, initial_temp, cooling_rate) + sa = SA_FineTuner(params_file, initial_row_cuts, initial_col_cuts, car_paths, max_iterations, initial_temp, cooling_rate) best_row_cuts, best_col_cuts, best_T = sa.run() # 输出结果 diff --git a/mtkl_sovler.py b/mtkl_sovler.py index 2ac7f00..27a81dd 100644 --- a/mtkl_sovler.py +++ b/mtkl_sovler.py @@ -17,7 +17,6 @@ num_iterations = 10000 # C = random.randint(0, 3) # 列分段数 R = 3 C = 1 - params_file = 'params2' diff --git a/solutions/mtkl_params2.yml.json b/solutions/mtkl_params2.yml.json deleted file mode 100644 index 7e21c70..0000000 --- a/solutions/mtkl_params2.yml.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "row_boundaries": [ - 0.0, - 0.3, - 0.6, - 0.8, - 1.0 - ], - "col_boundaries": [ - 0.0, - 0.5, - 1.0 - ], - "car_paths": [ - [ - [ - 22.5, - 37.5 - ], - [ - 7.5, - 37.5 - ] - ], - [ - [ - 7.5, - 12.5 - ], - [ - 45.0, - 37.5 - ] - ], - [ - [ - 22.5, - 12.5 - ], - [ - 35.0, - 12.5 - ], - [ - 35.0, - 37.5 - ], - [ - 45.0, - 12.5 - ] - ] - ] -} \ No newline at end of file diff --git a/solutions/trav_ga_params2_parallel.json b/solutions/trav_ga_params2_parallel.json index e5e72ed..101bee5 100644 --- a/solutions/trav_ga_params2_parallel.json +++ b/solutions/trav_ga_params2_parallel.json @@ -1,7 +1,7 @@ { "row_boundaries": [ 0.0, - 0.2, + 0.1, 0.4, 0.7, 1.0 @@ -12,19 +12,19 @@ 1.0 ], "car_paths": [ - [ - 7, - 6 - ], [ 4, 2, 0 ], [ - 1, + 5, 3, - 5 + 1 + ], + [ + 7, + 6 ] ] } \ No newline at end of file diff --git a/solutions/trav_ga_params3.json b/solutions/trav_ga_params3.json deleted file mode 100644 index cb6e440..0000000 --- a/solutions/trav_ga_params3.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "row_boundaries": [ - 0.0, - 0.3, - 1.0 - ], - "col_boundaries": [ - 0.0, - 0.4, - 1.0 - ], - "car_paths": [ - [ - [ - 19.5, - 21.0 - ] - ], - [ - [ - 4.5, - 6.0 - ], - [ - 4.5, - 21.0 - ], - [ - 19.5, - 6.0 - ] - ] - ] -} \ No newline at end of file diff --git a/solutions/trav_ga_params3_parallel.json b/solutions/trav_ga_params3_parallel.json index da3f6a7..929d6da 100644 --- a/solutions/trav_ga_params3_parallel.json +++ b/solutions/trav_ga_params3_parallel.json @@ -11,12 +11,12 @@ ], "car_paths": [ [ - 0, - 2 + 2, + 0 ], [ - 1, - 3 + 3, + 1 ] ] } \ No newline at end of file diff --git a/visualization.py b/visualization.py index 583ebe1..963d60a 100644 --- a/visualization.py +++ b/visualization.py @@ -53,7 +53,7 @@ if __name__ == "__main__": # 需要修改的超参数 # --------------------------- params_file = 'params2' - solution_file = r'solutions\trav_ga_params2_parallel.json' + solution_file = r'solutions\mtkl_params2.json' with open(params_file + '.yml', 'r', encoding='utf-8') as file: params = yaml.safe_load(file)