This algorithm is working correctly only if the graph is directed,but if the graph is undireted it will not.
To make the algorithm work as directed graph you will have to edit neighbour function as
@property def neighbours(self): neighbours = {vertex: set() for vertex in self.vertices} for edge in self.edges: neighbours[edge.start].add((edge.end, edge.cost)) neighbours[edge.end].add((edge.start, edge.cost)) return neighbours
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This algorithm is working correctly only if the graph is directed,but if the graph is undireted it will not.
To make the algorithm work as directed graph you will have to edit neighbour function as