Beispiel #1
0
    def experiment(nodes_start, nodes_end, edges_start, edges_end, nodes_step,
                   edges_step, algorithm, loop):

        graph = Graph(nodes_start, nodes_end, edges_start, edges_end,
                      nodes_step, edges_step, algorithm, loop)

        for nodes in range(nodes_start, nodes_end, nodes_step):
            S, T = set(nodes), set()

            current_node = random.sample(S, 1).pop()
            S.remove(current_node)
            T.add(current_node)

            # Utworzenie randomowo polaczonego grafu.
            while S:
                next_node = random.sample(nodes, 1).pop()
                if next_node not in T:
                    edge = (current_node, next_node)
                    graph.add_edge(edge)
                    S.remove(next_node)
                    T.add(next_node)
                current_node = next_node
            graph.add_random_edges(next_node)

            if algorithm == "kosaraju":
                kosaraju_strongly_connected_components(graph)
            else:
                naive_strongly_connected_components(graph)
Beispiel #2
0
    def test_very_long_path(self):
        n = 1000000

        result = kosaraju_strongly_connected_components(path(n))

        self.assertCountEqual(result, range(1, n+1))
Beispiel #3
0
    def test_three_separated_vertices(self):
        graph = [[], [], []]

        result = kosaraju_strongly_connected_components(graph)

        self.assertCountEqual(result, [1, 2, 3])
Beispiel #4
0
    def test_path(self):
        graph = [[1], [2], [3], [4], []]

        result = kosaraju_strongly_connected_components(graph)

        self.assertCountEqual(result, [1, 2, 3, 4, 5])
Beispiel #5
0
    def test_trivial_graph(self):
        graph = [[]]

        result = kosaraju_strongly_connected_components(graph)

        self.assertEqual(result, [1])