Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # PROBLEMATIC, DON'T USE THE CODE
- import sys
- import dispy
- # A method calculating the importance of a subgraph
- #
- # args has three parts
- # - args[0]: the graph data structure
- # - args[1]: the hash with some precalculated float values
- # - args[2]: the node name
- def calc_importance(args):
- subgraph = args[0].subgraph_from(args[2])
- importance = 0.0
- for e in subgraph.all_nodes():
- if e in ratio:
- importance += abs(args[1][e])
- return (args[2], importance)
- cluster = dispy.JobCluster(calc_importance)
- jobs = []
- # nodes is a list of string presenting node in a graph
- for n in nodes:
- # graph is a unpublished module dealing with graph data structure data
- # ratio is a hash with precalculated float values
- job = cluster.submit((graph, ratio, n))
- jobs.append(job)
- for job in jobs:
- n, importance = job()
- print "{}\t{}".format(n, importance)
- sys.stdout.flush()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement