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

Bug fix: traverse the graph in chronological order

So that segments in a trajectory are in chronological order.
parent 6aef09ea
No related branches found
No related tags found
No related merge requests found
......@@ -18,9 +18,16 @@ import graph_tool
from os import path
import json
import csv
from graph_tool import util
from graph_tool import util, search
import sys
class Visitor(search.BFSVisitor):
def discover_vertex(self, u):
if g.vp.traj[u] not in trajectories:
trajectories[g.vp.traj[u]] = [g.vp.name[u]]
else:
trajectories[g.vp.traj[u]].append(g.vp.name[u])
g = graph_tool.load_graph(sys.argv[1])
g.vp['traj'] = g.new_vp('int')
......@@ -59,12 +66,7 @@ print('Algorithm done, saving...')
# Make a dictionary of trajectories:
trajectories = {}
for node in g.vertices():
if g.vp.traj[node] not in trajectories:
trajectories[g.vp.traj[node]] = [g.vp.name[node]]
else:
trajectories[g.vp.traj[node]].append(g.vp.name[node])
search.bfs_search(g, visitor = Visitor())
with open("trajectories.json", "w") as outfile:
json.dump(trajectories, outfile, indent = 4)
......
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