def test_attracting_component_subgraphs(self): subgraphs = nx.attracting_component_subgraphs(self.G1) for subgraph in subgraphs: assert_equal(len(subgraph), 1) subgraphs = nx.attracting_component_subgraphs(self.G2) assert_equal(len(subgraphs), 1) assert_true(1 in subgraphs[0]) assert_true(2 in subgraphs[0])
def test_attracting_component_subgraphs(self): subgraphs = nx.attracting_component_subgraphs(self.G1) for subgraph in subgraphs: assert_equal(len(subgraph), 1) self.G2.add_edge(1, 2, eattr='red') # test attrs copied to subgraphs self.G2.node[2]['nattr'] = 'blue' self.G2.graph['gattr'] = 'green' subgraphs = nx.attracting_component_subgraphs(self.G2) assert_equal(len(subgraphs), 1) SG2 = subgraphs[0] assert_true(1 in SG2) assert_true(2 in SG2) assert_equal(SG2[1][2]['eattr'], 'red') assert_equal(SG2.node[2]['nattr'], 'blue') assert_equal(SG2.graph['gattr'], 'green') SG2.add_edge(1, 2, eattr='blue') assert_equal(SG2[1][2]['eattr'], 'blue') assert_equal(self.G2[1][2]['eattr'], 'red')
def test_attracting_component_subgraphs(self): subgraphs = nx.attracting_component_subgraphs(self.G1) for subgraph in subgraphs: assert_equal(len(subgraph), 1) self.G2.add_edge(1,2,eattr='red') # test attrs copied to subgraphs self.G2.node[2]['nattr']='blue' self.G2.graph['gattr']='green' subgraphs = nx.attracting_component_subgraphs(self.G2) assert_equal(len(subgraphs), 1) SG2=subgraphs[0] assert_true(1 in SG2) assert_true(2 in SG2) assert_equal(SG2[1][2]['eattr'],'red') assert_equal(SG2.node[2]['nattr'],'blue') assert_equal(SG2.graph['gattr'],'green') SG2.add_edge(1,2,eattr='blue') assert_equal(SG2[1][2]['eattr'],'blue') assert_equal(self.G2[1][2]['eattr'],'red')
print 'The number of attracting components of G is:', nx.number_attracting_components( G) print str(" ") print 'List of attracting components:' print sorted(nx.attracting_components(G), key=len, reverse=True) print str(" ") lc = sorted(nx.strongly_connected_components(G), key=len, reverse=True) print 'List of strongly connected components:' print lc print str(" ") colors_list = ['c', 'b', 'g', 'y', 'k', 'm'] colors_to_select = list(colors_list) graphs = sorted(nx.attracting_component_subgraphs(G), key=len, reverse=True) attracting_component_subgraphs_edges = [] attracting_component_subgraphs_nodes = [] nodes_color_alpha = [] edges_color_alpha = [] colors_of_edges = [] edge_width_l = [] attracting_component_subgraphs_edges_one_mode = [] attracting_component_subgraphs_nodes_one_mode = [] nodes_color_alpha = [] edges_color_alpha = [] colors_of_edges = [] edge_width_l = [] graphs_labels = dict() graphs_lists = dict() for gr in range(len(graphs)):
print 'Does the graph G consist of a single attracting component?', nx.is_attracting_component(G) print 'The number of attracting components of G is:', nx.number_attracting_components(G) print str(" ") print 'List of attracting components:' print sorted(nx.attracting_components(G), key = len, reverse=True) print str(" ") lc=sorted(nx.strongly_connected_components(G), key = len, reverse=True) print 'List of strongly connected components:' print lc print str(" ") colors_list=['c','b','g','y','k','m'] colors_to_select=list(colors_list) graphs =sorted(nx.attracting_component_subgraphs(G), key = len, reverse=True) attracting_component_subgraphs_edges=[] attracting_component_subgraphs_nodes=[] nodes_color_alpha=[] edges_color_alpha=[] colors_of_edges=[] edge_width_l=[] attracting_component_subgraphs_edges_one_mode=[] attracting_component_subgraphs_nodes_one_mode=[] nodes_color_alpha=[] edges_color_alpha=[] colors_of_edges=[] edge_width_l=[] graphs_labels=dict() graphs_lists=dict() for gr in range(len(graphs)):
import networkx import sys graph = networkx.MultiGraph() tags = [] tags_file = open(sys.argv[2]) n_tags = int(tags_file.readline().strip()) for tag in tags_file: tag = tag.strip() tags.append(unicode(tag, 'utf-8')) graph.add_node(unicode(tag, 'utf-8')) edges_file = open(sys.argv[1]) n_nodes = int(edges_file.readline().strip()) n_edges = int(edges_file.readline().strip()) for line in edges_file: a, b = line.split() graph.add_edge(tags[int(a)], tags[int(b)]) print(graph.number_of_nodes()) print(graph.number_of_edges()) sub_list=networkx.attracting_component_subgraphs(graph) for cluster in sub_list: for node in cluster.nodes(): print node print