I am struggling on what is theoretically a simple problem, much to my frustration.
Essentially, I need to be able to create Dijkstra's Algorithm so that:
- I have a 2D array holding distances between the network nodes
- I have a 2D array holding predecessor, length & visited/unvisited status
- I have a 1D array holding the optimum path from source to destination
Here is my code so far:
#usr/bin/python #Declarations max_nodes = 1000 infinity = -1 network = [max_nodes][max_nodes] state = [max_nodes] path = [] int k, i, j def Dijkstra (g, start, end) #For each node in graph for n in g: length = infinity #Set length to all nodes to infinity previousNode = none #Set previous node to none length[startingNode] = 0 #Set starting node length to 0 #For each edge outgoing from u for edge in g[n]: currentDistance = state[i] + network[k][i] #Set the current distance from each node if currentDistance < #If current distance is smaller than ??
As you can see it's terrible, i'm getting confused on how to work with the arrays and just need some guidance on how I can improve on the rubbish I have written so far .


Sign In
Create Account

Back to top









