Пример #1
0
 def test_mst_wiki(self):
     self.assertEqual(self.G.v(), self.N)
     algorithm = BoruvkaMST(self.G)
     algorithm.run()
     self.assertEqual(algorithm.mst.v(), self.N)
     self.assertEqual(algorithm.mst.e(), self.N - 1)
     mst_weight_expected = 40
     mst_weight = sum(edge.weight for edge in algorithm.mst.iteredges())
     self.assertEqual(mst_weight, mst_weight_expected)
     mst_edges_expected = [Edge(0, 1, 7), Edge(0, 3, 4), Edge(2, 4, 5), Edge(1, 4, 10), Edge(4, 6, 8), Edge(3, 5, 6)]
     for edge in mst_edges_expected:
         self.assertTrue(algorithm.mst.has_edge(edge))
Пример #2
0
 def test_boruvka(self):
     self.assertEqual(self.G.v(), self.N)
     algorithm = BoruvkaMST(self.G)
     algorithm.run()
     self.assertEqual(algorithm.mst.v(), self.N)
     self.assertEqual(algorithm.mst.e(), self.N-2) # 2 components
     mst_weight_expected = 40
     mst_weight = sum(edge.weight for edge in algorithm.mst.iteredges())
     self.assertEqual(mst_weight, mst_weight_expected)
     mst_edges_expected = [
         Edge(0, 1, 4), Edge(0, 7, 8), Edge(8, 2, 2), Edge(7, 6, 1), 
         Edge(6, 8, 6), Edge(3, 4, 9), Edge(5, 4, 10)]
     for edge in mst_edges_expected:
         self.assertTrue(algorithm.mst.has_edge(edge))
Пример #3
0
 def test_boruvka(self):
     self.assertEqual(self.G.v(), self.N)
     algorithm = BoruvkaMST(self.G)
     algorithm.run()
     self.assertEqual(algorithm.mst.v(), self.N)
     self.assertEqual(algorithm.mst.e(), self.N-1)
     mst_weight_expected = 40
     mst_weight = sum(edge.weight for edge in algorithm.mst.iteredges())
     self.assertEqual(mst_weight, mst_weight_expected)
     mst_edges_expected = [
         Edge(0, 1, 7), Edge(0, 3, 4), Edge(2, 4, 5), Edge(1, 4, 10), 
         Edge(4, 6, 8), Edge(3, 5, 6)]
     for edge in mst_edges_expected:
         self.assertTrue(algorithm.mst.has_edge(edge))
Пример #4
0
 def test_mst_cormen(self):
     self.assertEqual(self.G.v(), self.N)
     algorithm = BoruvkaMST(self.G)
     algorithm.run()
     self.assertEqual(algorithm.mst.v(), self.N)
     self.assertEqual(algorithm.mst.e(), self.N - 1)
     mst_weight_expected = 42
     mst_weight = sum(edge.weight for edge in algorithm.mst.iteredges())
     self.assertEqual(mst_weight, mst_weight_expected)
     mst_edges_expected = [
         Edge(0, 1, 4),
         Edge(0, 7, 8),
         Edge(8, 2, 2),
         Edge(7, 6, 1),
         Edge(2, 5, 5),
         Edge(6, 5, 3),
         Edge(3, 4, 9),
         Edge(5, 4, 10)
     ]
     for edge in mst_edges_expected:
         self.assertTrue(algorithm.mst.has_edge(edge))
Пример #5
0
 def test_mst_cormen(self):
     self.assertEqual(self.G.v(), self.N)
     algorithm = BoruvkaMST(self.G)
     algorithm.run()
     self.assertEqual(algorithm.mst.v(), self.N)
     self.assertEqual(algorithm.mst.e(), self.N - 1)
     mst_weight_expected = 42
     mst_weight = sum(edge.weight for edge in algorithm.mst.iteredges())
     self.assertEqual(mst_weight, mst_weight_expected)
     mst_edges_expected = [
         Edge(0, 1, 4),
         Edge(0, 7, 8),
         Edge(8, 2, 2),
         Edge(7, 6, 1),
         Edge(2, 5, 5),
         Edge(6, 5, 3),
         Edge(3, 4, 9),
         Edge(5, 4, 10),
     ]
     for edge in mst_edges_expected:
         self.assertTrue(algorithm.mst.has_edge(edge))