From 8bef8ced7954900eb39d01a818173c469adc80d1 Mon Sep 17 00:00:00 2001 From: JonZhao <1044264932@qq.com> Date: Tue, 4 Jun 2019 15:16:50 +0800 Subject: update and fix error in local_search_procedure --- multiple_ant_colony_system.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'multiple_ant_colony_system.py') diff --git a/multiple_ant_colony_system.py b/multiple_ant_colony_system.py index c0fc3c8..b4e6f92 100644 --- a/multiple_ant_colony_system.py +++ b/multiple_ant_colony_system.py @@ -388,8 +388,9 @@ class MultipleAntColonySystem: if self.whether_or_not_to_show_figure: path_queue_for_figure.put(PathMessage(None, None)) - file_to_write.flush() - file_to_write.close() + if file_to_write is not None: + file_to_write.flush() + file_to_write.close() return if path_found_queue.empty(): @@ -417,7 +418,8 @@ class MultipleAntColonySystem: self.print_and_write_in_file(file_to_write, '[macs]: distance of found path (%f) better than best path\'s (%f)' % (found_path_distance, self.best_path_distance)) self.print_and_write_in_file(file_to_write, 'it takes %0.3f second from multiple_ant_colony_system running' % (time.time()-start_time_total)) self.print_and_write_in_file(file_to_write, '*' * 50) - file_to_write.flush() + if file_to_write is not None: + file_to_write.flush() self.best_path = found_path self.best_vehicle_num = found_path_used_vehicle_num @@ -442,7 +444,8 @@ class MultipleAntColonySystem: % (found_path_used_vehicle_num, best_vehicle_num, found_path_distance)) self.print_and_write_in_file(file_to_write, 'it takes %0.3f second multiple_ant_colony_system running' % (time.time() - start_time_total)) self.print_and_write_in_file(file_to_write, '*' * 50) - file_to_write.flush() + if file_to_write is not None: + file_to_write.flush() self.best_path = found_path self.best_vehicle_num = found_path_used_vehicle_num -- cgit v1.2.3