Ejemplo n.º 1
0
def main():
    matr = graph.output_file_content("input/lab5.txt")
    choice = None
    while True:
        choice = input("""
            Що робити?
            1 - визначити матриці відстаней та досяжності графу
            2 - визначити наявність простих циклів у графі
            3 - визначити тип зв'язності графу
            """)
        if choice == "1":
            matr_distance, reach_matr = distance_and_reach_matr(matr)

            print("\nМатриця відстаней", end="")
            graph.show(matr_distance, "matr")

            print("\nМатриця досяжності", end="")
            graph.show(reach_matr, "matr")
            break
        elif choice == "2":
            find_cycles([x[:] for x in matr])
            break
        elif choice == "3":
            matr_distance, reach_matr = distance_and_reach_matr(matr)
            type_of_connect(matr, reach_matr)
            break
        else:
            print("В меню відсутній пункт", choice)

    graph.draw_graph(matr)
Ejemplo n.º 2
0
def main():
    matr = graph.output_file_content("input/2.txt")
    start_vert = None
    while not start_vert:
        try:
            start_vert = int(input("Введіть стартову вершину: "))
        except:
            print("Спробуйте ще раз (це мусить бути число)")

    choice = None
    while True:
        choice = input("""
        Яким методом обходити граф?
        1 - DFS
        2 - BFS
        """)
        if choice == "1":
            DFS(start_vert, matr)
            break
        elif choice == "2":
            BFS(start_vert, matr)
            break
        else:
            print("В меню відсутній пункт", choice)

    graph.draw_graph(matr)
Ejemplo n.º 3
0
def main():
    matr = graph.output_file_content("input/4.txt") # 4, 1
    odd_verteces = check_for_euler_path(matr)

    # power of every vertex in the graph
    verteces_numb = []
    for line in matr:
        sum = 0
        for elem in line:
            if elem != 0:
                sum += 1
        verteces_numb.append(sum)
    
    print("Degree of the every vertex:")
    for i in range(len(verteces_numb)):
        print(i + 1, "-", verteces_numb[i])
    
    if odd_verteces == []:
        print("There is no Euler cycle in the graph")
    else:
        vertex = odd_verteces[0]
        find_euler_path([x[:] for x in matr], vertex)
    graph.draw_graph(matr)
Ejemplo n.º 4
0
def main():
    matr = gr.output_file_content("input/wiki.txt")  # hard
    start = int(
        input("Input start vertex (from 1 to n): ")) - 1  # start vertex
    finish = int(
        input("Input finish vertex (from 1 to n): ")) - 1  # finish vertex
    line = LeviticusAlgorithm(matr, start, finish)

    # transform to dict form
    n = len(matr)
    graph = {}
    for i in range(n):
        dct = {}
        for j in range(n):
            if i != j and matr[i][j] == 0:
                dct[j] = INF
            else:
                dct[j] = matr[i][j]
        graph[i] = dct

    DanzigAlgorithm(graph, start, finish)
    print("\n" + line)

    gr.draw_graph(matr)
Ejemplo n.º 5
0
def main():
    matr = graph.output_file_content("input/8.txt")
    FindPath(matr)
    graph.draw_graph(matr)
Ejemplo n.º 6
0
def main():
    matr = graph.output_file_content(
        "input/hard.txt")  # 1, 3, 4, 5, oriented, hard, cool
    DFS(matr)

    graph.draw_graph(matr)
Ejemplo n.º 7
0
def main():
    matr = graph.output_file_content("input/1.txt")
    topological_sorting(matr)
    graph.draw_graph(matr)
Ejemplo n.º 8
0
def main():
    matr = graph.output_file_content(
        "input/wiki.txt")  # 1, 3, 4, 5, oriented, hard, cool, wiki
    find_components(matr)

    graph.draw_graph(matr)