def global_reaching_centrality(G, weight=None, normalized=True):
 if nx.is_negatively_weighted(G, weight=weight):
  raise nx.NetworkXError('edge weights must be positive')
 total_weight = G.size(weight=weight)
 if (total_weight <= 0):
  raise nx.NetworkXError('Size of G must be positive')
 if (weight is not None):
  as_distance = (lambda u, v, d: (total_weight / d.get(weight, 1)))
  shortest_paths = nx.shortest_path(G, weight=as_distance)
 else:
  shortest_paths = nx.shortest_path(G)
 centrality = local_reaching_centrality
 lrc = [centrality(G, node, paths=paths, weight=weight, normalized=normalized) for (node, paths) in shortest_paths.items()]
 max_lrc = max(lrc)
 return (sum(((max_lrc - c) for c in lrc)) / (len(G) - 1))

def global_reaching_centrality ( G , weight = None , normalized = True ) : if nx . is_negatively_weighted ( G , weight = weight ) : raise nx . NetworkXError ( 'edge weights must be positive' ) total_weight = G . size ( weight = weight ) if ( total_weight <= 0 ) : raise nx . NetworkXError ( 'Size of G must be positive' ) if ( weight is not None ) : as_distance = ( lambda u , v , d : ( total_weight / d . get ( weight , 1 ) ) ) shortest_paths = nx . shortest_path ( G , weight = as_distance ) else : shortest_paths = nx . shortest_path ( G ) centrality = local_reaching_centrality lrc = [ centrality ( G , node , paths = paths , weight = weight , normalized = normalized ) for ( node , paths ) in shortest_paths . items ( ) ] max_lrc = max ( lrc ) return ( sum ( ( ( max_lrc - c ) for c in lrc ) ) / ( len ( G ) - 1 ) )
returns the global reaching centrality of a directed graph .