Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text.Trim();
            if (textBox1.Text == null || textBox1.Text == "")
            {
                MessageBox.Show("Поле \"Название матрицы\" не заполнено", "Ошибка");
                return;
            }
            if (textBox1.Text.Contains(' '))
            {
                MessageBox.Show("Название матрицы не должно содержать пробелов", "Ошибка");
                return;
            }
            foreach (var el in matrix_collection)
            {
                if (el.name == textBox1.Text)
                {
                    MessageBox.Show("Матрица с таким названием уже существует", "Ошибка");
                    return;
                }
            }
            if (numericUpDown1.Value <= 0)
            {
                MessageBox.Show("Количество столбцов задано некорректно", "Ошибка");
                return;
            }
            if (numericUpDown4.Value <= 0)
            {
                MessageBox.Show("Количество строк задано некорректно", "Ошибка");
                return;
            }
            if (richTextBox1.Text == "" || richTextBox1.Text == null)
            {
                MessageBox.Show("Поле для координат и значений элементов не заполнено", "Ошибка");
                return;
            }
            Matrix temp = new Matrix(Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown4.Value), textBox1.Text);

            if (temp.InputMatrix(richTextBox1))
            {
                matrix_collection.Add(temp);
                names_collection.Add(temp.name + " (" + temp.sizey.ToString() + "x" + temp.sizex.ToString() + ")");


                ComboRefresh();

                if (MessageBox.Show("Матрица \"" + textBox1.Text + "\" успешно добавлена, вывести на экран?", "Успех", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    OperProgress prbarform = new OperProgress();
                    prbarform.Show();
                    prbarform.progressBar1.Maximum = temp.sizex * temp.sizey;
                    Matrix.Outparams forout = new Matrix.Outparams(new ForOutputMatrix(temp.name, "matrix"), prbarform);
                    ReadThisMatrix(temp);
                    temp.count_readers++;
                    new Thread(temp.OutputMatrix).Start(forout);
                }
                Close();
            }
        }
Ejemplo n.º 2
0
        private void AddFromFile(object sender, EventArgs e)
        {
            textBox4.Text = textBox4.Text.Trim();
            if (textBox3.Text == null || textBox3.Text == "")
            {
                MessageBox.Show("Поле \"Путь к файлу\" не заполнено", "Ошибка");
                return;
            }
            if (textBox4.Text == null || textBox4.Text == "")
            {
                MessageBox.Show("Поле \"Название матрицы\" не заполнено", "Ошибка");
                return;
            }
            if (textBox4.Text.Contains(' '))
            {
                MessageBox.Show("Название матрицы не должно содержать пробелов", "Ошибка");
                return;
            }
            foreach (var el in matrix_collection)
            {
                if (el.name == textBox4.Text)
                {
                    MessageBox.Show("Матрица с таким названием уже существует", "Ошибка");
                    return;
                }
            }
            Matrix temp = new Matrix();

            if (temp.TxtInput(textBox3.Text, textBox4.Text))
            {
                matrix_collection.Add(temp);
                names_collection.Add(temp.name + " (" + temp.sizey.ToString() + "x" + temp.sizex.ToString() + ")");

                ComboRefresh();

                if (MessageBox.Show("Матрица \"" + textBox4.Text + "\" успешно добавлена, вывести на экран?", "Успех", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    OperProgress prbarform = new OperProgress();
                    prbarform.Show();
                    prbarform.progressBar1.Maximum = temp.sizex * temp.sizey;
                    Matrix.Outparams forout = new Matrix.Outparams(new ForOutputMatrix(temp.name, "matrix"), prbarform);
                    ReadThisMatrix(temp);
                    temp.count_readers++;
                    new Thread(temp.OutputMatrix).Start(forout);
                }
                Close();
            }
        }
Ejemplo n.º 3
0
        private void button2_Click(object sender, EventArgs e)
        {
            Random R = new Random();
            int    _sizex, _sizey, _count;

            textBox2.Text = textBox2.Text.Trim();
            if (textBox2.Text == null || textBox2.Text == "")
            {
                MessageBox.Show("Поле \"Название матрицы\" не заполнено", "Ошибка");
                return;
            }
            if (textBox2.Text.Contains(' '))
            {
                MessageBox.Show("Название матрицы не должно содержать пробелов", "Ошибка");
                return;
            }
            foreach (var el in matrix_collection)
            {
                if (el.name == textBox2.Text)
                {
                    MessageBox.Show("Матрица с таким названием уже существует", "Ошибка");
                    return;
                }
            }
            if (checkBox2.Checked == true)
            {
                _sizex = R.Next(5, 56);
                _sizey = R.Next(5, 56);
            }
            else
            {
                if (numericUpDown2.Value <= 0)
                {
                    MessageBox.Show("Размерность матрицы задана некорректно", "Ошибка");
                    return;
                }
                _sizex = Convert.ToInt32(numericUpDown2.Value);
                _sizey = Convert.ToInt32(numericUpDown5.Value);
            }
            if (checkBox1.Checked == true)
            {
                _count = R.Next(1, _sizex * _sizey / 10);
            }
            else
            {
                if (numericUpDown2.Value * numericUpDown5.Value < numericUpDown3.Value)
                {
                    MessageBox.Show("Количество ненулевых элементов больше размера матрицы", "Ошибка");
                    return;
                }
                if (numericUpDown3.Value <= 0)
                {
                    MessageBox.Show("Кол-во ненулевых элементов задано некорректно", "Ошибка");
                    return;
                }
                _count = Convert.ToInt32(numericUpDown3.Value);
                if (_count > _sizex * _sizey / 10)
                {
                    MessageBox.Show("Количество ненулевых элементов слишком велико, производительность операций может быть значительно снижена", "Предупреждение");
                }
            }
            Matrix temp = new Matrix(_sizex, _sizey, textBox2.Text);

            temp.RI(_count);
            matrix_collection.Add(temp);
            names_collection.Add(temp.name + " (" + temp.sizey.ToString() + "x" + temp.sizex.ToString() + ")");

            ComboRefresh();
            if (MessageBox.Show("Матрица \"" + textBox2.Text + "\" успешно добавлена, вывести на экран?", "Успех", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                OperProgress prbarform = new OperProgress();
                prbarform.Show();
                prbarform.progressBar1.Maximum = temp.sizex * temp.sizey;
                Matrix.Outparams forout = new Matrix.Outparams(new ForOutputMatrix(temp.name, "matrix"), prbarform);
                ReadThisMatrix(temp);
                temp.count_readers++;
                new Thread(temp.OutputMatrix).Start(forout);
            }
            Close();
        }
Ejemplo n.º 4
0
 private void button6_Click(object sender, EventArgs e)
 {
     if (ComboMainFormOutMatrix.SelectedItem.ToString().Split(' ').Length == 3 && ComboMainFormOutMatrix.SelectedItem.ToString().Split(' ')[2] == "(запись)")
     {
         MessageBox.Show("В матрицу ещё производится запись,пожалуйста, подождите", "Ошибка");
         return;
     }
     if (RadioOutFile.Checked && RadioOutMatrix.Checked)
     {
         if (ComboMainFormOutMatrix.SelectedIndex == -1)
         {
             MessageBox.Show("Матрица не выбрана", "Ошибка");
             return;
         }
         if (textBox1.Text == null || textBox1.Text == "")
         {
             MessageBox.Show("Поле \"Путь к файлу\" не заполнено", "Ошибка");
             return;
         }
         string[] combo_line = ComboMainFormOutMatrix.SelectedItem.ToString().Split(' ');
         foreach (var el in matrix_collection)
         {
             if (el.name == combo_line[0])
             {
                 if (el.TxtOutputMatrix(textBox1.Text))
                 {
                     MessageBox.Show("Матрица \"" + combo_line[0] + "\" выведена в файл \"" + textBox1.Text + "\"");
                 }
                 return;
             }
         }
     }
     else if (RadioOutMonitor.Checked && RadioOutMatrix.Checked)
     {
         if (ComboMainFormOutMatrix.SelectedIndex == -1)
         {
             MessageBox.Show("Матрица не выбрана", "Ошибка");
             return;
         }
         string[] combo_line = ComboMainFormOutMatrix.SelectedItem.ToString().Split(' ');
         foreach (var el in matrix_collection)
         {
             if (el.name == combo_line[0])
             {
                 OperProgress prbarform = new OperProgress();
                 prbarform.Show();
                 prbarform.progressBar1.Maximum = el.sizex * el.sizey;
                 Matrix.Outparams forout = new Matrix.Outparams(new ForOutputMatrix(el.name, "matrix"), prbarform);
                 ReadThisMatrix(el);
                 el.count_readers++;
                 threads.Add(new Thread(el.OutputMatrix));
                 Fparent.threads.Last().Start(forout);
                 return;
             }
         }
     }
     else if (RadioOutMemory.Checked && RadioOutMonitor.Checked)
     {
         if (ComboMainFormOutMatrix.SelectedIndex == -1)
         {
             MessageBox.Show("Матрица не выбрана", "Ошибка");
             return;
         }
         string[] combo_line = ComboMainFormOutMatrix.SelectedItem.ToString().Split(' ');
         foreach (var el in matrix_collection)
         {
             if (el.name == combo_line[0])
             {
                 OperProgress prbarform = new OperProgress();
                 prbarform.Show();
                 prbarform.progressBar1.Maximum = el.sizex;
                 Matrix.Outparams forout = new Matrix.Outparams(new ForOutputMatrix(el.name, "memory"), prbarform);
                 ReadThisMatrix(el);
                 el.count_readers++;
                 threads.Add(new Thread(el.StructOutput));
                 Fparent.threads.Last().Start(forout);
                 return;
             }
         }
     }
     else if (RadioOutCompress.Checked && RadioOutMonitor.Checked)
     {
         if (ComboMainFormOutMatrix.SelectedIndex == -1)
         {
             MessageBox.Show("Матрица не выбрана", "Ошибка");
             return;
         }
         string[] combo_line = ComboMainFormOutMatrix.SelectedItem.ToString().Split(' ');
         foreach (var el in matrix_collection)
         {
             if (el.name == combo_line[0])
             {
                 OperProgress prbarform = new OperProgress();
                 prbarform.Show();
                 prbarform.progressBar1.Maximum = el.sizex;
                 Matrix.Outparams forout = new Matrix.Outparams(new ForOutputMatrix(el.name, "compress"), prbarform);
                 ReadThisMatrix(el);
                 el.count_readers++;
                 threads.Add(new Thread(el.OutputMatrixPacked));
                 Fparent.threads.Last().Start(forout);
                 return;
             }
         }
     }
     else if (RadioOutCompress.Checked && RadioOutFile.Checked)
     {
         if (ComboMainFormOutMatrix.SelectedIndex == -1)
         {
             MessageBox.Show("Матрица не выбрана", "Ошибка");
             return;
         }
         if (textBox1.Text == null || textBox1.Text == "")
         {
             MessageBox.Show("Поле \"Путь к файлу\" не заполнено", "Ошибка");
             return;
         }
         string[] combo_line = ComboMainFormOutMatrix.SelectedItem.ToString().Split(' ');
         foreach (var el in matrix_collection)
         {
             if (el.name == combo_line[0])
             {
                 if (el.TxtOutputMatrixPacked(textBox1.Text))
                 {
                     MessageBox.Show("Матрица \"" + combo_line[0] + "\" выведена в файл \"" + textBox1.Text + "\"");
                 }
                 return;
             }
         }
     }
     else if (RadioOutMemory.Checked && RadioOutFile.Checked)
     {
         if (ComboMainFormOutMatrix.SelectedIndex == -1)
         {
             MessageBox.Show("Матрица не выбрана", "Ошибка");
             return;
         }
         if (textBox1.Text == null || textBox1.Text == "")
         {
             MessageBox.Show("Поле \"Путь к файлу\" не заполнено", "Ошибка");
             return;
         }
         string[] combo_line = ComboMainFormOutMatrix.SelectedItem.ToString().Split(' ');
         foreach (var el in matrix_collection)
         {
             if (el.name == combo_line[0])
             {
                 if (el.TxtOutputMemory(textBox1.Text))
                 {
                     MessageBox.Show("Матрица \"" + combo_line[0] + "\" выведена в файл \"" + textBox1.Text + "\"");
                 }
                 return;
             }
         }
     }
 }
Ejemplo n.º 5
0
Archivo: Fparent.cs Proyecto: Dasem/psu
        public static void MultMatrix(Object para)
        {
            Parms        par = (Parms)para;
            Matrix       mat1 = par.left, mat2 = par.right, result = par.result;
            OperProgress prbar = par.prbar;
            int          count = 0;

            while (!prbar.IsHandleCreated)
            {
                Thread.Sleep(10);
            }
            for (int i = 0; i < result.sizey; ++i)
            {
                if (!prbar.IsDisposed)
                {
                    prbar.InvokeUI(() => { prbar.progressBar1.Value = count; });
                }
                count++;
                for (int j = 0; j < result.sizex; ++j)
                {
                    int  sum             = 0;
                    Link temp            = mat2.columns[j].next;
                    Link current_pointer = temp;
                    while (temp != null)
                    {
                        sum += mat2.Exist(j, temp.line_number, ref current_pointer) * mat1.Exist(temp.line_number, i);
                        //sum += mat2.Exist(j, temp.line_number) * mat1.Exist(temp.line_number, i);
                        temp = temp.next;
                    }
                    if (sum != 0)
                    {
                        result.columns[j].Insert(i, sum);
                    }
                }
            }
            Fparent.names_collection[Fparent.names_collection.IndexOf(result.name + " (" + result.sizey.ToString() + "x" + result.sizex.ToString() + ") (запись)")] = result.name + " (" + result.sizey.ToString() + "x" + result.sizex.ToString() + ")";

            if (mat1.name == mat2.name)
            {
                mat1.count_readers--;
            }
            else
            {
                mat1.count_readers--;
                mat2.count_readers--;
            }
            if (mat1.count_readers == 0)
            {
                if (mat1.name != result.name)//для сброса наименования и возможности дальнейшей работы с матрицами
                {
                    try
                    {
                        Fparent.names_collection[Fparent.names_collection.IndexOf(mat1.name + " (" + mat1.sizey.ToString() + "x" + mat1.sizex.ToString() + ") (чтение)")] = mat1.name + " (" + mat1.sizey.ToString() + "x" + mat1.sizex.ToString() + ")";
                    }
                    catch
                    {
                        Fparent.names_collection[Fparent.names_collection.IndexOf(mat1.name + " (" + mat1.sizey.ToString() + "x" + mat1.sizex.ToString() + ") (запись)")] = mat1.name + " (" + mat1.sizey.ToString() + "x" + mat1.sizex.ToString() + ")";
                    }
                }
            }

            if (mat2.count_readers == 0)
            {
                if (mat2.name != result.name && mat2.name != mat1.name)
                {
                    try
                    {
                        Fparent.names_collection[Fparent.names_collection.IndexOf(mat2.name + " (" + mat2.sizey.ToString() + "x" + mat2.sizex.ToString() + ") (чтение)")] = mat2.name + " (" + mat2.sizey.ToString() + "x" + mat2.sizex.ToString() + ")";
                    }
                    catch
                    {
                        Fparent.names_collection[Fparent.names_collection.IndexOf(mat2.name + " (" + mat2.sizey.ToString() + "x" + mat2.sizex.ToString() + ") (запись)")] = mat2.name + " (" + mat2.sizey.ToString() + "x" + mat2.sizex.ToString() + ")";
                    }
                }
            }
            Program.fr2.InvokeUI(() => { Program.fr2.ComboRefresh(); });



            if (MessageBox.Show("Матрица \"" + result.name + "\" успешно добавлена, вывести результат?", "Успех", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Program.fr2.InvokeUI(() => { prbar.progressBar1.Maximum = result.sizex * result.sizey; });
                Matrix.Outparams forout = new Matrix.Outparams(new ForOutputMatrix(result.name, "matrix"), prbar);
                //   result.count_readers++;
                Fparent.names_collection[Fparent.names_collection.IndexOf(result.name + " (" + result.sizey.ToString() + "x" + result.sizex.ToString() + ")")] = result.name + " (" + result.sizey.ToString() + "x" + result.sizex.ToString() + ") (чтение)";
                Program.fr2.InvokeUI(() => { Program.fr2.ComboRefresh(); });
                result.count_readers++;
                Fparent.threads.Add(new Thread(result.OutputMatrix));
                Fparent.threads.Last().Start(forout);
            }
            else
            if (!prbar.IsDisposed)
            {
                prbar.InvokeUI(() => { prbar.Close(); });
            }
        }
Ejemplo n.º 6
0
Archivo: Fparent.cs Proyecto: Dasem/psu
        public static void ReverseMatrix(Object para)
        {
            Parms        par = (Parms)para;
            Matrix       mat = par.left, result = par.result;
            OperProgress prbar = par.prbar;

            bool[] cols = new bool[mat.sizex];
            bool[] rows = new bool[mat.sizex];
            for (int i = 0; i < cols.Length; ++i)
            {
                cols[i] = rows[i] = true;
            }
            int det = mat.DetMatrix(rows, cols, mat.sizex);

            if (det == 0)
            {
                try
                {
                    Fparent.names_collection[Fparent.names_collection.IndexOf(result.name + " (" + result.sizey.ToString() + "x" + result.sizex.ToString() + ") (запись)")] = result.name + " (" + result.sizey.ToString() + "x" + result.sizex.ToString() + ")";
                }
                catch
                {
                    Thread.Sleep(200);
                    try
                    {
                        Fparent.names_collection[Fparent.names_collection.IndexOf(result.name + " (" + result.sizey.ToString() + "x" + result.sizex.ToString() + ") (запись)")] = result.name + " (" + result.sizey.ToString() + "x" + result.sizex.ToString() + ")";
                    }
                    catch { }
                }
                --mat.count_readers;
                if (mat.count_readers == 0)
                {
                    if (mat.name != result.name)
                    {
                        try
                        {
                            Fparent.names_collection[Fparent.names_collection.IndexOf(mat.name + " (" + mat.sizey.ToString() + "x" + mat.sizex.ToString() + ") (чтение)")] = mat.name + " (" + mat.sizey.ToString() + "x" + mat.sizex.ToString() + ")";
                        }
                        catch
                        {
                            Fparent.names_collection[Fparent.names_collection.IndexOf(mat.name + " (" + mat.sizey.ToString() + "x" + mat.sizex.ToString() + ") (запись)")] = mat.name + " (" + mat.sizey.ToString() + "x" + mat.sizex.ToString() + ")";
                        }
                    }
                }

                Program.fr2.InvokeUI(() => { Program.fr2.ComboRefresh(); });

                if (!prbar.IsDisposed)
                {
                    prbar.InvokeUI(() => { prbar.Close(); });
                }
                par.isDetermNull = 1;
                MessageBox.Show("Определитель матрицы равен нулю, невозможно найти обратную", "Ошибка");
                return;
            }
            else
            {
                par.isDetermNull = 0;
            }
            int k     = 0;
            int count = 0;

            while (!prbar.IsHandleCreated)
            {
                Thread.Sleep(10);
            }
            for (int i = 0; i < result.sizey; ++i)
            {
                for (int j = 0; j < result.sizex; ++j)
                {
                    if (!prbar.IsDisposed)
                    {
                        prbar.InvokeUI(() => { prbar.progressBar1.Value = count; });
                    }
                    count++;
                    result.columns[i].Insert(j, Convert.ToInt32((mat.Minor(i, j, (bool[])rows.Clone(), (bool[])cols.Clone(), mat.sizex)) / det));
                    Console.WriteLine(++k);
                }
            }
            try
            {
                Fparent.names_collection[Fparent.names_collection.IndexOf(result.name + " (" + result.sizey.ToString() + "x" + result.sizex.ToString() + ") (запись)")] = result.name + " (" + result.sizey.ToString() + "x" + result.sizex.ToString() + ")";
            }
            catch
            {
                Thread.Sleep(200);
                Fparent.names_collection[Fparent.names_collection.IndexOf(result.name + " (" + result.sizey.ToString() + "x" + result.sizex.ToString() + ") (запись)")] = result.name + " (" + result.sizey.ToString() + "x" + result.sizex.ToString() + ")";
            }
            --mat.count_readers;
            if (mat.count_readers == 0)
            {
                if (mat.name != result.name)
                {
                    try
                    {
                        Fparent.names_collection[Fparent.names_collection.IndexOf(mat.name + " (" + mat.sizey.ToString() + "x" + mat.sizex.ToString() + ") (чтение)")] = mat.name + " (" + mat.sizey.ToString() + "x" + mat.sizex.ToString() + ")";
                    }
                    catch
                    {
                        Fparent.names_collection[Fparent.names_collection.IndexOf(mat.name + " (" + mat.sizey.ToString() + "x" + mat.sizex.ToString() + ") (запись)")] = mat.name + " (" + mat.sizey.ToString() + "x" + mat.sizex.ToString() + ")";
                    }
                }
            }
            Program.fr2.InvokeUI(() => { Program.fr2.ComboRefresh(); });

            if (MessageBox.Show("Матрица \"" + result.name + "\" успешно добавлена, вывести результат?", "Успех", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Program.fr2.InvokeUI(() => { prbar.progressBar1.Maximum = result.sizex * result.sizey; });
                Matrix.Outparams forout = new Matrix.Outparams(new ForOutputMatrix(result.name, "matrix"), prbar);
                //   result.count_readers++;
                Fparent.names_collection[Fparent.names_collection.IndexOf(result.name + " (" + result.sizey.ToString() + "x" + result.sizex.ToString() + ")")] = result.name + " (" + result.sizey.ToString() + "x" + result.sizex.ToString() + ") (чтение)";
                Program.fr2.InvokeUI(() => { Program.fr2.ComboRefresh(); });
                result.count_readers++;
                Fparent.threads.Add(new Thread(result.OutputMatrix));
                Fparent.threads.Last().Start(forout);
            }
            else
            if (!prbar.IsDisposed)
            {
                prbar.InvokeUI(() => { prbar.Close(); });
            }
        }