From 3f9d51e66ecd44fef7595651c11bd424cea54ed9 Mon Sep 17 00:00:00 2001 From: JonZhao <1044264932@qq.com> Date: Fri, 24 May 2019 17:02:51 +0800 Subject: 在选择下一个结点的时候,考虑载重率、行驶距离等信息 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vrptw_base.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'vrptw_base.py') 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 -- cgit v1.2.3