diff --git a/trajectories.py b/trajectories.py index 21c09ac23657c480c0947a1166ab412ec3fc4cc8..d1e49597f3bf55004df620ac1f1dc44dcd14af3c 100755 --- a/trajectories.py +++ b/trajectories.py @@ -3,7 +3,7 @@ """A script that loads a segmented cf graph in the gt format, iterates on all of the edges and cost functions and generates the trajectories as done in MATLAB. Segments (nodes) have a new vertex property called -"traj" that holds the trajectory ID that that segment belongs to. The +"traj_prop" that holds the trajectory ID that that segment belongs to. The output is either an expanded JSON file and/or an edgelist file with all of the trajectories. @@ -26,17 +26,17 @@ class Visitor(search.BFSVisitor): self.trajectories = {} def discover_vertex(self, u): - if g.vp.traj[u] not in self.trajectories: - self.trajectories[g.vp.traj[u]] = [g.vp.name[u]] + if traj_prop[u] not in self.trajectories: + self.trajectories[traj_prop[u]] = [g.vp.name[u]] else: - self.trajectories[g.vp.traj[u]].append(g.vp.name[u]) + self.trajectories[traj_prop[u]].append(g.vp.name[u]) g = graph_tool.load_graph(sys.argv[1]) -g.vp['traj'] = g.new_vp('int') +traj_prop = g.new_vp('int') # Assign the new vertex property: for node in g.vertices(): - g.vp.traj[node] = g.vp.name[node] + traj_prop[node] = g.vp.name[node] print('Setting trajectory vertex property...') @@ -52,17 +52,17 @@ for edge in g.edges(): if current_cf <= min({g.ep.cost_function[e] for e in trg.out_edges()}): # Set trg trajectory to src trajectory - g.vp.traj[trg] = g.vp.traj[src] + traj_prop[trg] = traj_prop[src] else: - g.vp.traj[trg] = g.vp.traj[src] + traj_prop[trg] = traj_prop[src] else: # src.out_degree() == 1 if trg.in_degree() > 1: if current_cf <= min({g.ep.cost_function[e] for e in trg.in_edges()}): - g.vp.traj[trg] = g.vp.traj[src] + traj_prop[trg] = traj_prop[src] else: - g.vp.traj[trg] = g.vp.traj[src] + traj_prop[trg] = traj_prop[src] print('Creating the dictionary of trajectories...') visitor = Visitor()