Exemple #1
0
from graph.Graph import Graph

sources = [1, 2, 3, 0, 5, 1, 1, 3]
targets = [0, 0, 0, 5, 0, 2, 3, 1]
weights = [2, 2, 4, 1, 1, 3, 2, 2]

graph = Graph(sources, targets, weights)

graph.print_r()

graph.draw(with_weight=False)
from graph.Graph import Graph
from algorithms.floyd_warshall import *
from algorithms.eg import *

sources = [1, 2, 3, 0, 2, 3]
targets = [0, 0, 0, 4, 1, 1]
weights = [3, 2, 4, 1, 3, 2]

graph = Graph(sources, targets, weights, True)

dist = Floyd_Warshall(graph)
print(dist)

graph.dynamic_incremental_edge(source=4, target=3, weight=1)

print("<--------Even Gazit------->\n")

dist_eg = Even_Gazit(graph, dist)
print(dist_eg)

print("<-------- Floyd Warshall------->\n")

dist2 = Floyd_Warshall(graph)
print(dist2)

graph.draw()
Exemple #3
0
while True:
    origen = int(input("\nElija el vertice de origen: "))
    if not (origen in grafo.vertex):
        print("* El vertice elegido no existe, ingrese nuevamente")
    else:
        break

print("\n****** RESULTADOS ******")

dist = Dijkstra(origen, grafo)
print("\nDistancias Mínimas por Dijsktra: ")
for i in range(len(grafo.vertex)):
    print(
        f"La distancia mínima de '{origen}' a '{grafo.vertex[i]}' es: {int(dist[i])}"
    )
print(dist)
print()

dist = Dijkstra_ad(grafo)
print("Matriz de Adyacencia por algoritmo de Dijsktra")
print(dist)
print()

dist = Floyd_Warshall(grafo)
print("Matriz de Adyacencia por algoritmo de Floyd-Warshall")
print(dist)
print()

grafo.draw()