public static void Task7(IGraphAtoFactory graphFactory)
        {
            //var graph = graphFactory.CreateTwoPartsWeighedGraph(new int[,] {
            //                                                { 4,  3,  7,  9,  12, 10 },
            //                                                { 5,  7,  11, 10, 14, 6  },
            //                                                { 3,  8,  12, 11, 4,  9  },
            //                                                { 11, 9,  14, 7,  6,  13 },
            //                                                { 10, 12, 4,  3,  5,  8  },
            //                                                { 12, 4,  3,  8,  7,  12 },
            //                                                },
            //                                                    new[] { "1", "2", "3", "4", "5", "6" },
            //                                                    new[] { "A", "B", "C", "D", "E", "F" });
            var graph = graphFactory.CreateTwoPartsWeighedGraph(new int[, ] {
                { 8, 8, 1, 10, 4, 6, 6, 1 },
                { 6, 8, 8, 10, 3, 3, 3, 10 },
                { 3, 4, 10, 2, 3, 3, 3, 1 },
                { 8, 1, 6, 4, 4, 4, 9, 5 },
                { 2, 4, 9, 4, 5, 3, 3, 4 },
                { 1, 5, 4, 7, 2, 9, 3, 8 },
                { 8, 3, 3, 3, 4, 4, 4, 10 },
                { 8, 5, 1, 1, 1, 9, 8, 3 },
            },
                                                                new[] { "1", "2", "3", "4", "5", "6", "7", "8" },
                                                                new[] { "A", "B", "C", "D", "E", "F", "G", "H" });

            void OnStep(string info) => Console.WriteLine(info);

            var pairs = graph.ApplayHungarian(graphFactory, OnStep);

            Console.WriteLine(pairs.Print());
        }
Exemplo n.º 2
0
        public IWeighedPairsGraph Applay(ITwoPartsWeighedGraph graph)
        {
            var pairs      = _factory.CreateWeighedPairsGraph(graph.NodeXs, graph.NodeYs);
            var hard       = _factory.CreateTwoPartsWeighedGraph(graph.NodeXs, graph.NodeYs);
            var potentials = CreatePotential(graph.Nodes);
            int stepIndex  = 0;

            while (pairs.GetFree().FirstOrDefault() is { } node)
            {
                _onStep($"Шаг {stepIndex}");
                _onStep($"\tТекущая свободная вершина {node}");
                _onStep($"\tТекущие рёбра в графе H: {hard}");
                _onStep($"\tТекущие паросочетания: {pairs}");
                if (!TryIncreasePairs(pairs, node, hard, out IPairNode[] chainsNodeXs, out IPairNode[] chainsNodeYs))