mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-29 18:06:45 +00:00
Resolving ruff issues
This commit is contained in:
parent
11bfe18e0d
commit
8286b5855a
@ -1,8 +1,9 @@
|
|||||||
from collections import deque
|
|
||||||
import heapq
|
import heapq
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
#First implementation of johnson algorithm
|
#First implementation of johnson algorithm
|
||||||
|
#Steps followed to implement this algorithm is given in the below link:
|
||||||
|
#https://brilliant.org/wiki/johnsons-algorithm/
|
||||||
class JohnsonGraph:
|
class JohnsonGraph:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.edges = []
|
self.edges = []
|
||||||
@ -19,7 +20,6 @@ class JohnsonGraph:
|
|||||||
|
|
||||||
#perform a dijkstra algorithm on a directed graph
|
#perform a dijkstra algorithm on a directed graph
|
||||||
def dijkstra(self, s):
|
def dijkstra(self, s):
|
||||||
no_v = len(self.graph)
|
|
||||||
distances = {vertex: sys.maxsize-1 for vertex in self.graph}
|
distances = {vertex: sys.maxsize-1 for vertex in self.graph}
|
||||||
pq = [(0,s)]
|
pq = [(0,s)]
|
||||||
|
|
||||||
@ -38,7 +38,6 @@ class JohnsonGraph:
|
|||||||
|
|
||||||
#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):
|
def bellman_ford(self, s):
|
||||||
no_v = len(self.graph)
|
|
||||||
distances = {vertex: sys.maxsize-1 for vertex in self.graph}
|
distances = {vertex: sys.maxsize-1 for vertex in self.graph}
|
||||||
distances[s] = 0
|
distances[s] = 0
|
||||||
|
|
||||||
@ -49,7 +48,8 @@ class JohnsonGraph:
|
|||||||
|
|
||||||
return distances
|
return distances
|
||||||
|
|
||||||
#perform the johnson algorithm to handle the negative weights that could not be handled by either the dijkstra
|
#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):
|
def johnson_algo(self):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user