From: <gea...@us...> - 2009-05-17 15:34:13
|
Revision: 347 http://mypyspace.svn.sourceforge.net/mypyspace/?rev=347&view=rev Author: gearmonkey Date: 2009-05-17 15:34:06 +0000 (Sun, 17 May 2009) Log Message: ----------- fixed the bugs and cleaned up the shortest path function. Should work with unweighted or audio weight graphs now. Modified Paths: -------------- graphRDF/branches/songsAsNodes/graphRDF.py Modified: graphRDF/branches/songsAsNodes/graphRDF.py =================================================================== --- graphRDF/branches/songsAsNodes/graphRDF.py 2009-05-16 13:32:46 UTC (rev 346) +++ graphRDF/branches/songsAsNodes/graphRDF.py 2009-05-17 15:34:06 UTC (rev 347) @@ -389,18 +389,36 @@ 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.)""" + """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, exotic weights not cached.)""" #tests for existance of shortest paths for given src with the weighting and graph requested - if weight == None and graph = 'S': + 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] + self.S_shortestpaths_unweighted + except AttributeError: + self.S_shortestpaths_unweighted = [[]]*len(self.S.vs) + try: + return self.S_shortestpaths_unweighted[src][dst] + # try: + # 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] + except IndexError: + self.S_shortestpaths_unweighted[src] = self.S.get_shortest_paths(src) + return self.S_shortestpaths_unweighted[src][dst] + + + elif weight == 'audioWeight' and graph == 'S': + try: + self.S_shortestpaths_audioWeighted + except AttributeError: + self.S_shortestpaths_audioWeighted = [[]]*len(self.S.vs) + try: + return self.S_shortestpaths_audioWeighted[src][dst] + except IndexError: + self.S_shortestpaths_audioWeighted[src] = self.S.get_shortest_paths(src,weight) + return self.S_shortestpaths_audioWeighted[src][dst] else: print "the specified edge attribute weight and graph were poorly specifed or are not yet supported..." return This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |