~ubuntu-branches/ubuntu/utopic/python-networkx/utopic

« back to all changes in this revision

Viewing changes to networkx/algorithms/components/weakly_connected.py

  • Committer: Package Import Robot
  • Author(s): Sandro Tosi
  • Date: 2012-08-11 12:41:30 UTC
  • mfrom: (1.4.1) (5.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20120811124130-whr6uso7fncyg8bi
Tags: 1.7-1
* New upstream release
* debian/patches/changeset_*
  - removed, included upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
 
45
45
def weakly_connected_component_subgraphs(G):
46
46
    """Return weakly connected components as subgraphs.
 
47
 
 
48
    Graph, node, and edge attributes are copied to the subgraphs.
47
49
    """
48
50
    wcc=weakly_connected_components(G)
49
51
    graph_list=[]
50
52
    for c in wcc:
51
 
        graph_list.append(G.subgraph(c))
 
53
        graph_list.append(G.subgraph(c).copy())
52
54
    return graph_list
53
55
 
54
56
def is_weakly_connected(G):
110
112
 
111
113
    seen={}                  # level (number of hops) when seen in BFS
112
114
    level=0                  # the current level
113
 
    nextlevel={source:1}  # dict of nodes to check at next level
 
115
    nextlevel = set([source]) # set of nodes to check at next level
114
116
    while nextlevel:
115
117
        thislevel=nextlevel  # advance to next level
116
 
        nextlevel={}         # and start a new list (fringe)
 
118
        nextlevel = set()         # and start a new list (fringe)
117
119
        for v in thislevel:
118
120
            if v not in seen:
119
121
                seen[v]=level # set the level of vertex v