Exemplo n.º 1
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))
Exemplo n.º 2
0
    def test_shortest_path2(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_edge(0, 1, 1))
        self.assertTrue(self.graph.add_edge(1, 2, 1))
        self.assertTrue(self.graph.add_edge(0, 2, 0.5))

        algo = GraphAlgo(self.graph)

        p = algo.shortest_path(0, 2)
        self.assertEqual(p[0], 0.5)
        self.assertEqual(p[1], [0, 2])