Skip to content

GraphAlgo pyDocs

shaCode256 edited this page Mar 4, 2021 · 1 revision

class GraphAlgo(GraphAlgoInterface):

"""This abstract class represents an interface of a graph algotirhms class."""

     def __init__(self, graph=myGraph):  # , graph: DiGraph):
    """
   Init the graph on which this set of algorithms operates on.
    """

   def get_graph(self) -> DiGraph:
    """
   :return: the directed graph on which the algorithm works on.
    """

   def load_from_json(self, file_name: str) -> bool:
    """
    Loads a graph from a json file.
    @param file_name: The path to the json file
    @returns True if the loading was successful, False o.w.
    """

    def save_to_json(self, file_name: str) -> bool:
     """
    Saves the graph in JSON format to a file
    @param file_name: The path to the out file
    @return: True if the save was successful, Flase o.w.
    """

   def shortest_path_list(self, src, dest):
    """     returns the shortest path between src to dest - as an ordered List of nodes"""

   def shortest_path_dist(self, src, dest):
   """returns the length of the shortest path between src to dest"""

def shortest_path(self, id1: int, id2: int) -> (float, list):
"""
Returns the shortest path from node id1 to node id2 using Dijkstra's Algorithm
@param id1: The start node id
@param id2: The end node id
@return: The distance of the path, a list of the nodes ids that the path goes through
"""

    def connected_component(self, id1: int) -> list:
    """
    Finds the Strongly Connected Component(SCC) that node id1 is a part of him.
    @param id1: The node id
    @return: The list of nodes in the SCC
    """

def connected_components(self) -> List[list]:
   """
    Finds all the Strongly Connected Component(SCC) in the graph.
    @return: The list all SCC
    """

def bfs(self, g: DiGraph(), id1: int, has_family: dict) -> list:
"""BFS algorithm: this method operates BFS twice: one for the original graph, and the
second time for reverse graph. After this time we get SCC for specific node"""

def plot_graph(self) -> None:
"""
    Plots the graph.
    If the nodes have a position, the nodes will be placed there.
    Otherwise, they will be placed in a random but elegant manner.
    @return: None
"""
Clone this wiki locally