Esempio n. 1
0
        public void Solver_Should_Return_Fixed_Cycle_Points()
        {
            //Assert
            double[,] optimalityIndexTable = new double[3, 3]
            {
                { 0, 0, 3 },
                { 4, 0, 0 },
                { 5, -7, 0 }
            };

            var validResult = new Tuple <int, int>[]
            {
                new Tuple <int, int>(1, 1),
                new Tuple <int, int>(1, 2),
                new Tuple <int, int>(2, 1),
                new Tuple <int, int>(2, 2)
            };
            var solverResult = _solver.BuildCycle(optimalityIndexTable);

            Assert.IsTrue(CheckEquals(validResult.Select(i => i.Item1).ToArray(), solverResult.Select(i => i.Item1).ToArray()));
            Assert.IsTrue(CheckEquals(validResult.Select(i => i.Item2).ToArray(), solverResult.Select(i => i.Item2).ToArray()));
        }
Esempio n. 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();
        }