修改GA bug

This commit is contained in:
weixin_46229132 2025-03-22 17:24:45 +08:00
parent c9db9244b3
commit 17acfa5409
2 changed files with 3 additions and 2 deletions

View File

@ -82,7 +82,8 @@ with tqdm(total=total_iterations, desc="Processing") as pbar:
car_path = []
for k in range(from_index, end_index + 1):
rectrangle_idx = best_solution[k]
car_path.append(rectrangles[rectrangle_idx]['center'])
if rectrangle_idx not in to_process_idx:
car_path.append(rectrangles[rectrangle_idx - 1]['center'])
car_paths.append(car_path)
pbar.update(1)

View File

@ -112,7 +112,7 @@ if __name__ == "__main__": # 重要:在 Windows 上必须加这一行
for k in range(from_index, end_index + 1):
rectrangle_idx = best_solution[k]
if rectrangle_idx not in to_process_idx:
car_path.append(rectrangles[rectrangle_idx]['center'])
car_path.append(rectrangles[rectrangle_idx - 1]['center'])
car_paths.append(car_path)
# 输出最佳方案