Advertisement
cwchen

dipsy exercise

Apr 14th, 2016
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. # PROBLEMATIC, DON'T USE THE CODE
  2. import sys
  3. import dispy
  4.  
  5. # A method calculating the importance of a subgraph
  6. #
  7. # args has three parts
  8. # - args[0]: the graph data structure
  9. # - args[1]: the hash with some precalculated float values
  10. # - args[2]: the node name
  11. def calc_importance(args):
  12.     subgraph = args[0].subgraph_from(args[2])
  13.  
  14.     importance = 0.0
  15.     for e in subgraph.all_nodes():
  16.         if e in ratio:
  17.             importance += abs(args[1][e])
  18.  
  19.     return (args[2], importance)
  20.  
  21. cluster = dispy.JobCluster(calc_importance)
  22. jobs = []
  23. # nodes is a list of string presenting node in a graph
  24. for n in nodes:
  25.     # graph is a unpublished module dealing with graph data structure data
  26.     # ratio is a hash with precalculated float values
  27.     job = cluster.submit((graph, ratio, n))
  28.     jobs.append(job)
  29.  
  30. for job in jobs:
  31.     n, importance = job()
  32.     print "{}\t{}".format(n, importance)
  33.     sys.stdout.flush()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement