OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [remove_cycle/] [s_c_c.py] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
import networkx as nx
2
 
3
 
4
def filter_big_scc(g,edges_to_be_removed):
5
        #Given a graph g and edges to be removed
6
        #Return a list of big scc subgraphs (# of nodes >= 2)
7
        g.remove_edges_from(edges_to_be_removed)
8
        sub_graphs = filter(lambda scc: scc.number_of_nodes() >= 2, nx.strongly_connected_component_subgraphs(g))
9
        return sub_graphs
10
 
11
def get_big_sccs(g):
12
        self_loop_edges = g.selfloop_edges()
13
        g.remove_edges_from(g.selfloop_edges())
14
        num_big_sccs = 0
15
        edges_to_be_removed = []
16
        big_sccs = []
17
        for sub in nx.strongly_connected_component_subgraphs(g):
18
                number_of_nodes = sub.number_of_nodes()
19
                if number_of_nodes >= 2:
20
                        # strongly connected components
21
                        num_big_sccs += 1
22
                        big_sccs.append(sub)
23
        #print(" # big sccs: %d" % (num_big_sccs))
24
        return big_sccs
25
 
26
def nodes_in_scc(sccs):
27
        scc_nodes = []
28
        scc_edges = []
29
        for scc in sccs:
30
                scc_nodes += list(scc.nodes())
31
                scc_edges += list(scc.edges())
32
 
33
        #print("# nodes in big sccs: %d" % len(scc_nodes))
34
        #print("# edges in big sccs: %d" % len(scc_edges))
35
        return scc_nodes
36
 
37
def scc_nodes_edges(g):
38
        scc_nodes = set()
39
        scc_edges = set()
40
        num_big_sccs = 0
41
        num_nodes_biggest_scc = 0
42
        biggest_scc = None
43
        for sub in nx.strongly_connected_component_subgraphs(g):
44
                number_nodes = sub.number_of_nodes()
45
                if number_nodes >= 2:
46
                        scc_nodes.update(sub.nodes())
47
                        scc_edges.update(sub.edges())
48
                        num_big_sccs += 1
49
                        if num_nodes_biggest_scc < number_nodes:
50
                                num_nodes_biggest_scc = number_nodes
51
                                biggest_scc = sub
52
        nonscc_nodes = set(g.nodes()) - scc_nodes
53
        nonscc_edges = set(g.edges()) - scc_edges
54
        print num_nodes_biggest_scc
55
        print("num of big sccs: %d" % num_big_sccs)
56
        if biggest_scc == None:
57
                return scc_nodes,scc_nodes,nonscc_nodes,nonscc_edges
58
        print("# nodes in biggest scc: %d, # edges in biggest scc: %d" % (biggest_scc.number_of_nodes(),biggest_scc.number_of_edges()))
59
        print("# nodes,edges in scc: (%d,%d), # nodes, edges in non-scc: (%d,%d) " % (len(scc_nodes),len(scc_edges),len(nonscc_nodes),len(nonscc_edges)))
60
        num_of_nodes = g.number_of_nodes()
61
        num_of_edges = g.number_of_edges()
62
        print("# nodes in graph: %d, # of edges in graph: %d, percentage nodes, edges in scc: (%0.4f,%0.4f), percentage nodes, edges in non-scc: (%0.4f,%0.4f)" % (num_of_nodes,num_of_edges,len(scc_nodes)*1.0/num_of_nodes,len(scc_edges)*1.0/num_of_edges,len(nonscc_nodes)*1.0/num_of_nodes,len(nonscc_edges)*1.0/num_of_edges))
63
        return scc_nodes,scc_edges,nonscc_nodes,nonscc_edges
64
 
65
 
66
def c_c(graph_file):
67
        g = nx.read_edgelist(graph_file,create_using = nx.Graph(),nodetype = int)
68
        graphs = nx.connected_component_subgraphs(g)
69
        for graph in graphs:
70
                print graph.number_of_nodes(),graph.number_of_edges()
71
        print len(graphs)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.