def build_G_20000_160000_0():
    algo = GraphAlgo()
    st = time.time()
    flag = algo.load_from_json("../data/G_20000_160000_0.json")
    if flag:
        print("successfully construction from \"G_20000_160000_0.json\" run time: ", round(time.time() - st, 3), " sec")
        st = time.time()
        algo.shortest_path(5000, 15250)
        print("shortest_path 5000 -->> 15250 run time: ", round(time.time() - st, 3), " sec")
        st = time.time()
        algo.connected_component(0)
        print("connected_component - node 0 run time: ", round(time.time() - st, 3), " sec")
        st = time.time()
        algo.connected_components()
        print("connected_components run time: ", round(time.time() - st, 3), " sec")
Example #2
0
 def test_connected_component(self):
     graph = self.create_graph()
     g_algo = GraphAlgo(None)
     x = []
     self.assertEqual(x, g_algo.connected_components())
     g_algo = GraphAlgo(graph)
     x = []
     self.assertEqual(x, g_algo.connected_component(20))
     x = [0, 1, 2, 3, 4, 5]
     self.assertEqual(x, g_algo.connected_component(0))
     graph.remove_edge(3, 2)
     x = [0, 1, 2]
     self.assertEqual(x, g_algo.connected_component(0))
     graph.add_edge(3, 2, 1)
     graph.add_edge(6, 5, 7)
     graph.add_edge(9, 8, 2)
     x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
     self.assertEqual(x, g_algo.connected_component(5))
Example #3
0
def check2():
    """ This function tests the naming, basic testing over A5 json file.
      :return:
      """
    g_algo = GraphAlgo()
    file = '../data/A5'
    g_algo.load_from_json(file)
    g_algo.get_graph().remove_edge(13, 14)
    g_algo.save_to_json(file + "_edited")
    dist, path = g_algo.shortest_path(1, 7)
    print(dist, path)
    dist, path = g_algo.shortest_path(47, 19)
    print(dist, path)
    dist, path = g_algo.shortest_path(20, 2)
    print(dist, path)
    dist, path = g_algo.shortest_path(2, 20)
    print(dist, path)
    print(g_algo.connected_component(0))
    print(g_algo.connected_components())
    g_algo.plot_graph()