示例#1
0
        public void Solver_Shoult_Return_Fixed_NextBaseSolution()
        {
            //Arrange
            double[,] optimalityIndexTable = new double[3, 3]
            {
                { 0, 0, 3 },
                { 4, 0, 0 },
                { 5, -7, 0 }
            };

            var cyclePoints = _solver.BuildCycle(optimalityIndexTable);

            var baseSolution = new double[, ]
            {
                { 20, 30, 0 },
                { 0, 10, 60 },
                { 0, 0, 30 }
            };
            var validNextBaseSolution = new double[, ]
            {
                { 20, 30, 0 },
                { 0, 0, 70 },
                { 0, 10, 20 }
            };

            var solverResult = _solver.SolveTheCycle(cyclePoints, baseSolution);

            Assert.IsTrue(CheckEquals(validNextBaseSolution, solverResult));
        }
示例#2
0
        private async void Solve()
        {
            _solver = new TransportIssueSolver();

            double baseZ            = 0;
            double optimalZ         = 0;
            Form2  form             = new Form2();
            string baseSolutionText = string.Empty;
            await Task.Run(() =>
            {
                var b = _solver.FindaBaseSolution(_costs, _providers, _recipents);



                baseZ = _solver.getZ(_costs, b);

                var reversedCostsTable = _solver.InverseCostsMatrix(_costs, b);

                while (true)
                {
                    var dualVariables = _solver.BuildDualVariables(reversedCostsTable);

                    var alfa = dualVariables.Item1;
                    var beta = dualVariables.Item2;

                    var reversedBaseSolution = _solver.InverseBaseSolutionMatrix(b, _costs);
                    var optimalityTable      = _solver.BuildOptimalityIndexTable(reversedBaseSolution, alfa, beta);

                    if (_solver.isOptimal(optimalityTable))
                    {
                        break;
                    }

                    var cyclePoints = _solver.BuildCycle(optimalityTable);
                    b = _solver.SolveTheCycle(cyclePoints, b);
                }

                optimalZ = _solver.getZ(_costs, b);

                baseSolutionText = $"{b[0, 0]} {b[0, 1]} {b[0, 2]} \n" +
                                   $"{b[1, 0]} {b[1, 1]} {b[1, 2]} \n" +
                                   $"{b[2, 0]} {b[2, 1]} {b[2, 2]}";
            });


            label1.Text = $"Bazowe Z: {baseZ}";
            label2.Text = $"Optymalne Z {optimalZ}";
            form.Text   = baseSolutionText;
            form.Show();
        }