I am trying to write a Dijkstra Algorithm, however I am struggling to “say” certain things in the code. To visualize, here are the columns that I want to represent using arrays:
max_nodes
A B C Length Predecessor Visited/Unvisited
A 0 1 2 -1 U
B 1 0 1 -1 U
C 2 1 0 -1 U
So there will be several arrays as shown in my code below:
def dijkstra (graph, start, end)
network[max_nodes][max_nodes]
state [max_nodes][length]
state2 [max_nodes][predecessor]
state3 [max_nodes][visited]
initialNode = 0
for nodes in graph:
D[max_nodes][length] = -1
P[max_nodes][predecessor] = ""
V[max_nodes][visited] = false
for l in graph:
length = lengthFromSource[node] + graph[node][l]
if length < lengthFromSourceNode[w]:
state[l][length] = x
state2[l][predecessor]
state3[l][visited] = true
x +=1
The part in bold is where I got stuck - I'm trying to implement this section of the algorithm:
3. node . , node (A) 6, , node (B), 2, B A 6 + 2 = 8. , ,
4. node, . node ; , ,
, , , " node, node, , , node