Revision 3673c3e8 fiddle/heuristic-betweenness-centrality/betweenness_centrality.py

View differences:

fiddle/heuristic-betweenness-centrality/betweenness_centrality.py
211 211
        print "ERROR in get_value_from_traffic_matrix"
212 212
        return -1
213 213

  
214
def _accumulate_basic(betweenness, S, P, sigma, s, traffic_matrix, nodes):
215
    delta = dict.fromkeys(S, 0)
216
    while S:
217
        w = S.pop()
218
        coeff = (1.0 + delta[w]) / sigma[w]
219
        for v in P[w]:
220
            h = _get_value_from_traffic_matrix(nodes, traffic_matrix, s, v)
221
            delta[v] += sigma[v] * coeff + h
222
        if w != s:
223
            betweenness[w] += delta[w]
224

  
225

  
226 214
def _accumulate_weight_basic(betweenness, S, P, sigma, s):
227 215
    r"""Accumlate the BC score.
228 216

  
......
235 223
    .. [1] Rami Puzis
236 224
       Optimization of NIDS Placement for Protection of Intercommunicating Critical Infrastructures
237 225
    """
226
    # betweenness[s] += len(S) - 1
238 227
    delta = dict.fromkeys(S, 0)
239 228
    while S:
240 229
        w = S.pop()
241
        if w != s:
242
            delta[w] += 1 # this is the h, when w != s, then h(s, w) = 1
230
        # if w != s:
231
        delta[w] += 1 # this is the h, when w != s, then h(s, w) = 1
243 232
        coeff = delta[w] / sigma[w]
244 233
        for v in P[w]:
245 234
            delta[v] += sigma[v] * coeff
......
255 244
    .. [1] Rami Puzis
256 245
       Optimization of NIDS Placement for Protection of Intercommunicating Critical Infrastructures
257 246
    """
247
    # betweenness[s] += len(S) - 1
258 248
    delta = dict.fromkeys(S, 0)
259 249
    while S:
260 250
        w = S.pop()
261 251
        h = _get_value_from_traffic_matrix(nodes, traffic_matrix, s, w)
262 252
        delta[w] += h
253

  
263 254
        coeff = delta[w] / sigma[w]
264 255

  
265 256
        for v in P[w]:

Also available in: Unified diff