Node

Tree Node Class

class constrainthg.hypergraph.TNode(label: str, node_label: str, value=None, children: list = None, cost: float = None, trace: list = None, gen_edge_label: str = None, gen_edge_cost: float = 0.0, join_status: str = 'None', max_display_length: int = 12)

Bases: object

A basic tree node for printing tree structures.

__init__(label: str, node_label: str, value=None, children: list = None, cost: float = None, trace: list = None, gen_edge_label: str = None, gen_edge_cost: float = 0.0, join_status: str = 'None', max_display_length: int = 12)

Creates the root of a search tree.

Parameters:
  • label (str) – A unique identifier for the TNode, necessary for pathfinding.

  • node_label (str) – A string identifying the node represented by the TNode.

  • value (Any, optional) – The value of the tree solved to the TNode.

  • children (list, optional) – TNodes that form the source nodes of an edge leading to the TNode.

  • cost (float, optional) – Value indicating the cost of solving the tree rooted at the TNode.

  • trace (list, optional) – Top down trace of how the TNode could be resolved, used for path exploration.

  • gen_edge_label (str, optional) – A unique label for the edge generating the TNode (of which children are source nodes).

  • gen_edge_cost (float, default=0.) – Value for weight (cost) of the generating edge, default is 0.0.

  • join_status (str, optional) – Indicates if the TNode is the last of a set of children, used for printing.

  • max_display_length (int, default=12) – The maximum characters to display for the value of the node.

Properties

indexint

The maximum times the TNode or any child TNodes are repeated in the tree.

valuesdict

The values of all the child TNodes of the form {label : [Any,]}.

class conn

Bases: object

A class of connectors used for indicating child nodes.

blank = '   '
elbow = '└──'
elbow_join = '└◯─'
elbow_stop = '└●─'
pipe = '│  '
tee = '├──'
tee_join = '├◯─'
tee_stop = '├●─'
property cost: float

The total sum of the weights of each edge in the tree.

get_conn(last=True) str

Selecter function for the connector string on the tree print.

get_descendents() list

Returns a list of child nodes on all depths (includes self).

get_tree(last=True, header='', checked_edges: list = None) str

Returns the tree centered at the TNode as a str.

Adapted from https://stackoverflow.com/a/76691030/15496939, PierreGtch, under CC BY-SA 4.0.

get_tree_cost(root=None, checked_edges: set = None) float

Returns the cost of solving to the leaves of the tree.

Node Class

class constrainthg.hypergraph.Node(label: str, static_value=None, generating_edges: set = None, leading_edges: set = None, super_nodes: set = None, sub_nodes: set = None, description: str = None, units: str = None)

Bases: object

A value in the hypergraph, equivalent to a wired connection.

__init__(label: str, static_value=None, generating_edges: set = None, leading_edges: set = None, super_nodes: set = None, sub_nodes: set = None, description: str = None, units: str = None)

Creates a new Node object.

Parameters:
  • label (str) – A unique identifier for the node.

  • static_value (Any, optional) – The constant value of the node, set as an input.

  • generating_edges (set, optional) – A set of edges that have the node as their target.

  • leading_edges (set, optional) – A set of edges that have the node as one their sources.

  • super_nodes (Set[Node], optional) – A set of nodes that have this node as a subset, see note [1].

  • sub_nodes (Set[Node], optional) – A set of nodes that that have this node as a super node, see note [1].

  • description (str, optional) – A description of the node useful for debugging.

  • units (str, optional) – Units of value.

  • starting_index (int, default=1) – The starting index of the node.

Properties

is_constantbool

Describes whether the node should be reset in between simulations.

Notes

1. The subsetting accomplished by super_nodes is best conducted using via functions on the edge, as these will be executed for every node value. One case where this is impossible is when the node has leading edges when generated by a certain generating edge. In this case the via function cannot be used as the viability is edge dependent, not value dependent. Super nodes are provided for this purpose, though do not provide full functionality. When searching, the leading edges of each super node are added to the search queue as a valid path away from the node.

to_dict() dict

Returns a dict representation of the Node object.

to_json() str

Returns a JSON representation of the Node object.

static union(a, *args)

Performs a deep union of the two nodes, replacing values of a with those of b where necessary.

Home | Index | Search