def bellmanFord(G, s): init(G, s) for _ in range(len(G.V) - 1): for u, v, _ in G.E: relax(G, u, v) for u, v, _ in G.E: if G.V[v].d > G.V[u].d + G.W[u, v]: return False return True
def dijkstra(G, s): init(G, s) for v in G.V: G.V[v].key = float("inf") S = [] heap = MinHeap(list(G.V.values())) while not heap.isEmpty(): u = heap.extractMin() S.append(u.value) for v in G.Adj[u.value]: relax(G, u.value, v)
def dijkstrap(G, s): D, P, Q, S = {s: 0}, {}, [(0, s)], set() while Q: _, u = heappop(Q) if u in S: continue S.add(u) for v in G[u]: relax(G, u, v, D, P) heappush(Q, (D[v], v)) return D, P
def bell(G, s): D = {s: 0} P = {} for rnd in G: changed = False for u in G: for v in G[u]: if relax(G, u, v, D, P): changed = True if not changed: break else: print 'nagitive ' return D
h = 1. / (N - 1) # Pas d'espace dx, dy x = np.linspace(0, 1, N) y = np.linspace(0, 1, N) # # La solution exacte # Te = np.zeros([N, N]) for i in range(0, N): for j in range(0, N): Te[i, j] = (1 / np.sinh(np.pi)) * ( np.sinh(np.pi * x[i]) * np.sin(np.pi * y[j]) + np.sin(np.pi * x[i]) * np.sinh(np.pi * y[j])) debtime = time.time() if ksolve < 4: # méthodes itératives niter, errtab, restab, T = relax.relax(ksolve, ksch, N, Te) err = errtab[niter - 1] #print ksch,'\t',ksolve,'\t',N,'\t',np.log10(h),'\t', errtab[niter-1],'\t',niter,'\t',time.time()-debtime elif ksolve < 6: err, T = direct.direct(ksolve, ksch, N, Te) niter = 1 err = np.log10(err) #print ksch,'\t',ksolve,'\t',N,'\t',np.log10(h),'\t', np.log10(err),'\t',niter,'\t',time.time()-debtime else: # dernière question uniquement import jacobiOptimise as jo if ksolve <= 7: niter, errtab, restab, T = jo.relaxMatrice(ksolve, ksch, N, Te) if ksolve == 8: niter, errtab, restab, T = jo.relaxTableau(ksolve, ksch, N, Te) err = errtab[niter - 1]
def findPath(self, k, ontObjList): print("Finding path in AGV ", self.ownNo) it = initialWeights(self.mObj, self.source) u = self.source itrforOnt = 0 if (self.pathNo == 1): itrforOnt = 0 elif (self.pathNo > 1): itrforOnt = self.lastitrforOnt #print("Outside while:itrforfindNextX", itrforfindNextX) while len(it.Q) != 0: it.Q.remove(u) self.findLenPredecessor(it, u) adj_u = find_adj(self.mObj, u) seqNeigh = 0 lenPrednodes = self.findLenPredecessor(it, u) #print("lenPrednodes", lenPrednodes) if (lenPrednodes): #cal_len_pred_nodes(it,self.source, u) timeKF = lenPrednodes + k + 1 else: timeKF = k + 1 #print("timeKF",timeKF) #self.trackTimeKF.append(timeKF) predecessor_u = it.pi_v[u] # fid1 = open(self.f1,'a') # wrtxt1="AGvNo-"+str(self.ownNo)+" "+"U-"+str(u)+" "+"Pred-"+str(predecessor_u)+" "+"TimeKF-"+str(timeKF)+'\n' #' '+str(X_teqd)+ # fid1.write(wrtxt1) # fid1.close() #print("ownNo, u,timeKF, pred of u",self.ownNo, u, timeKF,predecessor_u) if (predecessor_u == 0): if (self.pathNo > 1): self.inPCurr = self.lastP #end if elif (predecessor_u != 0): if (timeKF > (self.regNo + 1)): # and self.pathNo >=1): self.inPCurr = self.fObj.P[predecessor_u][u] #end if #end if if (timeKF >= self.regNo): self.bModObj.createModel(self.fObj, self.phi, lenPrednodes, self.lastState, self.pathNo, self.regNo, timeKF, u, it) for h in adj_u: #(vphi,len_pred_nodes,state_inp,path_no,n,time_KF,curr_node,it): seqNeigh += 1 if h == 1: if (seqNeigh in self.mObj.neighbor_node_no[u]): currNeighbor = self.mObj.neighbor_node_no[u][seqNeigh] #end if if (currNeighbor != self.source): itrforOnt = itrforOnt + 1 #print("inside for and while:itrforfindNextX", itrforfindNextX) self.estCount, self.growPerDiff, edgecost_to_neighbor = self.fObj.findNextX( ontObjList, itrforOnt, self.mObj, it, self.pathNo, self.ownNo, self.regNo, self.inPCurr, seqNeigh, currNeighbor, u, timeKF, self.source, self.bModObj) relax(u, currNeighbor, it, edgecost_to_neighbor) #end if #end if #end for #calculating min_d min_d = float("inf") for l in it.Q: #print("l", l) if (it.d_v[l] < min_d): min_d = it.d_v[l] #end if #end for for v, e in it.d_v.items(): if e == min_d: if (v in it.Q): nextU = v #end if # end if # end for u = nextU #end of while loop self.pathCost(it) #set path cost here self.formEndVars(it, self.bModObj, itrforOnt, ontObjList) return self.acRYallP # call end var here ??
def noCircle(G, s): topoSort(G) init(G, s) for u in L: for v in G.Adj[u]: relax(G, u, v)