public static Answer Solve(Model _model) { if (_model == null) { return(null); } model = _model; if (model.CanonicalForm == null) { model.CanonicalForm = CanonicalGenerator.GenerateCanonicalForm(model, Algorithm.TwoPhaseSimplex); } double[][] table = model.CanonicalForm; Console.WriteLine(model.GenerateDisplayableCanonical()); FileHandler.Append(model.GenerateDisplayableCanonical(), "output.txt"); while (CheckIfDoneWithFirstPhase(table) == false) { //Console.WriteLine("Running"); double[] zRow = table[0]; int pivotColumnIndex = IdentifyPivotColumn(zRow); Console.WriteLine(pivotColumnIndex); double[] rhsValues = GetRHSValues(table); double[] columnValues = GetPivotColumnValues(table, pivotColumnIndex); int pivotRowIndex = IdentifyPivotRow(columnValues, rhsValues); Console.WriteLine(pivotRowIndex); table = Pivoting.PivotTable(table, pivotColumnIndex, pivotRowIndex); Console.WriteLine(CommonFunctions.GenerateTableIteration(model.DecisionVariables, table)); } Model modelForSimplex; double[][] newCanonical = CanonicalGenerator.GenerateSecondPhaseForTwoPhaseCanonical(model, table, out modelForSimplex); modelForSimplex.CanonicalForm = newCanonical; return(PrimalSimplex.Solve(modelForSimplex)); }
public static Answer Solve(Model _model) { if (_model == null) { return(null); } model = _model; if (model.CanonicalForm == null) { model.CanonicalForm = CanonicalGenerator.GenerateCanonicalForm(model, Algorithm.DualSimplex); } double[][] table = model.CanonicalForm; Console.WriteLine(model.GenerateDisplayableCanonical()); FileHandler.Append(model.GenerateDisplayableCanonical(), "output.txt"); while (CheckIfDoneWithDualPhase(table) == false) { //Console.WriteLine("Running"); double[] rhsValues = GetRHSValues(table); int pivotRowIndex = IdentifyPivotRow(rhsValues); double[] zRow = table[0]; double[] pivotRowValues = GetPivotRowValues(table, pivotRowIndex); if (CheckIfInfeasible(pivotRowValues)) { return(AnswerGenerator.GenerateInfeasibleAnswer(InfeasiblityReason.GeneralUnsolvability)); } int pivotColumnIndex = IdentifyPivotColumn(zRow, pivotRowValues); //Console.WriteLine(pivotColumnIndex); //Console.WriteLine(pivotRowIndex); table = Pivoting.PivotTable(table, pivotColumnIndex, pivotRowIndex); Console.WriteLine(CommonFunctions.GenerateTableIteration(model.DecisionVariables, table)); } Model modelForSimplex = model; modelForSimplex.CanonicalForm = table; return(PrimalSimplex.Solve(modelForSimplex)); }