예제 #1
0
        public void GreedySimple()
        {
            var vertices = Generator.VerticesInIdRange(0, 6);
            var graph    = new MutableGraph();

            graph.Vertices.AddRange(vertices);
            graph.ConnectAll(vertices[0], vertices[3]);
            graph.ConnectAll(vertices[0], vertices[4]);
            graph.ConnectAll(vertices[0], vertices[5]);
            graph.ConnectAll(vertices[1], vertices[3]);
            graph.ConnectAll(vertices[1], vertices[4]);
            graph.ConnectAll(vertices[1], vertices[5]);
            graph.ConnectAll(vertices[2], vertices[3]);
            graph.ConnectAll(vertices[2], vertices[4]);
            graph.ConnectAll(vertices[2], vertices[5]);

            var coloring = graph.ToImmutable().ColorGreedily();

            Assert.Equal(1, coloring[0]);
            Assert.Equal(1, coloring[1]);
            Assert.Equal(1, coloring[2]);
            Assert.Equal(2, coloring[3]);
            Assert.Equal(2, coloring[4]);
            Assert.Equal(2, coloring[5]);
        }
예제 #2
0
        public void ColoringOptimization()
        {
            var vertices = Generator.VerticesInIdRange(0, 3);
            var graph    = new MutableGraph();

            graph.Vertices.AddRange(vertices);
            graph.ConnectAll(vertices[0], vertices[1]);
            graph.ConnectAll(vertices[0], vertices[2]);

            var coloring = graph.ToImmutable().ColorGreedily();

            var originalCost = coloring.SummaryCost;

            var optimizedColoring = coloring.OptimizeByWeighting();

            var optimizedCost = optimizedColoring.SummaryCost;

            Assert.Equal(5, originalCost);
            Assert.Equal(4, optimizedCost);
        }