Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import networkx as nx
- # generates the shortest paths of train src-dst pair,
- def genShrstPathTraffic(G,traffic_file):
- fout= open('Trunk_IRN_Shortest','w')
- fin= open(traffic_file)
- for trn in fin.readlines():
- trn= trn.strip()
- trn= trn.split("||")
- path= nx.shortest_path(G,source= trn[2], target= trn[-1])
- fout.write(trn[0]+"||"+trn[1]+"||")
- for stn in path[0:-1]:
- fout.write(stn+"||")
- fout.write(path[-1]+"\n")
- fout.close()
- G= nx.Graph()
- G= nx.read_edgelist('IRN_DistanceCapacity_Graph')
- print "Distance Graph : Connected:: ",nx.algorithms.components.connected.is_connected(G)
- CC= nx.algorithms.components.connected.connected_components(G)
- print "#Components: ",len(CC)
- traffic_file= 'Trunk_IRN_DistanceCapacity_Traffic_modified'
- genShrstPathTraffic(G,traffic_file)
Add Comment
Please, Sign In to add comment