Esempio n. 1
0
        /// <summary>
        /// возвращает смежную матрицу узлов
        /// </summary>
        /// <param name="colrow">строки - количество связей входящих</param>
        /// <param name="colcol">столбцы - длинна одной линии значений (они все одинаковые должны быть, если не было ошибок)</param>
        /// <returns></returns>
        public MatrixСмежная[][] getMatrixСмежность(Node_struct tmpinode, int colrow, int colcol, List <Node_struct> listik)
        {
            MatrixСмежная[][]  mat     = new MatrixСмежная[colrow][];
            List <Node_struct> idnodes = new List <Node_struct>();

            for (int i = 0; i < colrow; i++)
            {
                mat[i] = new MatrixСмежная[colcol];
                for (int j = 0; j < colcol; j++)
                {
                    mat[i][j]          = new MatrixСмежная();
                    mat[i][j].nod      = new Node_struct();
                    mat[i][j].property = new Propertys_struct();
                    mat[i][j].value    = new double();
                }
            }
            foreach (var nood in tmpinode.connects_in)
            {
                idnodes.Add(nood);
            }
            if (idnodes.Count == 0)
            {
                return(mat);
            }
            for (int i = 0; i < idnodes.Count - 1; i++)
            {
                for (int j = i + 1; j < idnodes.Count; j++)
                {
                    if (idnodes[i].ID > idnodes[j].ID)
                    {
                        Node_struct aw = idnodes[i];
                        idnodes[i] = idnodes[j];
                        idnodes[j] = aw;
                    }
                }
            }
            //сформировали список индексов в листе tmp тех узлов с которыми у нас есть связь, чтобы не приходилось их потом вылавливать
            for (int i = colrow - 1, index = 0, h = 1; i >= 0; i--, index++)
            {
                //цикл движется от последней строки до первой
                //в строке он заполняет ячейки матрицы ид нода и названием (уникально в пределах нода) нужного свойства
                int hh = 0; var othnod = idnodes[i];
                for (int j = 0, ij = 0; j < colcol; j++)
                {
ifigoto:
                    if (hh < h)
                    {
                        mat[i][j].nod      = othnod;
                        mat[i][j].property = othnod.props[ij];
                        hh++;
                    }
                    else
                    {
                        ij++;
                        if (ij >= othnod.props.Count)
                        {
                            ij = 0;
                        }
                        hh = 0;
                        goto ifigoto;
                    }
                }
                if (h == 1)
                {
                    h = othnod.props.Count;
                }
                else
                {
                    h = h * othnod.props.Count;
                }
            }
            //получили верхнюю часть матрицы смежности поидее в нужном нам виде.
            return(mat);
        }
Esempio n. 2
0
        private List <Node_struct> MathДетейПоИзвестномуРодителю(Node_struct nod, List <Node_struct> list)
        {
metkaошибказаполнителя:
            int rows = -1, column = -1;

            rows   = getMatСмежКолСтрок(nod, false);
            column = getMatCмежКолСтолбцов(nod, false);
            if (rows == -1 || column == -1)
            {
                Console.WriteLine("-------------------------------------------");
                Console.WriteLine("Ошибка в вычислениях вверх метод - по известному родителю");
                Console.WriteLine("-------------------------------------------");
                return(list);
            }
            else
            {
                Console.WriteLine("Math up info: rows - " + rows + ", column -" + column);
            }
            Node classnode = new Node();

            MatrixСмежная[][] matrix = new MatrixСмежная[rows][];
            Parallel.For(0, rows, (i, state) =>
            {
                matrix[i] = new MatrixСмежная[column];
                for (int j = 0; j < column; j++)
                {
                    matrix[i][j] = new MatrixСмежная();
                }
            });
            MatЗаполнитель mat = new MatЗаполнитель();

            mat.matrix = matrix;
            mat.rows   = rows;
            mat.column = column;
            mat.h      = 1;
            bool ошибказаполнителя = false;

            matrix = getMatЗаполнитель(mat /*, rows, column, 1*/, nod, false).matrix;
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < column - 1; j++)
                {
                    try
                    {
                        if (classnode.getEstProperyTrueFix(matrix[i][j].nod.props) == false)
                        {
                            matrix[i][j].property.value_editor = 0;
                        }
                        else if (matrix[i][j].property.proc100)
                        {
                            matrix[i][j].value = 1;
                        }
                        else
                        {
                            matrix[i][j].value = 0;
                        }
                    }
                    catch (System.NullReferenceException ex)
                    {
                        Console.WriteLine("Ошибка заполнителя matirx[" + i + "][" + j + "]" + ex.ToString());
                        ошибказаполнителя = true;
                        break;
                    }
                }
            }

            if (ошибказаполнителя)
            {
                goto metkaошибказаполнителя;
            }
            double[] massres = new double[rows];
            double[,] mati = new double[rows, column - 1];
            for (int i = 0; i < rows; i++)
            {
                double proiz = matrix[i][column - 1].value;
                for (int j = 0; j < column - 1; j++)
                {
                    if (matrix[i][j].nod != null)
                    {
                        proiz *= matrix[i][j].value;
                    }
                }
                massres[i] = proiz;
            }
            печатьИнформации(rows, column, matrix, nod, massres);
            for (int j = 0; j < column /* - 1*/; j++)
            {
                for (int i = 0; i < rows; i++)
                {
                    if (matrix[i][column - 1].property.proc100)
                    {
                        matrix[i][j].property.value_editor += massres[i] / matrix[i][column - 1].property.value_editor_down;
                    }
                }
            }
            return(list);
        }