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(); }
public void Solver_Should_Return_Fixed_DualVariables() { //Arrange double[,] input = new double[, ] { { 3, 5, 0 }, { 0, 10, 9 }, { 0, 0, 9 } }; double[] validAlfa = new double[] { 0, -5, -5 }; double[] validBeta = new double[] { -3, -5, -4 }; //Act var solutions = _solver.BuildDualVariables(input); //Assert Assert.IsTrue(CheckEquals(solutions.Item1, validAlfa)); Assert.IsTrue(CheckEquals(solutions.Item2, validBeta)); }