Skip to content
Snippets Groups Projects
Commit 86e7612c authored by Lionel GUEZ's avatar Lionel GUEZ
Browse files

Use property map for in-degree

We know that we are going to need in-degree for every node of the
graph. For `Global_1993_2023/Graph_anti`, this commit reduces the time
to define `traj_prop` from 31 s to 25 s.
parent 99d5a5a7
No related branches found
No related tags found
No related merge requests found
......@@ -75,6 +75,7 @@ traj_vert_ind = []
# An element of traj_vert_ind is a trajectory, represented by a list
# of vertex indices.
in_deg_prop = g.degree_property_map("in")
# Loop to define traj_prop:
for n in topology.topological_sort(g):
......@@ -84,10 +85,10 @@ for n in topology.topological_sort(g):
# immediately followed by merging. We do not want to let phantom
# patterns interrupt trajectories.
if g.vertex(n).in_degree() == 2:
if in_deg_prop[n] == 2:
pred = g.get_in_neighbors(n)
if np.all(g.get_in_degrees(pred) == 1) \
if in_deg_prop[pred[0]] == 1 == in_deg_prop[pred[1]] \
and np.all(g.get_out_degrees(pred) == 1):
n1 = g.get_in_neighbors(pred[0])[0]
n2 = g.get_in_neighbors(pred[1])[0]
......@@ -132,7 +133,7 @@ for n in topology.topological_sort(g):
traj_vert_ind[traj_prop[n1]].append(n)
if traj_prop[n] == - 1:
if g.vertex(n).in_degree() >= 1:
if in_deg_prop[n] >= 1:
# Find the index of the closest direct predecessor of a node:
# head of the in-edge with smallest cost.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment