Beispiel #1
0
        /// <summary>
        /// 交错数组.是否为三角阵,如果是在只读一半就行了,加快读取时间。
        /// </summary>
        /// <returns></returns>
        public static double[][] GetMatrixArrayJagged(List <MatrixLine> Items, bool isTriangular = true)
        {
            if (Items == null || Items.Count == 0)
            {
                return(null);
            }
            MatrixLine last     = Items[Items.Count - 1];
            int        rowCount = last.Row;
            int        colCount = last.MatrixUnits[last.MatrixUnits.Count - 1].Col;

            double[][] matrixArray = new double[rowCount][];
            for (int i = 0; i < rowCount; i++)
            {
                matrixArray[i] = new double[colCount];
            }

            foreach (MatrixLine line in Items)
            {
                foreach (var unit in line.MatrixUnits)
                {
                    matrixArray[unit.Row - 1][unit.Col - 1] = unit.Val;
                    if (isTriangular && unit.Row != unit.Col)
                    {
                        matrixArray[unit.Col - 1][unit.Row - 1] = unit.Val;
                    }
                }
            }

            return(matrixArray);
        }
Beispiel #2
0
        /// <summary>
        /// 解析矩阵行。
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public static MatrixLine ParseLine(string line)
        {
            MatrixLine b = new MatrixLine();

            b.Row = int.Parse(line.Substring(1, 5));
            b.Col = int.Parse(line.Substring(7, 5));

            int i = 0, cur;

            while (line.Length > (cur = 13 + (i++) * 22))
            {
                MatrixUnit u = new MatrixUnit();
                u.Row = b.Row;
                u.Col = b.Col + i;
                u.Val = double.Parse(line.Substring(cur, 21));

                b.MatrixUnits.Add(u);
            }
            return(b);
        }
Beispiel #3
0
        /// <summary>
        /// 二位数组
        /// </summary>
        /// <param name="isTriangular">是否为三角阵,如果是在只读一半就行了,加快读取时间。</param>
        /// <returns></returns>
        public static double[,] GetMatrixArray2D(List <MatrixLine> Items, bool isTriangular = true)
        {
            MatrixLine last     = Items[Items.Count - 1];
            int        rowCount = last.Row;
            int        colCount = last.MatrixUnits[last.MatrixUnits.Count - 1].Col;

            double[,] matrixArray = new double[rowCount, colCount];

            foreach (MatrixLine line in Items)
            {
                foreach (var unit in line.MatrixUnits)
                {
                    matrixArray[unit.Row - 1, unit.Col - 1] = unit.Val;
                    if (isTriangular && unit.Row != unit.Col)
                    {
                        matrixArray[unit.Col - 1, unit.Row - 1] = unit.Val;
                    }
                }
            }
            return(matrixArray);
        }