Esempio n. 1
0
        private void ReadSimplexMethod()
        {
            ClearDataGridColor(dataGridView_Result);

            int numberOfRows     = dataGridView_InputData_Methods.RowCount;
            int numberOfCollumns = dataGridView_InputData_Methods.ColumnCount;

            double[][] mainArray = new double[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++)
            {
                mainArray[i] = new double[numberOfCollumns];
                for (int j = 0; j < numberOfCollumns; j++)
                {
                    mainArray[i][j] = Convert.ToDouble(dataGridView_InputData_Methods.Rows[i].Cells[j].Value);
                }
            }

            double[] function = new double[numberOfCollumns];
            for (int i = 0; i < numberOfCollumns; i++)
            {
                function[i] = 1;
            }

            double[] freeValues = new double[numberOfRows];
            for (int i = 0; i < numberOfRows; i++)
            {
                freeValues[i] = 1;
            }

            Compare[] signs = new Compare[numberOfRows];
            for (int i = 0; i < numberOfRows; i++)
            {
                signs[i] = Compare.LessEqual;
            }

            Direction direction = Direction.Max;

            SimplexMethod simplexMethod = new SimplexMethod(numberOfRows, numberOfCollumns, mainArray, function,
                                                            freeValues, signs, direction);

            _table = simplexMethod.MakeSimplexTable();

            FillDataGrid(_table, dataGridView_Result);

            if (_table.Function[_table.MainCollumnForNextStep] >= 0)
            {
                MessageBox.Show("Оптимальний план знайдено.\nЗначення функції - " + _table.FunctionResult + ".");
            }
        }
Esempio n. 2
0
        public Homory ReadHomoryMethod()
        {
            int numberOfRows     = Convert.ToInt32(numericUpDown_InputData_Rows.Value);
            int numberOfCollumns = Convert.ToInt32(numericUpDown_InputData_Collumns.Value);

            double[][] mainArray = new double[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++)
            {
                mainArray[i] = new double[numberOfCollumns];
            }

            for (int i = 0; i < numberOfRows; i++)
            {
                for (int j = 0; j < numberOfCollumns; j++)
                {
                    mainArray[i][j] = Convert.ToDouble(dataGridView_InputData_Methods.Rows[i].Cells[j].Value);
                }
            }

            double[] function = new double[numberOfCollumns];
            for (int i = 0; i < numberOfCollumns; i++)
            {
                function[i] = Convert.ToDouble(dataGridView_InputData_Function.Rows[0].Cells[i].Value);
            }

            double[] freeValues = new double[numberOfRows];
            for (int i = 0; i < numberOfRows; i++)
            {
                freeValues[i] = Convert.ToDouble(dataGridView_InputData_FreeValues.Rows[i].Cells[0].Value);
            }

            Compare[] signs = new Compare[numberOfRows];
            for (int i = 0; i < numberOfRows; i++)
            {
                signs[i] = Convert.ToString(dataGridView_InputData_Signs.Rows[i].Cells[0].Value) == "="
                    ? Compare.Equal
                    : Convert.ToString(dataGridView_InputData_Signs.Rows[i].Cells[0].Value) == ">="
                        ? Compare.MoreEqual
                        : Compare.LessEqual;
            }

            Direction direction = radioButton_InputData_Max.Checked ? Direction.Max : Direction.Min;

            SimplexMethod simplexMethod = new SimplexMethod(numberOfRows, numberOfCollumns, mainArray, function,
                                                            freeValues, signs, direction);

            return(new Homory(simplexMethod.MakeSimplexTable()));
        }
Esempio n. 3
0
        private void button_Calculate_Click(object sender, EventArgs e)
        {
            try
            {
                ClearDataGrid(dataGridView_Result);

                int numberOfRows     = Convert.ToInt32(numericUpDown_InputData_Rows.Value);
                int numberOfCollumns = Convert.ToInt32(numericUpDown_InputData_Collumns.Value);

                double[][] mainArray = new double[numberOfRows][];
                for (int i = 0; i < numberOfRows; i++)
                {
                    mainArray[i] = new double[numberOfCollumns];
                }

                for (int i = 0; i < numberOfRows; i++)
                {
                    for (int j = 0; j < numberOfCollumns; j++)
                    {
                        mainArray[i][j] = Convert.ToDouble(dataGridView_InputData_Methods.Rows[i].Cells[j].Value);
                    }
                }

                double[] function = new double[numberOfCollumns];
                for (int i = 0; i < numberOfCollumns; i++)
                {
                    function[i] = Convert.ToDouble(dataGridView_InputData_Function.Rows[0].Cells[i].Value);
                }

                double[] freeValues = new double[numberOfRows];
                for (int i = 0; i < numberOfRows; i++)
                {
                    freeValues[i] = Convert.ToDouble(dataGridView_InputData_FreeValues.Rows[i].Cells[0].Value);
                }

                Compare[] signs = new Compare[numberOfRows];
                for (int i = 0; i < numberOfRows; i++)
                {
                    signs[i] = Convert.ToString(dataGridView_InputData_Signs.Rows[i].Cells[0].Value) == "="
                        ? Compare.Equal
                        : Convert.ToString(dataGridView_InputData_Signs.Rows[i].Cells[0].Value) == ">="
                            ? Compare.MoreEqual
                            : Compare.LessEqual;
                }

                Direction direction = radioButton_InputData_Max.Checked ? Direction.Max : Direction.Min;

                SimplexMethod simplexMethod = new SimplexMethod(numberOfRows, numberOfCollumns, mainArray, function,
                                                                freeValues, signs, direction);


                if (comboBox_ChooseMethod.SelectedIndex == 0)
                {
                    _table = simplexMethod.MakeSimplexTable();
                }
                else
                {
                    _table = simplexMethod.MakeDoubleSimplexTable();
                }
                FillDataGrid(_table, dataGridView_Result);

                if (comboBox_ChooseMethod.SelectedIndex == 0 && _table.Function[_table.MainCollumnForNextStep] >= 0)
                {
                    MessageBox.Show("Оптимальний план знайдено.\nЗначення функції - " + _table.FunctionResult + ".");
                }
                if (comboBox_ChooseMethod.SelectedIndex == 1 && _table.FreeValues[_table.MainRowForNextStep] >= 0)
                {
                    MessageBox.Show("Оптимальний план знайдено.\nЗначення функції - " + _table.FunctionResult + ".");
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }