def Johnson(A): printCosts(A) N = len(A) d = potencjal(A) if not d: return None for v in range(N): for u in range(N): A[u][v] = A[u][v] + d[-1][u] - d[-1][v] print printCosts(A) d2 = [] for u in range(N): d2 = Dijkstra(u,A) #for u in range(N): # dfg = Dijkstra(u,A) # BLAD dla u=1 #for v in range(N): # A[u][v] = d2[v] + d[-1][u] - d[-1][v] return A
if __name__ == '__main__': from printCosts import * #m = [[0, 3, 10, float('inf')], # [3, 0, 4, 10], # [10, 4, 0, 14], # [float('inf'), 10, 14, 0]] m = [[0, 5, 1, float('inf'), 10, 4, float('inf')], [5, 0, 2, float('inf'), float('inf'), float('inf'), 1], [1, 2, 0, 1, float('inf'), float('inf'), float('inf')], [float('inf'), float('inf'), 1, 0, 4, 1, float('inf')], [10, float('inf'), float('inf'), 4, 0, 1, float('inf')], [4, float('inf'), float('inf'), 1, 1, 0, 2], [float('inf'), 1, float('inf'), float('inf'), float('inf'), 2, 0]] print "Original matrix:" printCosts(m) d = findAllShortestPaths(m) print "Shortest distances:" printCosts(d)
i = kr.index(1) j = kr[(i + 1):].index(1) + i + 1 List[i].append(j) List[j].append(i) return List if __name__ == '__main__': from printCosts import * from GraphDigital import * #startGraf() am = [[0, 1, 1, 0, 0], [1, 0, 0, 0, 1], [1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 1, 0, 0, 0]] printCosts(am) al = matrixToList(am) am = listToMatrix(al) print '\n', 'Lista z Macierzy:', al wyswietl(al) print 'Macierz z Listy:' printCosts(am) ai = matSasToMatIn(am) print '\n', 'Incydencji z Macierzy:', ai, '\n' am = matInToMatSas(ai) printCosts(am) print '\n\n', 'Lista:', al wyswietl(al)
return None return [[x[0] for x in row] for row in dist] if __name__ == '__main__': import sys n = 20 if len(sys.argv) < 2 else int(sys.argv[1]) l = 30 if len(sys.argv) < 2 else int(sys.argv[2]) from printCosts import * from DIrandom import * from DIrandomizeWeights import * from GraphDigital2 import * A = losowyDigraf(n, l) wyswietl(A, False) from DIspojne import * from GraphSlice import * A = GraphSlice(A, listaSpojnychSkladowych(A)[0]) A = randomizeWeights(A, -5, 20) wyswietl(A) print "Original matrix:" printCosts(A) d = findAllShortestPaths(A) if d != None: print "Shortest distances:" printCosts(d)
czujnik += 1 if czujnik == 10000: print "Wybierz inne n, l." return None A[i][j] = 1 A[j][i] = 1 operation += 1 return A def H(n, p): '''losuje graf n-wierzcholkowy z prawdopodobienstwem powstania kazdej krawedzi rownym p''' A = [[0] * n for i in range(n)] for i in range(n): for j in range(i + 1, n): if random.random() < p: A[i][j] = 1 A[j][i] = 1 return A if __name__ == "__main__": from printCosts import * from GraphDigital import * from konwersje import * g = G(5, 4) printCosts(g) wyswietl(matrixToList(g)) print("*********************************************") printCosts(H(5, 0.7))