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

dump tree

parent caa88220
No related branches found
No related tags found
1 merge request!9Tutorial
......@@ -103,15 +103,17 @@ if __name__ == "__main__":
time = timeit.default_timer()
traces = scenario.simulate(60, 0.05)
print("\x1b[31mrun1\x1b[0m", timeit.default_timer() - time)
traces.dump_tree()
fig = go.Figure()
fig = simulation_tree(traces, tmp_map, fig, 1,
2, 'lines', 'trace', print_dim_list=[1, 2])
fig.show()
time = timeit.default_timer()
traces = scenario.simulate(60, 0.05)
print("\x1b[31mrun2\x1b[0m", timeit.default_timer() - time)
fig = go.Figure()
fig = simulation_tree(traces, tmp_map, fig, 1,
2, 'lines', 'trace', print_dim_list=[1, 2])
fig.show()
# time = timeit.default_timer()
# traces = scenario.simulate(60, 0.05)
# print("\x1b[31mrun2\x1b[0m", timeit.default_timer() - time)
# traces.dump_tree()
# fig = go.Figure()
# fig = simulation_tree(traces, tmp_map, fig, 1,
# 2, 'lines', 'trace', print_dim_list=[1, 2])
# fig.show()
from typing import List, Dict, Any
import json
from treelib import Tree
class AnalysisTreeNode:
"""AnalysisTreeNode class
......@@ -122,3 +123,20 @@ class AnalysisTree:
parent_node.child.append(child_node)
queue.append((child_node_dict, child_node))
return AnalysisTree(root)
def dump_tree(self):
tree = Tree()
AnalysisTree._dump_tree(self.root, tree, 0, 1)
tree.show()
@staticmethod
def _dump_tree(node, tree, pid, id):
n = "\n".join(str((aid, *node.mode[aid], *node.init[aid])) for aid in node.agent)
if pid != 0:
tree.create_node(n, id, parent=pid)
else:
tree.create_node(n, id)
nid = id + 1
for child in node.child:
nid = AnalysisTree._dump_tree(child, tree, id, nid)
return nid + 1
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