You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This line creates a DijkstraHeap object. We will see later how this can be implemented but the best part is that....This is not part of the algorithm! What is a DijkstraHeap then? This is a **priority queue** that has the following properties:
78
+
This line creates a DijkstraHeap object and puts the starting point in it. We will see later how this can be implemented but the best part is that....This is not part of the algorithm! What is a DijkstraHeap then? This is a **priority queue** that has the following properties:
79
79
80
80
* If we try to insert an already visited element in the queue the DijkstraHeap will do nothing.
81
81
* The DijkstraHeap always pop the element that has the lowest cost and NEVER pops an already visited element.
82
82
83
83
Cool! So this DijkstraHeap knows the visiting order of the elements. Its **like a heap but never pops an already visited element**.
84
84
85
+
By the way, a Node object is a tuple of the form ( cost_so_far, point, point_from_we_came ).
86
+
85
87
```python
86
88
while frontier:
87
89
```
@@ -95,24 +97,24 @@ current_node = frontier.pop()
95
97
Each iteration we pop an element from the DijkstraHeap. This element always has the lowest cost element because the DijkstraHeap has this property ( because is a heap and heaps are awesome ).
96
98
97
99
```python
98
-
if current_node.value== end:
100
+
if current_node.point== end:
99
101
return frontier
100
102
```
101
103
102
104
If we have reached the end, we stop and return the DijkstraHeap that has all the information about our path (because it knows how we reach each element).
103
105
104
106
```python
105
-
for neighbor in graph.neighbors( current_node.value ):
107
+
for neighbor in graph.neighbors( current_node.point ):
0 commit comments