Skip to content

Commit 8a62ac9

Browse files
committed
Change name to edge_load_centrality.
Also add import of future division and fix initial setup of dict.
1 parent ffa3e5d commit 8a62ac9

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

‎doc/source/reference/algorithms.centrality.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Load
7373
:toctree: generated/
7474

7575
load_centrality
76-
edge_load
76+
edge_load_centrality
7777

7878
Dispersion
7979
----------

‎networkx/algorithms/centrality/load.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
Load centrality.
1414
1515
"""
16+
from __future__ import division
1617
from operator import itemgetter
1718
import networkx as nx
1819

1920
__all__ = ['load_centrality',
20-
'edge_load']
21+
'edge_load_centrality']
2122

2223

2324
def newman_betweenness_centrality(G, v=None, cutoff=None,
@@ -153,7 +154,7 @@ def _node_betweenness(G, source, cutoff=False, normalized=True, weight=None):
153154
load_centrality = newman_betweenness_centrality
154155

155156

156-
def edge_load(G, cutoff=False):
157+
def edge_load_centrality(G, cutoff=False):
157158
"""Compute edge load.
158159
159160
WARNING: This concept of edge load has not been analysed
@@ -177,13 +178,14 @@ def edge_load(G, cutoff=False):
177178
the count is divided equally among paths.
178179
"""
179180
betweenness = {}
181+
for u, v in G.edges():
182+
betweenness[(u, v)] = 0.0
183+
betweenness[(v, u)] = 0.0
184+
180185
for source in G:
181186
ubetween = _edge_betweenness(G, source, cutoff=cutoff)
182187
for e, ubetweenv in ubetween.items():
183-
if e in betweenness:
184-
betweenness[e] += ubetweenv # cumulative total
185-
else:
186-
betweenness[e] = ubetweenv
188+
betweenness[e] += ubetweenv # cumulative total
187189
return betweenness
188190

189191

‎networkx/algorithms/centrality/tests/test_load_centrality.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def test_load_betweenness_difference(self):
227227

228228
def test_c4_edge_load(self):
229229
G=self.C4
230-
c = nx.edge_load(G)
230+
c = nx.edge_load_centrality(G)
231231
d={(0, 1): 6.000,
232232
(0, 3): 6.000,
233233
(1, 2): 6.000,
@@ -237,7 +237,7 @@ def test_c4_edge_load(self):
237237

238238
def test_p4_edge_load(self):
239239
G=self.P4
240-
c = nx.edge_load(G)
240+
c = nx.edge_load_centrality(G)
241241
d={(0, 1): 6.000,
242242
(1, 2): 8.000,
243243
(2, 3): 6.000}
@@ -246,7 +246,7 @@ def test_p4_edge_load(self):
246246

247247
def test_k5_edge_load(self):
248248
G=self.K5
249-
c = nx.edge_load(G)
249+
c = nx.edge_load_centrality(G)
250250
d={(0, 1): 5.000,
251251
(0, 2): 5.000,
252252
(0, 3): 5.000,
@@ -262,7 +262,7 @@ def test_k5_edge_load(self):
262262

263263
def test_tree_edge_load(self):
264264
G=self.T
265-
c = nx.edge_load(G)
265+
c = nx.edge_load_centrality(G)
266266
d={(0, 1): 24.000,
267267
(0, 2): 24.000,
268268
(1, 3): 12.000,

0 commit comments

Comments
 (0)