graphit/graph_algorithms.py
def dfs_paths(graph, start, goal, method='dfs'):
    """
    Return all possible paths between two nodes.
    
    Setting method to 'bfs' returns the shortest path first
    
    :param graph:     graph to search
    :type graph:      graph class instance
    :param start:     root node to start the search from
    :type start:      :py:int
    :param goal:      target node
    :type goal:       :py:int
    :param method:    search method. Depth-first search (dfs, default)
                      and Breath-first search (bfs) supported.
    :type method:     :py:str
    
    :rtype:           :py:list
    """
    
    # Define the search method
    stack_pop = -1
    if method == 'bfs':
        stack_pop = 0
    
    stack = [(start, [start])]
    while stack:
        (vertex, path) = stack.pop(stack_pop)
        neighbors = node_neighbors(graph, vertex)
        for next_node in set(neighbors) - set(path):
            if next_node == goal:
                yield path + [next_node]
            else:
                stack.append((next_node, path + [next_node]))

    Return all possible paths between two nodes.
    
    Setting method to 'bfs' returns the shortest path first
    
    :param graph:     graph to search
    :type graph:      graph class instance
    :param start:     root node to start the search from
    :type start:      :py:int
    :param goal:      target node
    :type goal:       :py:int
    :param method:    search method. Depth-first search (dfs, default)
                      and Breath-first search (bfs) supported.
    :type method:     :py:str
    
    :rtype:           :py:list
    
Return all possible paths between two nodes.
Setting method to 'bfs' returns the shortest path first
Return all possible paths between two nodes . Setting method to ' bfs ' returns the shortest path first
def dfs_paths(graph, start, goal, method='dfs'):
    stack_pop = -1
    if method == 'bfs':
        stack_pop = 0
    stack = [(start, [start])]
    while stack:
        (vertex, path) = stack.pop(stack_pop)
        neighbors = node_neighbors(graph, vertex)
        for next_node in set(neighbors) - set(path):
            if next_node == goal:
                yield path + [next_node]
            else:
                stack.append((next_node, path + [next_node]))
def dfs_paths ( graph , start , goal , method = 'dfs' ) : stack_pop = - 1 if method == 'bfs' : stack_pop = 0 stack = [ ( start , [ start ] ) ] while stack : ( vertex , path ) = stack . pop ( stack_pop ) neighbors = node_neighbors ( graph , vertex ) for next_node in set ( neighbors ) - set ( path ) : if next_node == goal : yield path + [ next_node ] else : stack . append ( ( next_node , path + [ next_node ] ) )
Return all possible paths between two nodes.
Return all possible paths between two nodes .
"""
    Return all possible paths between two nodes.
    
    Setting method to 'bfs' returns the shortest path first
    
    :param graph:     graph to search
    :type graph:      graph class instance
    :param start:     root node to start the search from
    :type start:      :py:int
    :param goal:      target node
    :type goal:       :py:int
    :param method:    search method. Depth-first search (dfs, default)
                      and Breath-first search (bfs) supported.
    :type method:     :py:str
    
    :rtype:           :py:list
    """ # Define the search method
None
:py:list
graph
graph to search
graph to search
start
root node to start the search from
root node to start the search from
goal
None
method
search method. Depth-first search (dfs, default)
and Breath-first search (bfs) supported.
search method . Depth - first search ( dfs default ) and Breath - first search ( bfs ) supported .