Exemple #1
0
from Graph.Graph import Graph
from Graph.exception import CantReach

graph = [[1, 2, -2], [1, 3, 4], [3, 2, 3], [3, 4, 1], [4, 3, 2], [5, 5, None]]

g = Graph(st=graph)
#print(g.fw_path(start = 4, end=3))
print('Інциденція:\n')
m = g.matrix_incidence()
for n, i in enumerate(m):
    print(n + 1, ":", i)

print('Суміжність:\n')
mm = g.matrix_adjacency()
for n, i in enumerate(mm):
    print(n + 1, ":", i)

hamilton = g.check_hamilton_cycle(1)
print("Без циклів" if hamilton is None else (
    "Цикл з вершини {} на шляху {}".format(hamilton[0], hamilton[1])))

print("Степені точок: ", g.get_nodes_power())
print("Ізольовані точки: ", g.get_isolated())
dejkstra_path = g.dejkstra_path(1, end=2)

bellman_ford_path = g.bf_path(1)
topological_sorted_list = g.topological_sort()

print(dejkstra_path)
print(bellman_ford_path)
print("Топологічне сортування: ", topological_sorted_list)