Exemplo n.º 1
0
Arquivo: Fparent.cs Projeto: Dasem/psu
        public void OutputMatrix(Object _Outparams)
        {
            Outparams    outpar    = (Outparams)_Outparams;
            RichTextBox  ForOut    = outpar.ForOutForm.richTextBox1;
            OperProgress prbarform = outpar.prbarform;
            Link         temp;
            int          count = 0;

            for (int i = 0; i < this.sizey; ++i)
            {
                for (int j = 0; j < this.sizex; ++j)
                {
                    if (!prbarform.IsDisposed)
                    {
                        if (!prbarform.IsDisposed)
                        {
                            prbarform.InvokeUI(() => { prbarform.progressBar1.Value = count; });
                        }
                        count++;
                    }
                    temp = this.columns[j];
                    bool F = true;
                    if (temp.next == null)//Если столбец пустой
                    {
                        ForOut.AppendText(TabSpaces(0));
                    }
                    else
                    {
                        while (temp.next != null && F)
                        {
                            if (temp.next.line_number == i)
                            {
                                ForOut.AppendText(TabSpaces(temp.next.inf));
                                F = false;
                            }
                            else
                            {
                                temp = temp.next;
                            }
                        }
                        if (F)
                        {
                            ForOut.AppendText(TabSpaces(0));
                        }
                    }
                }
                ForOut.AppendText("\n\n\n\n\n\n");
            }
            if (!prbarform.IsDisposed)
            {
                prbarform.InvokeUI(() => { prbarform.Close(); });
            }
            if (--this.count_readers == 0)
            {
                Fparent.names_collection[Fparent.names_collection.IndexOf(this.name + " (" + this.sizey.ToString() + "x" + this.sizex.ToString() + ") (чтение)")] = this.name + " (" + this.sizey.ToString() + "x" + this.sizex.ToString() + ")";
                Program.fr2.InvokeUI(() => { Program.fr2.ComboRefresh(); });
            }
            outpar.ForOutForm.ShowDialog();
        }
Exemplo n.º 2
0
Arquivo: Fparent.cs Projeto: Dasem/psu
        public void RI(int count)
        {
            Random       rnd   = new Random();
            int          x     = rnd.Next(0, this.sizex);
            int          y     = rnd.Next(0, this.sizey);
            OperProgress progr = new OperProgress();

            progr.Text = "Создание матрицы \"" + this.name + "\"";
            progr.progressBar1.Maximum = count;
            progr.Show();
            for (int i = 0; i < count; i++)
            {
                progr.progressBar1.Value = i;
                while (NotZero(x, y))
                {
                    x = rnd.Next(0, this.sizex);
                    y = rnd.Next(0, this.sizey);
                }
                this.columns[x].Insert(y, rnd.Next(-50, 51));
            }
            progr.Close();
        }
Exemplo n.º 3
0
Arquivo: Fparent.cs Projeto: Dasem/psu
        public void OutputMatrixPacked(Object _Outparams)
        {
            Outparams    outpar    = (Outparams)_Outparams;
            RichTextBox  outp      = outpar.ForOutForm.richTextBox1;
            OperProgress prbarform = outpar.prbarform;
            Link         temp;
            int          count = 0;

            outp.AppendText("Размерность матрицы, X:" + this.sizex.ToString() + ", Y:" + this.sizey.ToString() + "\n(X, Y, Значение)\n");
            for (int j = 0; j < sizex; ++j)
            {
                if (!prbarform.IsDisposed)
                {
                    prbarform.InvokeUI(() => { prbarform.progressBar1.Value = count; });
                    count++;
                }
                temp = columns[j];
                if (!(temp.next == null))
                {
                    while (temp.next != null)
                    {
                        outp.AppendText(j + 1 + " ");
                        outp.AppendText(temp.next.line_number + 1 + " ");
                        outp.AppendText(temp.next.inf.ToString() + "\n");
                        temp = temp.next;
                    }
                }
            }
            if (!prbarform.IsDisposed)
            {
                prbarform.InvokeUI(() => { prbarform.Close(); });
            }
            if (--this.count_readers == 0)
            {
                Fparent.names_collection[Fparent.names_collection.IndexOf(this.name + " (" + this.sizey.ToString() + "x" + this.sizex.ToString() + ") (чтение)")] = this.name + " (" + this.sizey.ToString() + "x" + this.sizex.ToString() + ")";
                Program.fr2.InvokeUI(() => { Program.fr2.ComboRefresh(); });
            }
            outpar.ForOutForm.ShowDialog();
        }
Exemplo n.º 4
0
Arquivo: Fparent.cs Projeto: Dasem/psu
        public void StructOutput(Object _Outparams)
        {
            Outparams    outpar    = (Outparams)_Outparams;
            RichTextBox  outp      = outpar.ForOutForm.richTextBox1;
            OperProgress prbarform = outpar.prbarform;
            Link         temp;
            int          count       = 0;
            int          memory_size = 0;

            for (int j = 0; j < this.sizex; ++j)
            {
                if (!prbarform.IsDisposed)
                {
                    prbarform.InvokeUI(() => { prbarform.progressBar1.Value = count; });
                    count++;
                }
                temp = this.columns[j];
                while (temp.next != null)
                {
                    memory_size += 12;
                    var safeptr = SafePtr.Create(temp.next);
                    outp.AppendText("Элемент " + temp.next.inf + " с координатами X:" + (j + 1) + " Y:" + (1 + temp.next.line_number) + " находится по адресу " + safeptr.IntPtr.ToString("x") + "\n");
                    temp = temp.next;
                }
            }
            if (!prbarform.IsDisposed)
            {
                prbarform.InvokeUI(() => { prbarform.Close(); });
            }
            outp.AppendText("\nОбщий объём памяти, занимаемый матрицой: " + memory_size / 1024.0 + " Кбайт\n");
            if (--this.count_readers == 0)
            {
                Fparent.names_collection[Fparent.names_collection.IndexOf(this.name + " (" + this.sizey.ToString() + "x" + this.sizex.ToString() + ") (чтение)")] = this.name + " (" + this.sizey.ToString() + "x" + this.sizex.ToString() + ")";
                Program.fr2.InvokeUI(() => { Program.fr2.ComboRefresh(); });
            }
            outpar.ForOutForm.ShowDialog();
        }
Exemplo n.º 5
0
Arquivo: Fparent.cs Projeto: 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(); });
            }
        }
Exemplo n.º 6
0
Arquivo: Fparent.cs Projeto: 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(); });
            }
        }