// выбор опорного элемента public static void SelectSupportElem(LinearProgrammingProblem lpp, out int column, out int row, string method, Fraction[,] matrixIn) { column = -1; row = -1; Fraction[,] matrix = (Fraction[, ])matrixIn.Clone(); int columns = matrix.GetLength(0); int rows = matrix.GetLength(1); Fraction[] supportElementsIndex = new Fraction[columns]; for (int i = 1; i < columns - 1; i++) { supportElementsIndex[i] = MAB_SM.FindSupportMinRatio(i, matrix); } bool flagSupportElem = false; for (int y = 0; y < rows && !flagSupportElem; y++) { for (int x = 0; x < columns; x++) { Fraction ratio = matrix[columns - 1, y] / matrix[x, y]; if (x != 0 && x != columns - 1 && y != 0 && y != rows - 1 && supportElementsIndex[x] != null && supportElementsIndex[x].IsEquals(ratio) && matrix[x, y] > 0 && !flagSupportElem) { switch (method) { case "MAB": if (matrix[0, y] >= lpp.matrix2.GetLength(0)) { column = x; row = y; flagSupportElem = true; } break; case "SM": column = x; row = y; flagSupportElem = true; break; } } } } }
// отбразить матрицу мет. иск. баз./ сим. мет. public static void InitializeGrid_3_4(MainWindow w, string method, Grid grid, Fraction[,] matrix) { // изменить доступность кнопок навигации switch (method) { case "MAB": ChangePropertiesButton_Enabled_1(w); break; case "SM": ChangePropertiesButton_Enabled_2(w); break; } // grid - где отображаем if (grid != null) { int columns; int rows; // разлинеить сетку DisplayGrid_3_4(w, grid, matrix, out columns, out rows); // минимальные отношения b/a в каждом столбце Fraction[] minRatio = new Fraction[columns]; for (int i = 1; i < columns - 1; i++) { minRatio[i] = MAB_SM.FindSupportMinRatio(i, matrix); } // флаг зацикливания bool flagCycle = true; // добавить TextBox/Label в grid for (int y = 0; y < rows; y++) { for (int x = 0; x < columns; x++) { if (MAB_SM.IsCanBeSupperElem(matrix, columns, rows, minRatio, y, x)) { switch (method) { case "MAB": // в строке вспомогательный х if (matrix[0, y] >= w.lpp.matrix2.GetLength(0)) { DisplayButton(w, grid, matrix, y, x); flagCycle = false; } else { DisplayLabel(grid, matrix, y, x); }; break; case "SM": DisplayButton(w, grid, matrix, y, x); flagCycle = false; break; } } else { DisplayLabel(grid, matrix, y, x); } } } if (flagCycle && w.message.Content.Equals("")) { w.message.Content = "Нет подходящего опорного элемента. Найден цикл"; } } }