Ejemplo n.º 1
0
        private void button_Calculate_Click(object sender, EventArgs e)
        {
            try
            {
                ClearDataGridColor(dataGridView_Result);

                _homory = ReadHomoryMethod();
                FillDataGrid(_homory, dataGridView_Result);

                if (_homory.Table.IsEnd())
                {
                    MessageBox.Show("Симплекс метод завершено");
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Ejemplo n.º 2
0
        public void FillDataGrid(Homory homory, DataGridView dgv)
        {
            // simplexTable
            if (homory.IsSimplexMethod)
            {
                // головні змінні + для функції
                dgv.RowCount = homory.Table.NumberOfRows + 1;
                // mainVariables + basis variables + basis + freeValues + EstimateRelations
                dgv.ColumnCount = homory.Table.NumberOfCollumns + 3;
            }
            else
            {
                //doubleSimplexTable
                // головні змінні + для функції + EstimateRelations
                dgv.RowCount = homory.Table.NumberOfRows + 2;
                // mainVariables + basis variables + basis + freeValues
                dgv.ColumnCount = homory.Table.NumberOfCollumns + 2;
            }
            foreach (DataGridViewColumn column in dgv.Columns)
            {
                column.SortMode = DataGridViewColumnSortMode.NotSortable;
            }

            dgv.Rows[homory.Table.MainRowForNextStep].Cells[homory.Table.MainCollumnForNextStep + 2].Style.BackColor = Color.AntiqueWhite;
            if (homory.Table.MainRow != -1)
            {
                dgv.Rows[homory.Table.MainRow].Cells[homory.Table.MainCollumn + 2].Style.BackColor = Color.White;
            }

            // basis
            dgv.Columns[0].HeaderText = "Базис";
            for (int i = 0; i < homory.Table.NumberOfRows; i++)
            {
                dgv.Rows[i].Cells[0].Value = homory.Table.Basis[i] + 1;
            }

            // freeValues
            dgv.Columns[1].HeaderText = "Вільні члени";
            for (int i = 0; i < homory.Table.NumberOfRows; i++)
            {
                dgv.Rows[i].Cells[1].Value = Math.Round(homory.Table.FreeValues[i], 2);
            }

            // variables
            for (int i = 0; i < homory.Table.NumberOfCollumns; i++)
            {
                dgv.Columns[i + 2].HeaderText = "X" + (i + 1);
                for (int j = 0; j < homory.Table.NumberOfRows; j++)
                {
                    dgv.Rows[j].Cells[i + 2].Value = Math.Round(homory.Table.Variables[j][i], 2);
                }
            }

            // function
            dgv.Rows[homory.Table.NumberOfRows].Cells[0].Value = "F";
            dgv.Rows[homory.Table.NumberOfRows].Cells[1].Value = homory.Table.FunctionResult;
            for (int i = 0; i < homory.Table.NumberOfCollumns; i++)
            {
                dgv.Rows[homory.Table.NumberOfRows].Cells[i + 2].Value = Math.Round(homory.Table.Function[i], 2);
            }


            // simplexTable
            if (homory.IsSimplexMethod)
            {
                // Estimate relations
                for (int i = 0; i < homory.Table.NumberOfRows; i++)
                {
                    if (homory.Table.EstimateRelations[i] < 0)
                    {
                        dgv.Rows[i].Cells[dgv.ColumnCount - 1].Value = 1.0f / 0;
                    }
                    else
                    {
                        dgv.Rows[i].Cells[dgv.ColumnCount - 1].Value = Math.Round(homory.Table.EstimateRelations[i], 2);
                    }
                }
            }
            // double simplexTable
            else
            {
                // Estimate relations
                for (int i = 2; i < homory.Table.EstimateRelations.Length + 2; i++)
                {
                    if (Double.IsNaN(homory.Table.EstimateRelations[i - 2]))
                    {
                        dgv.Rows[dgv.RowCount - 1].Cells[i].Value = 1.0f / 0;
                    }
                    else
                    {
                        dgv.Rows[dgv.RowCount - 1].Cells[i].Value = Math.Round(homory.Table.EstimateRelations[i - 2], 2);
                    }
                }
            }
        }