예제 #1
0
def test_intersection_and_reachability_empty_intersection():
    graph = main.Graph()
    aut = main.Graph()

    graph.read_graph_from_file("tests/hw2_test_mama_graph.txt")
    aut.parse_regex("tests/hw2_test_sobaka_regex.txt")
    intersection = main.Utils.get_intersection(graph, aut)
    assert not intersection.label_matrices
예제 #2
0
def test_intersection_and_reachability_intersection_vertices():
    graph = main.Graph()
    aut = main.Graph()

    graph.read_graph_from_file("tests/hw2_test_sobaka_graph.txt")
    aut.parse_regex("tests/hw2_test_sobaka_regex.txt")
    intersection = main.Utils.get_intersection(aut, graph)
    assert intersection.vertices_count == 35
예제 #3
0
def test_intersection_and_reachability_matrix_equality():
    graph = main.Graph()
    aut = main.Graph()

    graph.read_graph_from_file("tests/hw2_test_mama_graph.txt")
    aut.parse_regex("tests/hw2_test_mama_regex.txt")
    intersection = main.Utils.get_intersection(graph, aut)
    reachability_matrix = main.Utils.get_total_reachability(intersection)
    assert graph.label_matrices["mama"] == intersection.label_matrices["mama"]
    assert reachability_matrix == Matrix.dense(BOOL, 5, 5).full(True)
예제 #4
0
def test_hellings():
    grammar = main.Utils.read_grammar_from_file(
        "tests/hw4_test_hellings_grammar.txt")
    graph = main.Graph()
    graph.read_graph_from_file("tests/hw4_test_hellings_graph.txt")

    assert main.Utils.get_total_reachability(graph) == main.hellings(
        grammar, graph)
예제 #5
0
def test_cfpq_matrix_prod2():
    grammar = main.Utils.read_grammar_from_file(
        "tests/hw5_test_cfpq_matrix_prod2_grammar.txt")
    graph = main.Graph()
    graph.read_graph_from_file("tests/hw5_test_cfpq_matrix_prod1_graph.txt")

    expected = main.hellings(grammar, graph)
    actual = main.Utils.cfpq_matrix_product(graph, grammar)

    assert expected == actual

    actual = main.Utils.cfpq_tensor_product(graph, grammar)
    assert expected == actual
        start = time.time()
        print(main.dijkstra(temp, 0))
        end = time.time()
        timer.append((end - start) * 1000)  # đơn vị time là s

    pylab.plot(sizeInput, timer, 'o-')
    pylab.show()


# timmerPrim()

# ------------------------------------

# Thuật toán Kruskal
g_1 = main.Graph(4)
g_1.addEdge(0, 1, 10)
g_1.addEdge(0, 2, 6)
g_1.addEdge(0, 3, 5)
g_1.addEdge(1, 3, 15)
g_1.addEdge(2, 3, 4)

g_2 = main.Graph(10)
g_2.addEdge(0, 1, 10)
g_2.addEdge(0, 2, 6)
g_2.addEdge(0, 3, 5)
g_2.addEdge(0, 4, 8)
g_2.addEdge(0, 5, 9)
g_2.addEdge(0, 6, 12)
g_2.addEdge(0, 7, 14)
g_2.addEdge(0, 8, 4)
예제 #7
0
import main as m
import time

for number_of_times in range(5, 55, 5):
    average_p = 0
    best_p = 0
    worst_P = 0
    average_k = 0
    best_k = 0
    worst_k = 0

    for x in range(20):

        # calcuting time complexity for prim algorithm
        # initialization graph
        g = m.Graph(number_of_times)
        prim_algothim = m.Prim(g)

        # calculate time
        start_time_p = time.perf_counter()
        prim_algothim.prim()
        end_time_p = time.perf_counter()
        time_total = (end_time_p - start_time_p) * 1000
        # check for the best complexity
        if time_total < best_p or x == 0:
            best_p = time_total
        # check for the worst complexity
        if time_total > worst_P or x == 0:
            worst_P = time_total
        average_p += time_total