python - getting an error when I call this Dijkstra function -


when call function, error below raised, idea appreciated.

the error: dist, next = dijkstra(graph, sink, sources) line 111, in dijkstra s, q = list(sources[:]), range(1,n+1) typeerror: 'int' object has no attribute 'getitem'

the code:

def dijkstra(graph, sink, sources = none):     n = len (graph.nodes ())     dist = {k+1:np.inf k in range(n)}     next = {k+1:none k in range(n)}     dist[sink] = 0.0     s = list(sources[:])     q = range(1,n+1)     while len(q)>0:         min = np.inf         v in q:             if (dist[v] < min):                 u=v                 min = dist[v]         if min == np.inf: return dist, next         s in s:             if u == s: s.remove(u)         if len(s)==0: return dist,next         q.remove(u)         in graph.predecessors_iter(u):             v =             alt = dist[u] + graph [v][u]["weight"]             if alt < dist[v]: dist[v] = alt; next[v] = u     return dist, next   def mainksp(graph, sources, sink, k): """find k-shortest paths sources sink  return value: ------------- as: dictionary s.t. as[s]=[k-shortest paths s sink s in sources] """ dist, next = dijkstra(graph, sink, sources) a0s = {s:get_path(s, sink, next) s in sources} return {s : yenksp(graph, s, sink, k, a0s[s]) s in sources} graphnodes = [h h in range (1, 24)]     path = mainksp(network, graphnodes, 1, 3) 

i python beginner , made afford figure out wrong s list, no success. dijkstra function called inside of function provided above.


Comments