def test_K4(self):
        """Betweenness centrality: K4"""
        G=networkx.complete_graph(4)
        b=edge_current_flow_subset(G,list(G),list(G),normalized=False)
        b_answer=edge_current_flow(G,normalized=False)
        for (s,t),v1 in b_answer.items():
            v2=b.get((s,t),b.get((t,s)))
            assert_almost_equal(v1,v2)
        # test weighted network
        G.add_edge(0,1,{'weight':0.5,'other':0.3})
        b=edge_current_flow_subset(G,list(G),list(G),normalized=False,weight=None)
        # weight is None => same as unweighted network
        for (s,t),v1 in b_answer.items():
            v2=b.get((s,t),b.get((t,s)))
            assert_almost_equal(v1,v2)

        b=edge_current_flow_subset(G,list(G),list(G),normalized=False)
        b_answer=edge_current_flow(G,normalized=False)
        for (s,t),v1 in b_answer.items():
            v2=b.get((s,t),b.get((t,s)))
            assert_almost_equal(v1,v2)

        b=edge_current_flow_subset(G,list(G),list(G),normalized=False,weight='other')
        b_answer=edge_current_flow(G,normalized=False,weight='other')
        for (s,t),v1 in b_answer.items():
            v2=b.get((s,t),b.get((t,s)))
            assert_almost_equal(v1,v2)
コード例 #2
0
    def test_K4(self):
        """Betweenness centrality: K4"""
        G = nx.complete_graph(4)
        b = edge_current_flow_subset(G, list(G), list(G), normalized=False)
        b_answer = edge_current_flow(G, normalized=False)
        for (s, t), v1 in b_answer.items():
            v2 = b.get((s, t), b.get((t, s)))
            assert almost_equal(v1, v2)
        # test weighted network
        G.add_edge(0, 1, weight=0.5, other=0.3)
        b = edge_current_flow_subset(G,
                                     list(G),
                                     list(G),
                                     normalized=False,
                                     weight=None)
        # weight is None => same as unweighted network
        for (s, t), v1 in b_answer.items():
            v2 = b.get((s, t), b.get((t, s)))
            assert almost_equal(v1, v2)

        b = edge_current_flow_subset(G, list(G), list(G), normalized=False)
        b_answer = edge_current_flow(G, normalized=False)
        for (s, t), v1 in b_answer.items():
            v2 = b.get((s, t), b.get((t, s)))
            assert almost_equal(v1, v2)

        b = edge_current_flow_subset(G,
                                     list(G),
                                     list(G),
                                     normalized=False,
                                     weight="other")
        b_answer = edge_current_flow(G, normalized=False, weight="other")
        for (s, t), v1 in b_answer.items():
            v2 = b.get((s, t), b.get((t, s)))
            assert almost_equal(v1, v2)
コード例 #3
0
    def test_K4(self):
        """Betweenness centrality: K4"""
        G=networkx.complete_graph(4)
        b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=False)
        b_answer=edge_current_flow(G,normalized=False)
        for (s,t),v1 in b_answer.items():
            v2=b.get((s,t),b.get((t,s)))
            assert_almost_equal(v1,v2)
        # test weighted network
        G.add_edge(0,1,{'weight':0.5,'other':0.3})
        b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=False,weight=None)
        # weight is None => same as unweighted network
        for (s,t),v1 in b_answer.items():
            v2=b.get((s,t),b.get((t,s)))
            assert_almost_equal(v1,v2)

        b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=False)
        b_answer=edge_current_flow(G,normalized=False)
        for (s,t),v1 in b_answer.items():
            v2=b.get((s,t),b.get((t,s)))
            assert_almost_equal(v1,v2)

        b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=False,weight='other')
        b_answer=edge_current_flow(G,normalized=False,weight='other')
        for (s,t),v1 in b_answer.items():
            v2=b.get((s,t),b.get((t,s)))
            assert_almost_equal(v1,v2)
 def test_K4_normalized(self):
     """Betweenness centrality: K4"""
     G=networkx.complete_graph(4)
     b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=True)
     b_answer=edge_current_flow(G,normalized=True)
     for n in sorted(G.edges()):
         assert_almost_equal(b[n],b_answer[n])
 def test_K4_normalized(self):
     """Betweenness centrality: K4"""
     G = networkx.complete_graph(4)
     b = edge_current_flow_subset(G, G.nodes(), G.nodes(), normalized=True)
     b_answer = edge_current_flow(G, normalized=True)
     for n in sorted(G.edges()):
         assert_almost_equal(b[n], b_answer[n])
コード例 #6
0
 def test_P4(self):
     """Edge betweenness centrality: P4"""
     G = nx.path_graph(4)
     b = edge_current_flow_subset(G, list(G), list(G), normalized=True)
     b_answer = edge_current_flow(G, normalized=True)
     for (s, t), v1 in b_answer.items():
         v2 = b.get((s, t), b.get((t, s)))
         assert almost_equal(v1, v2)
 def test_P4(self):
     """Edge betweenness centrality: P4"""
     G=networkx.path_graph(4)
     b=edge_current_flow_subset(G, list(G), list(G), normalized=True)
     b_answer=edge_current_flow(G,normalized=True)
     for (s,t),v1 in b_answer.items():
         v2=b.get((s,t),b.get((t,s)))
         assert_almost_equal(v1,v2)
コード例 #8
0
 def test_K4_normalized(self):
     """Betweenness centrality: K4"""
     G=networkx.complete_graph(4)
     b=edge_current_flow_subset(G,list(G),list(G),normalized=True)
     b_answer=edge_current_flow(G,normalized=True)
     for (s,t),v1 in b_answer.items():
         v2=b.get((s,t),b.get((t,s)))
         assert_almost_equal(v1,v2)
 def test_K4_normalized(self):
     """Betweenness centrality: K4"""
     G=nx.complete_graph(4)
     b=edge_current_flow_subset(G,list(G),list(G),normalized=True)
     b_answer=edge_current_flow(G,normalized=True)
     for (s,t),v1 in b_answer.items():
         v2=b.get((s,t),b.get((t,s)))
         assert_almost_equal(v1,v2)
コード例 #10
0
 def test_C4(self):
     """Edge betweenness centrality: C4"""
     G=networkx.cycle_graph(4)
     b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=True)
     b_answer=edge_current_flow(G,normalized=True)
     for (s,t),v1 in b_answer.items():
         v2=b.get((s,t),b.get((t,s)))
         assert_almost_equal(v1,v2)
コード例 #11
0
 def test_P4(self):
     """Edge betweenness centrality: P4"""
     G = nx.path_graph(4)
     b = edge_current_flow_subset(G, list(G), list(G), normalized=True)
     b_answer = edge_current_flow(G, normalized=True)
     for (s, t), v1 in b_answer.items():
         v2 = b.get((s, t), b.get((t, s)))
         assert v1 == pytest.approx(v2, abs=1e-7)
コード例 #12
0
 def test_K4(self):
     """Betweenness centrality: K4"""
     G=networkx.complete_graph(4)
     b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=False)
     b_answer=edge_current_flow(G,normalized=False)
     for n in sorted(G.edges()):
         assert_almost_equal(b[n],b_answer[n])
     # test weighted network
     G.add_edge(0,1,{'weight':0.5,'other':0.3})
     b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=False,weight=None)
     # weight is None => same as unweighted network
     for n in sorted(G.edges()):
         assert_almost_equal(b[n],b_answer[n])
     b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=False)
     b_answer=edge_current_flow(G,normalized=False)
     for n in sorted(G.edges()):
         assert_almost_equal(b[n],b_answer[n])
     b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=False,weight='other')
     b_answer=edge_current_flow(G,normalized=False,weight='other')
     for n in sorted(G.edges()):
         assert_almost_equal(b[n],b_answer[n])