finesse.tree module
Tree data structure.
- class finesse.tree.TreeNode(str name, TreeNode parent=None, bool empty=True, str edge_info=None)[source]
Bases:
objectContainer for tree-like structures.
Tree nodes can contain other tree nodes, allowing these objects to be built into a tree-like hierarchy useful for representing connections between components, nested data sets, etc.
Parameters
- namestr
The node name.
- parent:
TreeNode, optional The parent tree node, if not the root.
- emptybool, optional
Whether this node is considered “empty”, which determines which character to use to represent the node in the tree; defaults to True.
- edge_infostr, optional
String information on how this node is connected to its parent node. Will be used in
TreeNode.draw_tree()
- children
children: list
- draw_tree(self, fn_name=None, title=None, show_max_children=None)[source]
Draws the solution tree in text form.
Based on https://stackoverflow.com/a/49638425/2251982.
Parameters
- fn_namecallable, optional
Function to return the name of a
TreeNodegiven theTreeNodeitself. Defaults to usingTreeNode.name.- titlestr, optional
The tree title. If not specified, no title is printed.
- show_max_childrenint, optional
Maximum number of children to show in the tree; defaults to showing all children.
Returns
- str
The tree in textual form.
- edge_info
edge_info: str
- empty
empty: ‘bool’
- classmethod from_network(cls, network, root)[source]
Create a tree node hierarchy from an acyclic network.
Notes
Cyclic networks are handled by
networkx.algorithms.traversal.depth_first_search.dfs_tree(), so this method does not need to detect and avoid such cycles.Parameters
- network
networkx.Graph The network that is to be represented as a tree.
- roothashable
The network node to use as the root of the tree.
Raises
- ValueError
When the specified network is not a forest.
- network
- parent
parent: finesse.tree.TreeNode