Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

STY Indented comment string and added citations for Dijkstra implemen…

…tation
  • Loading branch information...
commit 2eb2ce092902973d1d5a451db84ea740b0b89407 1 parent e248442
@effigies authored
Showing with 11 additions and 3 deletions.
  1. +11 −3 mvpa2/misc/neighborhood.py
View
14 mvpa2/misc/neighborhood.py
@@ -395,6 +395,10 @@ def __getitem__(self, coordinate):
return idcs
def dijkstra(self, G, start, end=None):
+ """Dijkstra's algorithm for shortest paths
+ Modified from version by David Eppstein, UC Irvine, 4 Apr 2002
+
+ Original source: http://code.activestate.com/recipes/119466"""

I just wonder how it would compare to networkx's single_source_dijkstra_path_length ?
https://networkx.lanl.gov/trac/browser/networkx/networkx/algorithms/shortest_paths/weighted.py#L171

ideally we should be just reusing other's work ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
D = {} # dictionary of final distances
Q = priorityDictionary() # est.dist. of non-final vert.
Q[start] = 0
@@ -417,6 +421,10 @@ def dijkstra(self, G, start, end=None):
class priorityDictionary(dict):
+ """Priority dictionary using binary heaps
+ Modified from version by David Eppstein, UC Irvine, 8 Mar 2002
+
+ Original source: http://code.activestate.com/recipes/117228"""

Licensed under the PSF License
Copyright: 2002, David Eppstein, UC Irvine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
def __init__(self):
self.__heap = []
dict.__init__(self)
@@ -451,9 +459,9 @@ def iterfn():
return iterfn()
def __setitem__(self, key, val):
- '''Change value stored in dictionary and add corresponding
-pair to heap. Rebuilds the heap if the number of deleted items grows
-too large, to avoid memory leakage.'''
+ '''Change value stored in dictionary and add corresponding pair to
+ heap. Rebuilds the heap if the number of deleted items grows too large,
+ to avoid memory leakage.'''
dict.__setitem__(self, key, val)
heap = self.__heap
if len(heap) > 2 * len(self):
Please sign in to comment.
Something went wrong with that request. Please try again.