diff options
| author | JonZhao <[email protected]> | 2019-05-29 11:21:19 +0800 |
|---|---|---|
| committer | JonZhao <[email protected]> | 2019-05-29 11:21:19 +0800 |
| commit | 8d459d62b4deed1212f613cad1967b36ca385d5a (patch) | |
| tree | 7e34f4374c753d637ba45c5b6ea973e84b5a79cf /vrptw_base.py | |
| parent | 7dd68707124da17bc0de801de4c690be515926ab (diff) | |
| download | VRPTW-ACO-python-8d459d62b4deed1212f613cad1967b36ca385d5a.tar.gz VRPTW-ACO-python-8d459d62b4deed1212f613cad1967b36ca385d5a.tar.bz2 VRPTW-ACO-python-8d459d62b4deed1212f613cad1967b36ca385d5a.zip | |
1. add reference
2. fix some error in macs calculate next index
3. add comment
Diffstat (limited to 'vrptw_base.py')
| -rw-r--r-- | vrptw_base.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/vrptw_base.py b/vrptw_base.py index 645b114..988713e 100644 --- a/vrptw_base.py +++ b/vrptw_base.py @@ -32,7 +32,7 @@ class VrptwGraph: self.rho = rho # 创建信息素矩阵 - self.nnh_travel_path, self.init_pheromone_val = self.nearest_neighbor_heuristic() + self.nnh_travel_path, self.init_pheromone_val, _ = self.nearest_neighbor_heuristic() self.init_pheromone_val = 1/(self.init_pheromone_val * self.node_num) self.pheromone_mat = np.ones((self.node_num, self.node_num)) * self.init_pheromone_val @@ -129,7 +129,9 @@ class VrptwGraph: # 最后要回到depot travel_distance += self.node_dist_mat[current_index][0] travel_path.append(0) - return travel_path, travel_distance + + vehicle_num = travel_path.count(0)-1 + return travel_path, travel_distance, vehicle_num def _cal_nearest_next_index(self, index_to_visit, current_index, current_load, current_time): """ @@ -166,6 +168,7 @@ class PathMessage: def __init__(self, path, distance): self.path = copy.deepcopy(path) self.distance = copy.deepcopy(distance) + self.used_vehicle_num = self.path.count(0) - 1 def get_path_info(self): - return self.path, self.distance + return self.path, self.distance, self.used_vehicle_num |
