Using Python object-oriented knowledge, I made the following modification to the dijkstra method to make it return the distance instead of the path as a deque object.
return the distance between the nodes
distance_between_nodes = 0
for index in range(1, len(path)):
for thing in self.edges:
if thing.start == path[index - 1] and thing.end == path[index]:
distance_between_nodes += thing.cost
return distance_between_nodes
What changes should i do if i dont want to use the deque() data structure?
Also how to read the graph contents from a file with the below structure
a / b / 3
a / c / 5
...
Source node: a
Destination node: j
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.
Using Python object-oriented knowledge, I made the following modification to the dijkstra method to make it return the distance instead of the path as a deque object.
return the distance between the nodes
distance_between_nodes = 0
for index in range(1, len(path)):
for thing in self.edges:
if thing.start == path[index - 1] and thing.end == path[index]:
distance_between_nodes += thing.cost
return distance_between_nodes
# return path
What changes should i do if i dont want to use the deque() data structure?
Also how to read the graph contents from a file with the below structure
a / b / 3
a / c / 5
...
Source node: a
Destination node: j