<s> """<STR_LIT>""" <EOL> import networkx as nx <EOL> __author__ = "<STR_LIT:\n>" . join ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> __all__ = [ '<STR_LIT>' ] <EOL> def weiner_index ( G , weight = None ) : <EOL> weiner = <NUM_LIT:0.0> <EOL> if weight is None : <EOL> for n in G : <EOL> path_length = nx . single_source_shortest_path_length ( G , n ) <EOL> weiner += sum ( path_length . values ( ) ) <EOL> else : <EOL> for n in G : <EOL> path_length = nx . single_source_dijkstra_path_length ( G , <EOL> n , weight = weight ) <EOL> weiner += sum ( path_length . values ( ) ) <EOL> return weiner <EOL> def closeness_vitality ( G , weight = None ) : <EOL> """<STR_LIT>""" <EOL> multigraph = G . is_multigraph ( ) <EOL> wig = weiner_index ( G , weight ) <EOL> closeness_vitality = { } <EOL> for n in G : <EOL> if multigraph : <EOL> edges = G . edges ( n , data = True , keys = True ) <EOL> if G . is_directed ( ) : <EOL> edges += G . in_edges ( n , data = True , keys = True ) <EOL> else : <EOL> edges = G . edges ( n , data = True ) <EOL> if G . is_directed ( ) : <EOL> edges += G . in_edges ( n , data = True ) <EOL> G . remove_edges_from ( edges ) <EOL> closeness_vitality [ n ] = wig - weiner_index ( G , weight ) <EOL> G . add_edges_from ( edges ) <EOL> return closeness_vitality </s>
