kosmos.topology.net

Classes

class Network

Network that stores nodes and links.


Methods

add_node(node: kosmos.topology.node.Node) None

Add a node to the network.

Parameters:

node (Node) – Node instance to insert.

Add a link to the network.

Both endpoints of the link must be present in the network.

Parameters:

link (Link) – Link instance to insert.

get_node(node_id: kosmos.topology.node.NodeId | str) kosmos.topology.node.Node | None

Node by id.

Parameters:

node_id (NodeId | str) – Identifier of the node.

Returns:

The node if present, else None.

Return type:

Node | None

Link by id.

Parameters:

link_id (LinkId | str) – Identifier of the link.

Returns:

The link if present, else None.

Return type:

Link | None

nodes() collections.abc.Iterable[kosmos.topology.node.Node]

Iterate over all nodes.

Returns:

Iterator over nodes.

Return type:

Iterable[Node]

Iterate over all links.

Returns:

Iterator over links.

Return type:

Iterable[Link]

Outgoing links of a node.

Parameters:

node (NodeReference) – The node or its id.

Returns:

Outgoing links of the node.

Return type:

Iterable[Link]

Incoming links of a node.

Parameters:

node (NodeReference) – The node or its id.

Returns:

Incoming links of the node.

Return type:

Iterable[Link]

validate_node(node: kosmos.topology.typing.NodeReference) kosmos.topology.node.Node

Get the node for a node reference if it is valid, else raise.

Parameters:

node (NodeReference) – The node or its id.

Returns:

The valid node.

Return type:

Node

Get the link for a link reference if it is valid, else raise.

Parameters:

link (LinkReference) – The link or its id.

Returns:

The valid link.

Return type:

Link