Ejemplo n.º 1
0
 def RunTest1(self):
     print("Test 1: ",
           len(dfs_predecessors(self.graphRev, 'shiny gold').keys()))
Ejemplo n.º 2
0
def _get_subgraph(full_graph, task_name):
    nodes_set = traversal.dfs_predecessors(full_graph.reverse(),
                                           task_name).keys()
    nodes_set.append(task_name)

    return full_graph.subgraph(nodes_set)
Ejemplo n.º 3
0
Programming The algorithm of Depth-First Traversal
'''
# def DFS_nodes(graph, node, visited=[]):
# visited.append(node)
# for neighbor in graph[node]:
# if not neighbor in visited:
# DFS_nodes(graph, neighbor, visited)
# return visited

# def DFS_edges(graph, node, visited=[], edges=[]):
# visited.append(node)
# for ni in graph[node]:
# if not ni in visited:
# edges.append((node, ni))
# DFS_edges(graph, ni, visited, edges)
# return edges

# print DFS_nodes(g, 2)    # choose node 0 as the starting point
# print DFS_edges(g, 2)
'''
DFS in NetworkX 
'''
print list(traversal.dfs_edges(g))
print traversal.dfs_successors(g)
print traversal.dfs_predecessors(g)
tree = traversal.dfs_tree(g)
tree.successors(0)
# tree.succ
net.draw(tree)
plt.show()
Ejemplo n.º 4
0
def _get_subgraph(full_graph, task_name):
    nodes_set = traversal.dfs_predecessors(full_graph.reverse(),
                                           task_name).keys()
    nodes_set.append(task_name)

    return full_graph.subgraph(nodes_set)