Ejemplo n.º 1
0
        public static void PrimsMinimumSpanningTree_1()
        {
            {
                var expected = MstGraphA.OrderBy(e => e.from).ToArray();
                var actual   = PrimAlgorithm.MinimumSpanningTreeWithHeap(new ArrayGraph(graphA))
                               .OrderBy(e => e.from)
                               .ToArray();

                Assert.AreEqualSequences(expected, actual, EdgeComparer.UndirectedEdgeComparer);
            }

            {
                var expected = MstGraphB.OrderBy(e => e.from).ToArray();
                var actual   = PrimAlgorithm.MinimumSpanningTreeWithHeap(new ArrayGraph(graphB))
                               .OrderBy(e => e.from)
                               .ToArray();

                Assert.AreEqualSequences(expected, actual, EdgeComparer.UndirectedEdgeComparer);
            }

            //foreach (var edge in actual)
            //{
            //    Console.WriteLine($"{edge.from} -> {edge.to} \t {edge.weight}");
            //}
        }
Ejemplo n.º 2
0
        public static void KruskalMinimumSpanningTree()
        {
            {
                var expected = MstGraphA.OrderBy(e => e.weight).ToArray();
                var actual   = KruskalAlgorithm.MinimumSpanningTree(new ArrayGraph(graphA))
                               .OrderBy(e => e.weight)
                               .ToArray();

                Assert.AreEqualSequences(expected, actual, EdgeComparer.UndirectedEdgeComparer);
            }

            {
                var expected = MstGraphB.OrderBy(e => e.weight).ToArray();
                var actual   = KruskalAlgorithm.MinimumSpanningTree(new ArrayGraph(graphB))
                               .OrderBy(e => e.weight)
                               .ToArray();

                Assert.AreEqualSequences(expected, actual, EdgeComparer.UndirectedEdgeComparer);
            }
        }