Skip to content

utility

cosmica.experimental_packet_routing.utility

Utility functions for experimental packet routing.

__all__ module-attribute

__all__ = [
    "get_edge_data",
    "has_edge_bidirectional",
    "remove_edge_safe",
]

get_edge_data

get_edge_data(
    graph: Graph, u: Node, v: Node
) -> dict | None

Get edge data for either direction (u,v) or (v,u).

Source code in src/cosmica/experimental_packet_routing/utility.py
30
31
32
33
34
35
36
def get_edge_data(graph: Graph, u: Node, v: Node) -> dict | None:
    """Get edge data for either direction (u,v) or (v,u)."""
    if graph.has_edge(u, v):
        return graph.edges[u, v]
    elif graph.has_edge(v, u):
        return graph.edges[v, u]
    return None

has_edge_bidirectional

has_edge_bidirectional(
    graph: Graph, u: Node, v: Node
) -> bool

Check if edge exists in either direction (u,v) or (v,u).

Source code in src/cosmica/experimental_packet_routing/utility.py
14
15
16
def has_edge_bidirectional(graph: Graph, u: Node, v: Node) -> bool:
    """Check if edge exists in either direction (u,v) or (v,u)."""
    return graph.has_edge(u, v) or graph.has_edge(v, u)

remove_edge_safe

remove_edge_safe(graph: Graph, u: Node, v: Node) -> bool

Safely remove edge in either direction. Returns True if edge was removed.

Source code in src/cosmica/experimental_packet_routing/utility.py
19
20
21
22
23
24
25
26
27
def remove_edge_safe(graph: Graph, u: Node, v: Node) -> bool:
    """Safely remove edge in either direction. Returns True if edge was removed."""
    if graph.has_edge(u, v):
        graph.remove_edge(u, v)
        return True
    elif graph.has_edge(v, u):
        graph.remove_edge(v, u)
        return True
    return False