# -*- encoding: utf-8 -*-
import networkx as nx

#formatar a saida ordenada de acordo com o valor de centralidade
def processValues(result):
  
  listValues = []

  for key, value in result.items():
	  listValues.append(str("{:.10f}".format(value))+'-'+str(key))

  sortedList = sorted(listValues)

  listResult = []
  count = 0
  for i in reversed(sortedList):
	if count <MAXNODES:
		array = i.split('-')
	
	value = G.node[int(array[1])]['label']+';;'+(array[0])
	count = count +1
	listResult.append(value)

  return listResult

if __name__ == '__main__':
	MAXNODES = 500
	G=nx.read_gml('BeloHorizonte_DAY.gml')

	#BETWEENNESS
	result = nx.betweenness_centrality(G)
	listResults = processValues(result)
	f = open('result-betweenness.txt','w')
	for i in listResults:
		f.write(i+'\n')



