From bcbb5547ffdccb832b6301b4252d43fa0f832721 Mon Sep 17 00:00:00 2001 From: hagrid67 <jdhwatson@gmail.com> Date: Fri, 14 Aug 2020 13:58:49 +0100 Subject: [PATCH] performance fix for agent_chains, reduce the calls to G.reverse() --- flatland/envs/agent_chains.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/flatland/envs/agent_chains.py b/flatland/envs/agent_chains.py index ac3f9135..e3f47e42 100644 --- a/flatland/envs/agent_chains.py +++ b/flatland/envs/agent_chains.py @@ -74,20 +74,20 @@ class MotionCheck(object): #print("Component:", oWCC) Gwcc = self.G.subgraph(oWCC) - #lChain = list(nx.topological_sort(Gwcc)) - #print("path: ", lChain) - # Find all the stops in this chain svCompStops = svStops.intersection(Gwcc) #print(svCompStops) if len(svCompStops) > 0: - #print("component contains a stop") + + # We need to traverse it in reverse - back up the movement edges + Gwcc_rev = Gwcc.reverse() for vStop in svCompStops: - - iter_stops = nx.algorithms.traversal.dfs_postorder_nodes(Gwcc.reverse(), vStop) + + # Find all the agents stopped by vStop by following the (reversed) edges + # This traverses a tree - dfs = depth first seearch + iter_stops = nx.algorithms.traversal.dfs_postorder_nodes(Gwcc_rev, vStop) lStops = list(iter_stops) - #print(vStop, "affected preds:", lStops) svBlocked.update(lStops) return svBlocked -- GitLab