Revision cf1932f7 mrai_setter/milaniBGPLoad.py

View differences:

mrai_setter/milaniBGPLoad.py
22 22

  
23 23

  
24 24

  
25
def mice_centrality(G, cutoff=None, normalized=True, weight=None, destIdentifier=None):
25
def mice_centrality(G, cutoff=None, normalized=True, weight=None, destIdentifier='destinations'):
26 26
    """Compute distributed partial centrality for nodes.
27 27

  
28 28
    The centrality of a node is the fraction of all shortest
......
58 58
    dpc_load = {}.fromkeys(G, 0.0)
59 59
    dpc = {}
60 60
    # Take the list of stub nodes
61
    nodeList = [i for i in G.nodes if G.nodes[i]['type'] != 'T']
61
    nodeList = [i for i in G.nodes if destIdentifier in G.nodes[i]]
62 62
    for node in nodeList:
63 63
        dpc[node] = 0.0  # For each initial stub node I set a dpc of 0
64 64

  
65 65
    # Calculate the load dispersione between each couple of stub nodes
66 66
    for source in dpc:
67
        ubetween = _node_betweenness(G, source, cutoff, weight)
67
        ubetween = _node_betweenness(G, source, cutoff, weight, destIdentifier=destIdentifier)
68 68
        for vk in ubetween:
69 69
            dpc_load[vk] += ubetween[vk]
70 70

  
......
78 78
    return dpc_load  # all nodes
79 79

  
80 80

  
81
def _node_betweenness(G, source, cutoff=False, weight=None):
81
def _node_betweenness(G, source, cutoff=False, weight=None, destIdentifier='destinations'):
82 82
    """Node betweenness_centrality helper:
83 83

  
84 84
    See betweenness_centrality for what you probably want.
......
117 117

  
118 118
    between = {}.fromkeys(length, 1.0)
119 119
    for node in G.nodes:
120
        if G.nodes[node]['type'] == 'T':
120
        if destIdentifier not in G.nodes[node]:
121 121
            between[node] = 0.0  # No stub nodes does not propagate any contribute
122 122
        else:
123 123
            between[node] = 1.0  # Stub nodes propagate 1 contribute
......
132 132
                between[x] += between[v] / float(num_paths)
133 133

  
134 134
    for node in G.nodes:
135
        if G.nodes[node]['type'] != 'T':
135
        if destIdentifier in G.nodes[node]:
136 136
            between[node] -= 1.0
137 137

  
138 138
    return between

Also available in: Unified diff