From: <gea...@us...> - 2009-05-16 14:22:48
|
Revision: 346 http://mypyspace.svn.sourceforge.net/mypyspace/?rev=346&view=rev Author: gearmonkey Date: 2009-05-16 13:32:46 +0000 (Sat, 16 May 2009) Log Message: ----------- Added a function to access the path from src to dst, currently uweighted graphs only. Modified Paths: -------------- graphRDF/branches/songsAsNodes/graphRDF.py Modified: graphRDF/branches/songsAsNodes/graphRDF.py =================================================================== --- graphRDF/branches/songsAsNodes/graphRDF.py 2009-05-09 13:41:10 UTC (rev 345) +++ graphRDF/branches/songsAsNodes/graphRDF.py 2009-05-16 13:32:46 UTC (rev 346) @@ -388,9 +388,26 @@ + def shortestPath(self, src, dst, graph='S', weight='audioWeight'): + """returns the shortest path between the nodes src and dst (specified as node numbers) within graph (specify 'S' or 'G', S used by default). The edge attribute to use as a weight can be specified in weight, use None if an unweighted shortest path is desired. Looks to see if the shortest path index has been filled in self.graph.shortestpaths_unweighted or self.graph.shortestpaths_weighted (for audioWeight, exoitic weights not cached.)""" + #tests for existance of shortest paths for given src with the weighting and graph requested + if weight == None and graph = 'S': + try: + self.S.shortestpaths_unweighted[src] + except NameError: + self.S.shortestpaths_unweighted[src] = []*len(S.vs) + if not self.S.shortestpaths_unweighted[src][dst] == []: + return self.S.shortestpaths_unweighted[src][dst] + else: + self.S.shortestpaths_unweighted[src] = self.S.get_shortest_paths(src) + return self.S.shortestpaths_unweighted[src][dst] + else: + print "the specified edge attribute weight and graph were poorly specifed or are not yet supported..." + return + def getGenreAssortativity(self): '''get the assortivaty coeff for the igraph G - based on Newman 2002 "Mixing Patterns in Networks" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |