Skip to content

Graph

A module representing an abstract Graph base class.

Graph

An abstract graph data structure.

Source code in maestrowf/abstracts/graph.py
@six.add_metaclass(ABCMeta)
class Graph:
    """An abstract graph data structure."""

    # NOTE: fdinatal -- 04/07/2017
    # This class mandates that a graph class be searchable currently.
    # That requirement should be filtered out into another abstract interface
    # most likely (think C# interfaces). I could imagine cases where a coder/
    # developer would want a leaner object without the frills.

    @abstractmethod
    def add_node(self, name, obj):
        """
        Method to add a node to the graph.

        :param name: String identifier of the node.
        :param obj: An object representing the value of the node.
        """

    @abstractmethod
    def add_edge(self, src, dest):
        """
        Add the edge (src, dest) to the graph.

        :param src: Source vertex name.
        :param dest: Destination vertex name.
        """

    @abstractmethod
    def remove_edge(self, src, dest):
        """
        Remove edge (src, dest) from the graph.

        :param src: Source vertex name.
        :param dest: Destination vertex name.
        """

add_edge(src, dest) abstractmethod

Add the edge (src, dest) to the graph.

Parameters:

Name Type Description Default
src

Source vertex name.

required
dest

Destination vertex name.

required
Source code in maestrowf/abstracts/graph.py
@abstractmethod
def add_edge(self, src, dest):
    """
    Add the edge (src, dest) to the graph.

    :param src: Source vertex name.
    :param dest: Destination vertex name.
    """

add_node(name, obj) abstractmethod

Method to add a node to the graph.

Parameters:

Name Type Description Default
name

String identifier of the node.

required
obj

An object representing the value of the node.

required
Source code in maestrowf/abstracts/graph.py
@abstractmethod
def add_node(self, name, obj):
    """
    Method to add a node to the graph.

    :param name: String identifier of the node.
    :param obj: An object representing the value of the node.
    """

remove_edge(src, dest) abstractmethod

Remove edge (src, dest) from the graph.

Parameters:

Name Type Description Default
src

Source vertex name.

required
dest

Destination vertex name.

required
Source code in maestrowf/abstracts/graph.py
@abstractmethod
def remove_edge(self, src, dest):
    """
    Remove edge (src, dest) from the graph.

    :param src: Source vertex name.
    :param dest: Destination vertex name.
    """