Skip to content

graph

Bases: base_topology

Represents a generic graph structure, inheriting from the base_topology class.

Parameters:

Name Type Description Default
name str

The name of the graph, by default 'graph'.

'graph'
*args tuple

Additional positional arguments to be passed to the base_topology class.

()
**kwargs dict

Additional keyword arguments to be passed to the base_topology class.

{}
Inherits From

base_topology The base class for topological structures.

Source code in tinybig/koala/topology/graph.py
class graph(base_topology):
    """
    Represents a generic graph structure, inheriting from the `base_topology` class.

    Parameters
    ----------
    name : str, optional
        The name of the graph, by default 'graph'.
    *args : tuple
        Additional positional arguments to be passed to the `base_topology` class.
    **kwargs : dict
        Additional keyword arguments to be passed to the `base_topology` class.

    Inherits From
    -------------
    base_topology
        The base class for topological structures.
    """
    def __init__(self, name: str = 'graph', *args, **kwargs):
        """
        Initializes a graph with the specified name.

        Parameters
        ----------
        name : str, optional
            The name of the graph, by default 'graph'.
        *args : tuple
            Additional positional arguments to be passed to the `base_topology` class.
        **kwargs : dict
            Additional keyword arguments to be passed to the `base_topology` class.
        """
        super().__init__(name=name, *args, **kwargs)

    def bfs(self, start=None, goal=None):
        """
        Performs a Breadth-First Search (BFS) traversal of the graph.

        Parameters
        ----------
        start : node, optional
            The starting node for the BFS traversal. If None, traversal starts from an arbitrary node.
        goal : node, optional
            The target node to search for. If None, the BFS traversal continues until all nodes are visited.

        Returns
        -------
        list
            A list of nodes representing the BFS traversal path or the path to the goal if specified.
        """
        pass

    def dfs(self, start=None, goal=None):
        """
        Performs a Depth-First Search (DFS) traversal of the graph.

        Parameters
        ----------
        start : node, optional
            The starting node for the DFS traversal. If None, traversal starts from an arbitrary node.
        goal : node, optional
            The target node to search for. If None, the DFS traversal continues until all nodes are visited.

        Returns
        -------
        list
            A list of nodes representing the DFS traversal path or the path to the goal if specified.
        """
        pass

    def radius(self):
        """
        Calculates the radius of the graph.

        Returns
        -------
        int
            The radius of the graph, defined as the minimum eccentricity of all nodes.

        Notes
        -----
        Eccentricity is the maximum distance from a node to any other node in the graph.
        """
        pass

    def shortest_path(self, start=None, goal=None):
        """
        Finds the shortest path between two nodes in the graph.

        Parameters
        ----------
        start : node, optional
            The starting node for the path. If None, raises a ValueError.
        goal : node, optional
            The target node for the path. If None, raises a ValueError.

        Returns
        -------
        list
            A list of nodes representing the shortest path from the start node to the goal node.

        Raises
        ------
        ValueError
            If either the `start` or `goal` node is None or not in the graph.
        """
        pass

__init__(name='graph', *args, **kwargs)

Initializes a graph with the specified name.

Parameters:

Name Type Description Default
name str

The name of the graph, by default 'graph'.

'graph'
*args tuple

Additional positional arguments to be passed to the base_topology class.

()
**kwargs dict

Additional keyword arguments to be passed to the base_topology class.

{}
Source code in tinybig/koala/topology/graph.py
def __init__(self, name: str = 'graph', *args, **kwargs):
    """
    Initializes a graph with the specified name.

    Parameters
    ----------
    name : str, optional
        The name of the graph, by default 'graph'.
    *args : tuple
        Additional positional arguments to be passed to the `base_topology` class.
    **kwargs : dict
        Additional keyword arguments to be passed to the `base_topology` class.
    """
    super().__init__(name=name, *args, **kwargs)

bfs(start=None, goal=None)

Performs a Breadth-First Search (BFS) traversal of the graph.

Parameters:

Name Type Description Default
start node

The starting node for the BFS traversal. If None, traversal starts from an arbitrary node.

None
goal node

The target node to search for. If None, the BFS traversal continues until all nodes are visited.

None

Returns:

Type Description
list

A list of nodes representing the BFS traversal path or the path to the goal if specified.

Source code in tinybig/koala/topology/graph.py
def bfs(self, start=None, goal=None):
    """
    Performs a Breadth-First Search (BFS) traversal of the graph.

    Parameters
    ----------
    start : node, optional
        The starting node for the BFS traversal. If None, traversal starts from an arbitrary node.
    goal : node, optional
        The target node to search for. If None, the BFS traversal continues until all nodes are visited.

    Returns
    -------
    list
        A list of nodes representing the BFS traversal path or the path to the goal if specified.
    """
    pass

dfs(start=None, goal=None)

Performs a Depth-First Search (DFS) traversal of the graph.

Parameters:

Name Type Description Default
start node

The starting node for the DFS traversal. If None, traversal starts from an arbitrary node.

None
goal node

The target node to search for. If None, the DFS traversal continues until all nodes are visited.

None

Returns:

Type Description
list

A list of nodes representing the DFS traversal path or the path to the goal if specified.

Source code in tinybig/koala/topology/graph.py
def dfs(self, start=None, goal=None):
    """
    Performs a Depth-First Search (DFS) traversal of the graph.

    Parameters
    ----------
    start : node, optional
        The starting node for the DFS traversal. If None, traversal starts from an arbitrary node.
    goal : node, optional
        The target node to search for. If None, the DFS traversal continues until all nodes are visited.

    Returns
    -------
    list
        A list of nodes representing the DFS traversal path or the path to the goal if specified.
    """
    pass

radius()

Calculates the radius of the graph.

Returns:

Type Description
int

The radius of the graph, defined as the minimum eccentricity of all nodes.

Notes

Eccentricity is the maximum distance from a node to any other node in the graph.

Source code in tinybig/koala/topology/graph.py
def radius(self):
    """
    Calculates the radius of the graph.

    Returns
    -------
    int
        The radius of the graph, defined as the minimum eccentricity of all nodes.

    Notes
    -----
    Eccentricity is the maximum distance from a node to any other node in the graph.
    """
    pass

shortest_path(start=None, goal=None)

Finds the shortest path between two nodes in the graph.

Parameters:

Name Type Description Default
start node

The starting node for the path. If None, raises a ValueError.

None
goal node

The target node for the path. If None, raises a ValueError.

None

Returns:

Type Description
list

A list of nodes representing the shortest path from the start node to the goal node.

Raises:

Type Description
ValueError

If either the start or goal node is None or not in the graph.

Source code in tinybig/koala/topology/graph.py
def shortest_path(self, start=None, goal=None):
    """
    Finds the shortest path between two nodes in the graph.

    Parameters
    ----------
    start : node, optional
        The starting node for the path. If None, raises a ValueError.
    goal : node, optional
        The target node for the path. If None, raises a ValueError.

    Returns
    -------
    list
        A list of nodes representing the shortest path from the start node to the goal node.

    Raises
    ------
    ValueError
        If either the `start` or `goal` node is None or not in the graph.
    """
    pass