summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonZhao <[email protected]>2019-06-05 15:45:16 +0800
committerJonZhao <[email protected]>2019-06-05 15:45:16 +0800
commit332f13fefb21cf47361562db42bac73ef608ec0d (patch)
tree1514b1540179818351aa9aff187931d0a6ee68ad
parent2ccd546062ac96fdf9e1e9229d8ec3df5997e928 (diff)
downloadVRPTW-ACO-python-332f13fefb21cf47361562db42bac73ef608ec0d.tar.gz
VRPTW-ACO-python-332f13fefb21cf47361562db42bac73ef608ec0d.tar.bz2
VRPTW-ACO-python-332f13fefb21cf47361562db42bac73ef608ec0d.zip
use limited vehicle num to initiate path in acs-vei
-rw-r--r--multiple_ant_colony_system.py4
-rw-r--r--vrptw_base.py10
2 files changed, 10 insertions, 4 deletions
diff --git a/multiple_ant_colony_system.py b/multiple_ant_colony_system.py
index 6dced28..751a441 100644
--- a/multiple_ant_colony_system.py
+++ b/multiple_ant_colony_system.py
@@ -233,7 +233,7 @@ class MultipleAntColonySystem:
global_best_distance = None
# 使用nearest_neighbor_heuristic算法初始化path 和distance
- current_path, current_path_distance, _ = new_graph.nearest_neighbor_heuristic()
+ current_path, current_path_distance, _ = new_graph.nearest_neighbor_heuristic(max_vehicle_num=vehicle_num)
# 找出当前path中未访问的结点
current_index_to_visit = list(range(new_graph.node_num))
@@ -373,7 +373,7 @@ class MultipleAntColonySystem:
while acs_vehicle_thread.is_alive() and acs_time_thread.is_alive():
# 如果在指定时间内没有搜索到更好的结果,则退出程序
- given_time = 5
+ given_time = 10
if time.time() - start_time_found_improved_solution > 60 * given_time:
stop_event.set()
self.print_and_write_in_file(file_to_write, '*' * 50)
diff --git a/vrptw_base.py b/vrptw_base.py
index 52cdafa..30c20de 100644
--- a/vrptw_base.py
+++ b/vrptw_base.py
@@ -96,14 +96,18 @@ class VrptwGraph:
self.pheromone_mat[current_ind][next_ind] += self.rho/best_path_distance
current_ind = next_ind
- def nearest_neighbor_heuristic(self):
+ def nearest_neighbor_heuristic(self, max_vehicle_num=None):
index_to_visit = list(range(1, self.node_num))
current_index = 0
current_load = 0
current_time = 0
travel_distance = 0
travel_path = [0]
- while len(index_to_visit) > 0:
+
+ if max_vehicle_num is None:
+ max_vehicle_num = self.node_num
+
+ while len(index_to_visit) > 0 and max_vehicle_num > 0:
nearest_next_index = self._cal_nearest_next_index(index_to_visit, current_index, current_load, current_time)
if nearest_next_index is None:
@@ -113,6 +117,8 @@ class VrptwGraph:
current_time = 0
travel_path.append(0)
current_index = 0
+
+ max_vehicle_num -= 1
else:
current_load += self.nodes[nearest_next_index].demand