def find_all_paths()

in graph/utils/heron.py [0:0]


def find_all_paths(parent_to_child, start, path=[], path_dict=defaultdict()):
    """This is a recursive function that finds all paths from the given start node to
    sinks and returns them."""
    p = path.copy()
    p.append(start)
    if start not in parent_to_child:
        return p, path_dict
    paths = []
    for node in parent_to_child[start]:
        if node in path_dict:
            new_paths = path_dict[node]
        else:
            new_paths, path_dict = find_all_paths(parent_to_child, node, p, path_dict)
            path_dict[node] = new_paths.copy()
        if type(new_paths[0]) is int:
            # there is only one downstream path from current node
            paths.append(new_paths)
        else:
            # there are multiple downstream paths from current node
            for new_path in new_paths:
                paths.append(new_path)
    # LOG.info("Returning paths for node: %d", start)
    return paths, path_dict