summaryrefslogtreecommitdiffstats
path: root/vrptw_base.py
diff options
context:
space:
mode:
authorJonZhao <[email protected]>2019-05-24 17:02:51 +0800
committerJonZhao <[email protected]>2019-05-24 17:02:51 +0800
commit3f9d51e66ecd44fef7595651c11bd424cea54ed9 (patch)
tree7df80f7edff1131a5ff8ddddcab3c32136efbbbb /vrptw_base.py
parent5ea43c019d6bc47d0d28f9768c38be635e846a36 (diff)
downloadVRPTW-ACO-python-3f9d51e66ecd44fef7595651c11bd424cea54ed9.tar.gz
VRPTW-ACO-python-3f9d51e66ecd44fef7595651c11bd424cea54ed9.tar.bz2
VRPTW-ACO-python-3f9d51e66ecd44fef7595651c11bd424cea54ed9.zip
在选择下一个结点的时候,考虑载重率、行驶距离等信息
Diffstat (limited to 'vrptw_base.py')
-rw-r--r--vrptw_base.py15
1 files changed, 2 insertions, 13 deletions
diff --git a/vrptw_base.py b/vrptw_base.py
index 2541842..1647bd9 100644
--- a/vrptw_base.py
+++ b/vrptw_base.py
@@ -65,11 +65,13 @@ class Ant:
self.travel_path = [0]
self.arrival_time = [0]
self.index_to_visit = list(range(1, node_num))
+ self.total_travel_distance = 0
def move_to_next_index(self, graph, vehicle_speed, next_index):
# 更新蚂蚁路径
self.travel_path.append(next_index)
self.arrival_time.append(self.current_time)
+ self.total_travel_distance += graph.node_dist_mat[self.current_index][next_index]
if next_index == 0:
# 如果一下个位置为服务器点,则要将车辆负载等清空
@@ -88,16 +90,3 @@ class Ant:
def index_to_visit_empty(self):
return len(self.index_to_visit) == 0
-
- def calculate_path_distance(self, graph: VPRTW_Graph):
- """
- 计算所有蚂蚁的行走路径的长度
- :param paths:
- :return:
- """
- distance = 0
- current_index = self.travel_path[0]
- for index in self.travel_path[1:]:
- distance += graph.node_dist_mat[current_index][index]
- current_index = index
- return distance