static void Main(string[] args) { double[,] coefs = { { -2, 1, 1, 0, 1, 0 }, { -1, -2, 0, 1, 3, 0 }, { 3, -1, 0, 0, -12, 1 } }; double[] basis = new double[] { 20, 24, 18 }; Sign[] signs = new Sign[] { Sign.Equal, Sign.Equal, Sign.Equal }; double[] objFunctionCoefs = new double[] { 1, -4, 1, 1, 1, 1 }; Coef[] ansCoefs = null; try { SymplexMatrix symplexMatrix = new SymplexMatrix(new ObjectiveFunction(objFunctionCoefs, Striving.Min), coefs, basis, signs); ConsoleSymplex.GetSolution(symplexMatrix); } catch (Exception e) { Console.WriteLine(e.Message); } }
public static Coef[] GetSolution(SymplexMatrix symplexMatrix) { /*if (symplexMatrix.ObjectiveFunction.Striving == Striving.Min) * { * symplexMatrix.ObjectiveFunction.SwapStriving(); * }*/ SymplexTable symplexTable = new SymplexTable(symplexMatrix); symplexTable.EventTableChanges += SymplexTableEventChanges; Coef[] coefs = symplexTable.GetSolution(); Console.WriteLine("Решение"); ShowVector(coefs); Console.WriteLine( $"Значение функции: {GetValueFun(symplexMatrix.ObjectiveFunction.Coefs.ToArray(), coefs)}"); var dualCoefs = symplexTable.GetDualSolution(); Console.WriteLine("Решение двойственной"); ShowVector(dualCoefs); return(coefs); }
public Coef[] GetDualSolution() { Coef[] coefs = new Coef[SymplexMatrix.GetCountBalance()]; for (int i = SymplexMatrix.ObjectiveFunction.Coefs.Count - SymplexMatrix.GetCountArtificial() - SymplexMatrix.GetCountBalance(), j = 0; i < SymplexMatrix.GetCountBalance(); i++, j++) { coefs[j].Value = LastsymplexDifference[i, 0]; coefs[j].TypeCoef = TypeCoef.Balance; } return(coefs); }
public SymplexTable(SymplexMatrix symplexMatrix) { SymplexMatrix = symplexMatrix; Table = new double[symplexMatrix.Basis.Length, SymplexMatrix.Coefs.GetLength(1) + SymplexMatrix.GetCountBalance() + SymplexMatrix.GetCountArtificial() + 1]; CurrentBasis = new Coef[SymplexMatrix.Basis.Length]; InitTable(); }