From 6c95eeebca7c843a3b9a775a4215836af2f5ab42 Mon Sep 17 00:00:00 2001 From: JonZhao <1044264932@qq.com> Date: Tue, 4 Jun 2019 09:51:17 +0800 Subject: =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=9C=A8given=5Ftime=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=86=85=E6=B2=A1=E6=9C=89=E5=BE=97=E5=88=B0?= =?UTF-8?q?=E6=9B=B4=E5=A5=BD=E7=9A=84=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- multiple_ant_colony_system.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/multiple_ant_colony_system.py b/multiple_ant_colony_system.py index 0ef14da..3a47ff1 100644 --- a/multiple_ant_colony_system.py +++ b/multiple_ant_colony_system.py @@ -123,6 +123,7 @@ class MultipleAntColonySystem: # 如果走完所有的点了,需要回到depot if ant.index_to_visit_empty(): + ant.graph.local_update_pheromone(ant.current_index, 0) ant.move_to_next_index(0) # 对未访问的点进行插入,保证path是可行的 @@ -371,11 +372,15 @@ class MultipleAntColonySystem: while acs_vehicle_thread.is_alive() and acs_time_thread.is_alive(): # 如果在指定时间内没有搜索到更好的结果,则退出程序 - if time.time() - start_time_found_improved_solution > 60 * 5: + given_time = 5 + if time.time() - start_time_found_improved_solution > 60 * given_time: stop_event.set() print('*' * 50) - print('time is up: cannot find a better solution in given time') + print('time is up: cannot find a better solution in given time(%d minutes)' % given_time) print('it takes %0.3f second from multiple_ant_colony_system running' % (time.time()-start_time_total)) + print('the best path have found is:') + print(self.best_path) + print('best path distance is %f, best vehicle_num is %d' % (self.best_path_distance, self.best_vehicle_num)) print('*' * 50) return -- cgit v1.2.3