Guest User

Untitled

a guest
Feb 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1.  
  2. import networkx as nx
  3.  
  4. # generates the shortest paths of train src-dst pair,
  5. def genShrstPathTraffic(G,traffic_file):
  6.  
  7. fout= open('Trunk_IRN_Shortest','w')
  8.  
  9. fin= open(traffic_file)
  10.  
  11. for trn in fin.readlines():
  12. trn= trn.strip()
  13. trn= trn.split("||")
  14.  
  15. path= nx.shortest_path(G,source= trn[2], target= trn[-1])
  16. fout.write(trn[0]+"||"+trn[1]+"||")
  17. for stn in path[0:-1]:
  18. fout.write(stn+"||")
  19. fout.write(path[-1]+"\n")
  20.  
  21. fout.close()
  22.  
  23. G= nx.Graph()
  24. G= nx.read_edgelist('IRN_DistanceCapacity_Graph')
  25. print "Distance Graph : Connected:: ",nx.algorithms.components.connected.is_connected(G)
  26. CC= nx.algorithms.components.connected.connected_components(G)
  27. print "#Components: ",len(CC)
  28.  
  29. traffic_file= 'Trunk_IRN_DistanceCapacity_Traffic_modified'
  30. genShrstPathTraffic(G,traffic_file)
Add Comment
Please, Sign In to add comment