NetworkX in python -


i want define weighted graph node ids name of persons , links between nodes directed. each edge has label representing relationship , trust value real number.

then, need find path between pair of users calculate indirect trust between two. have written following code, getting following error:

file "osn_graph.py", line 30, in trust=trust*float(g[list[i]][list[i+1]][trust]) keyerror: 1

#!/usr/bin/python   import networkx nx   g = nx.digraph()   f = open("osndata.txt","rb")   while 1:       line = f.readline()       if not line:          break       src = line.rstrip('\n')       g.add_node(src)       line = f.readline()       dest = line.rstrip('\n')       g.add_node(dest)       line = f.readline()       t = int(line)*0.01       line = f.readline()       r = line.rstrip('\n')       g.add_edge(src, dest, weight=t, relation=r)   f.close()   try:       list = nx.dijkstra_path(g, "akash", "jitendra")       trust = 1       = 0       j in range(0, len(list) - 1):          trust = trust * float(g[list[j]][list[j + 1]]['weight'])           += 1       print trust   except nx.networkxnopath:       print "there no path between nodes"    


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -