Exemplo n.º 1
0
    def test_minimum_spanning_tree(self):
        graph = hg.get_4_adjacency_graph((2, 3))

        edge_weights = np.asarray((1, 0, 2, 1, 1, 1, 2))

        mst = hg.minimum_spanning_tree(graph, edge_weights)
        mst_edge_map = hg.CptMinimumSpanningTree.get_edge_map(mst)

        self.assertTrue(mst.num_vertices() == 6)
        self.assertTrue(mst.num_edges() == 5)

        ref_sources = (0, 0, 1, 2, 1)
        ref_targets = (3, 1, 4, 5, 2)
        sources, targets = mst.edge_list()

        self.assertTrue(np.all(sources == ref_sources))
        self.assertTrue(np.all(targets == ref_targets))

        self.assertTrue(np.all(mst_edge_map == (1, 0, 3, 4, 2)))
Exemplo n.º 2
0
    def test_minimum_spanning_forest(self):
        graph = hg.UndirectedGraph(6)
        graph.add_edges((0, 0, 1, 3, 3, 4), (1, 2, 2, 4, 5, 5))

        edge_weights = np.asarray((0, 1, 2, 3, 4, 5))

        mst = hg.minimum_spanning_tree(graph, edge_weights)
        mst_edge_map = hg.CptMinimumSpanningTree.get_edge_map(mst)

        self.assertTrue(mst.num_vertices() == 6)
        self.assertTrue(mst.num_edges() == 4)

        ref_sources = (0, 0, 3, 3)
        ref_targets = (1, 2, 4, 5)
        sources, targets = mst.edge_list()

        self.assertTrue(np.all(sources == ref_sources))
        self.assertTrue(np.all(targets == ref_targets))

        self.assertTrue(np.all(mst_edge_map == (0, 1, 3, 4)))
Exemplo n.º 3
0
def MST(G):
  return hg.minimum_spanning_tree(G[0], G[1])