data.Graph
data.Graph(self)The Graph class represents a data structure of non-directed graphs.
Attributes
| Name | Type | Description |
|---|---|---|
| nodes | (list, readonly) | A list of psiclone.graph.Node objects. |
| edges | (list, readonly) | A list of psiclone.graph.Edge objects. |
| link_table | (dict, readonly) | A table that maps each node to a list of its adjacent __edges. |
Methods
| Name | Description |
|---|---|
| add_edge | Create and add an edge linking node1 and node2. |
| add_node | Create and add a node. |
| connected_components | Compute connected components. |
| create_edge | Factory method creating an Edge instance. |
| create_graph | Factory method of Graph. |
| create_node | Factory method creating a Node instance. |
| detach__edges | Make a node isolated so that each adjacent node is connected to a clone of the node. |
| find_walk | Find a path from src to dest. |
| invert_branch | Try to invert branch operation. Note that midnode is not removed. |
| reconnect | Replace a connected old_node by new_node in edge. |
| reduce | Reduce a node in the direction of an edge. |
| register_edge | Register the edge instance. |
| register_node | Register the node instance. |
| remove_edge | Remove the edge. |
| remove_node | Remove the node. |
| subgraph | Create a sub-graph made of given nodes. |
| walk_deeply | Walk from initial_node and apply fun to each node in a deep recursion. |
add_edge
data.Graph.add_edge(node1, node2, *args, **kwgs)Create and add an edge linking node1 and node2.
add_node
data.Graph.add_node(*args, **kwgs)Create and add a node.
connected_components
data.Graph.connected_components()Compute connected components.
Returns
| Name | Type | Description |
|---|---|---|
| components | list | A list of connected sub-graphs. |
create_edge
data.Graph.create_edge(node1, node2, *args, **kwgs)Factory method creating an Edge instance.
create_graph
data.Graph.create_graph()Factory method of Graph.
create_node
data.Graph.create_node(*args, **kwgs)Factory method creating a Node instance.
detach__edges { #psiclone.data.Graph.detach__edges }
data.Graph.detach__edges(node)Make a node isolated so that each adjacent node is connected to a clone of the node.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| node | psiclone.graph.Node |
A node to be detached. | required |
Returns
| Name | Type | Description |
|---|---|---|
| new__nodes | list | A list of __nodes cloned from the original node. |
find_walk
data.Graph.find_walk(src, dest)Find a path from src to dest.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| src | psiclone.graph.Node |
Source and destination nodes. | required |
| dest | psiclone.graph.Node |
Source and destination nodes. | required |
Returns
| Name | Type | Description |
|---|---|---|
| walk | (list, None) | A list of __edges that realizes the found path. None is returned if not found. |
invert_branch
data.Graph.invert_branch(branch1, branch2, midnode)Try to invert branch operation. Note that midnode is not removed.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| branch1 | psiclone.graph.Edge |
Edges connecting a common midnode. |
required |
| branch2 | psiclone.graph.Edge |
Edges connecting a common midnode. |
required |
| midnode | psiclone.graph.Node |
A common node connected with branch1 and branch2. |
required |
Returns
| Name | Type | Description |
|---|---|---|
| edge | psiclone.graph.Edge |
An edge recovered from branch1 and branch2. |
reconnect
data.Graph.reconnect(edge, old_node, new_node)Replace a connected old_node by new_node in edge.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| edge | psiclone.graph.Edge |
An edge to be reconnected. | required |
| old_node | psiclone.graph.Node |
Nodes to be replaced. | required |
| new_node | psiclone.graph.Node |
Nodes to be replaced. | required |
reduce
data.Graph.reduce(edge, needless_node)Reduce a node in the direction of an edge.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| edge | psiclone.graph.Edge |
An edge to be reduced. | required |
| needless_node | psiclone.graph.Node |
A node to be removed. | required |
register_edge
data.Graph.register_edge(edge)Register the edge instance.
register_node
data.Graph.register_node(node)Register the node instance.
remove_edge
data.Graph.remove_edge(edge)Remove the edge.
remove_node
data.Graph.remove_node(node)Remove the node.
subgraph
data.Graph.subgraph(nodes, edges=None)Create a sub-graph made of given nodes.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| nodes | list | A list of subgraph nodes. Not copied. | required |
| edges | list | A list of subgraph edges. Not copied. All the edges linking given nodes are used if omitted. | None |
Returns
| Name | Type | Description |
|---|---|---|
| other | psiclone.graph.Graph |
A graph made of given nodes. |
walk_deeply
data.Graph.walk_deeply(initial_node, fun)Walk from initial_node and apply fun to each node in a deep recursion.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| initial_node | psiclone.graph.Node |
A first node to visit. | required |
| fun | callable | A function with the signature fun(node, n) applied to each node. Parameters ———- node : psiclone.graph.Node Every node path-connected with initial_node. n : int >= 0 Recursion depth, or a path length, from initial_node. Note that this does not coincide with the shortest path length in general. |
required |