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

Accept more general input

Accept input graph of segments without cost functions and accept
absence of file `traj_segm.json`.
parent 531e64c6
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
"""Reads a graph of segments with cost functions and creates the
corresponding Graphviz file, coloring the segments in red."""
"""This script reads a graph of segments and creates the corresponding
Graphviz file. If the segments have cost functions then the width of
an edge is inversely proportionnal to the cost function. If the file
traj_segm.json is found then the trajectories are colored in red.
"""
import graph_tool
import sys
......@@ -20,15 +24,22 @@ for v in g_in.vertices():
for e in g_in.edges():
source = e.source()
target = e.target()
g_out.add_edge(g_in.vp.name[source], g_in.vp.name[target],
penwidth = 10 / g_in.ep.cost_function[e])
with open("traj_segm.json") as f: traj_segm = json.load(f)
for segment_list in traj_segm:
for i in range(len(segment_list) - 1):
e = g_out.get_edge(segment_list[i], segment_list[i + 1])
e.attr["color"] = "red"
try:
g_out.add_edge(g_in.vp.name[source], g_in.vp.name[target],
penwidth = 10 / g_in.ep.cost_function[e])
except AttributeError:
g_out.add_edge(g_in.vp.name[source], g_in.vp.name[target])
try:
with open("traj_segm.json") as f: traj_segm = json.load(f)
except FileNotFoundError:
print("traj_segm.json not found")
print("Will not color trajectories.")
else:
for segment_list in traj_segm:
for i in range(len(segment_list) - 1):
e = g_out.get_edge(segment_list[i], segment_list[i + 1])
e.attr["color"] = "red"
g_out.write(sys.argv[2])
......
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