-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloyd.py
More file actions
24 lines (19 loc) · 723 Bytes
/
Copy pathfloyd.py
File metadata and controls
24 lines (19 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
INF = float("inf")
#Matriz de distancias entre cada Nó. INF = Nós não possuem ligação.
grafo = [ [0, 5, INF, 10],
[INF, 0, 3, INF],
[INF, INF, 0, 1],
[INF, INF, INF, 0]
]
def floyd(grafo):
ponderados = grafo
len_matrix = len(grafo)
#Aplicação do algoritmo de Floyd
for k in range(len_matrix):
for i in range(len_matrix):
for j in range(len_matrix):
ponderados[i][j] = min(ponderados[i][j], ponderados[i][k] + ponderados[k][j])
for itens in ponderados: #Printa a matriz final organizando a leitura
print("")
for item in itens:
print("%s\t" % item, end="")