mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-30 16:31:08 +00:00
Merge branch 'joel_graph' of https://github.com/joelkurien/Python into joel_graph
This commit is contained in:
commit
b8c6beae72
|
@ -23,8 +23,8 @@ class JohnsonGraph:
|
|||
|
||||
# perform a dijkstra algorithm on a directed graph
|
||||
def dijkstra(self, s) -> dict:
|
||||
distances = {vertex: sys.maxsize-1 for vertex in self.graph}
|
||||
pq = [(0,s)]
|
||||
distances = {vertex: sys.maxsize - 1 for vertex in self.graph}
|
||||
pq = [(0, s)]
|
||||
distances[s] = 0
|
||||
while pq:
|
||||
weight, v = heapq.heappop(pq)
|
||||
|
@ -38,9 +38,9 @@ class JohnsonGraph:
|
|||
heapq.heappush(pq, (distances[node], node))
|
||||
return distances
|
||||
|
||||
#carry out the bellman ford algorithm for a node and estimate its distance vector
|
||||
# carry out the bellman ford algorithm for a node and estimate its distance vector
|
||||
def bellman_ford(self, s) -> dict:
|
||||
distances = {vertex: sys.maxsize-1 for vertex in self.graph}
|
||||
distances = {vertex: sys.maxsize - 1 for vertex in self.graph}
|
||||
distances[s] = 0
|
||||
|
||||
for u in self.graph:
|
||||
|
@ -52,7 +52,7 @@ class JohnsonGraph:
|
|||
|
||||
# perform the johnson algorithm to handle the negative weights that
|
||||
# could not be handled by either the dijkstra
|
||||
#or the bellman ford algorithm efficiently
|
||||
# or the bellman ford algorithm efficiently
|
||||
def johnson_algo(self) -> dict:
|
||||
self.add_vertices("#")
|
||||
for v in self.graph:
|
||||
|
|
Loading…
Reference in New Issue
Block a user