Skip to content
Snippets Groups Projects
Commit 8dedf25b authored by crides's avatar crides
Browse files

analysis_tree: add `visualize` method

The `visualize` method uses the `networkx` to graph the nodes as a tree.
Each node in the tree is currently shown with its ID and start time

closes one half of #19
parent 2057f981
No related branches found
No related tags found
1 merge request!21Arch2023 merged
......@@ -7,6 +7,9 @@ import numpy.typing as nptyp, numpy as np, portion
from verse.analysis.dryvr import _EPSILON
import networkx as nx
import matplotlib.pyplot as plt
TraceType = nptyp.NDArray[np.float_]
class AnalysisTreeNode:
......@@ -226,3 +229,14 @@ class AnalysisTree:
total_len = len(other_tree[min_agents[0]])
# bloat and containment
return all(other_tree[aid][i][j] in this_tree[aid][i][j].apply(lambda x: x.replace(lower=lambda v: v - tol, upper=lambda v: v + tol)) for aid in other_agents for i in range(total_len) for j in range(cont_num))
def visualize(self):
G = nx.Graph()
for node in self.nodes:
G.add_node(node.id,time=(node.id,node.start_time))
for child in node.child:
G.add_node(child.id,time=(child.id,child.start_time))
G.add_edge(node.id, child.id)
labels = nx.get_node_attributes(G, 'time')
nx.draw_planar(G,labels=labels)
plt.show()
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