Exemplo n.º 1
0
    def test_component_s(self):
        self.assertTrue(self.graph.add_node(0))
        self.assertTrue(self.graph.add_node(1))
        self.assertTrue(self.graph.add_node(2))
        self.assertTrue(self.graph.add_node(3))

        self.assertTrue(self.graph.add_edge(0, 1, 1))
        self.assertTrue(self.graph.add_edge(1, 2, 1))
        self.assertTrue(self.graph.add_edge(2, 0, 0.5))
        self.assertTrue(self.graph.add_edge(2, 3, 0.5))

        algo = GraphAlgo(self.graph)
        p = algo.connected_components()
        self.assertEqual(p, [[0, 1, 2], [3]])
        p = algo.connected_component(3)
        p1 = algo.connected_component(1)
        self.assertEqual(p, [3])
        self.assertEqual(p1, [1, 2, 0])
Exemplo n.º 2
0
def my_graph(filename):
    algo = GraphAlgo()
    algo.load_from_json(filename)

    start = timeit.default_timer()
    algo.shortest_path(1, 5)
    stop = timeit.default_timer()
    print("my shoetest path ", (stop - start))

    start = timeit.default_timer()
    algo.connected_components()
    stop = timeit.default_timer()
    print("my connected components ", (stop - start))

    start = timeit.default_timer()
    algo.connected_component(0)
    stop = timeit.default_timer()
    print("my connected component ", (stop - start))