示例#1
0
        /// <summary>
        /// 写方法。Version 1.
        /// </summary>
        public override IMatrix Read(MatrixHeader header)
        {
            SkipHeader();

            int row = header.RowCount;
            int col = header.ColCount;

            SparseMatrix matr      = new SparseMatrix(row, col);
            int          itemCount = header.ContentCount;

            for (int i = 0; i < itemCount; i++)
            {
                //各个节点位置无关,可以考虑并行存取,但是由于内存共享,还得序列化读取。
                int    Row   = BinaryReader.ReadInt32();
                int    Col   = BinaryReader.ReadInt32();
                double Value = BinaryReader.ReadDouble();
                matr.Add(Row, Col, Value);
            }

            Char end = this.BinaryReader.ReadChar();

            if (end != BinarySpliter.EndOfContent)
            {
                throw new Exception("末尾数字匹配上啊!!!");
            }

            return(matr);
        }
示例#2
0
        /// <summary>
        /// 写方法。Version 1.
        /// </summary>
        public override IMatrix Read(MatrixHeader header)
        {
            SkipHeader();

            int row = header.RowCount;
            int col = header.ColCount;

            Geo.Algorithm.ArrayMatrix matrix = new Geo.Algorithm.ArrayMatrix(row, col);

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    if (header.MatrixType == MatrixType.FloatWing && i != j)
                    {
                        matrix[i, j] = BinaryReader.ReadSingle();
                    }
                    else
                    {
                        matrix[i, j] = BinaryReader.ReadDouble();
                    }
                }
            }
            Char end = this.BinaryReader.ReadChar();

            if (end != BinarySpliter.EndOfContent)
            {
                throw new Exception("末尾数字匹配上啊!!!");
            }
            return(matrix);
        }
示例#3
0
        public override void Write(IMatrix matrix)
        {
            MatrixHeader header = MatrixHeader.GetDefaultHeader(matrix);

            WriteHeader(header);

            WriteMatrix(matrix);
        }
示例#4
0
        private BaseBinaryMatrixReader InitWriter(MatrixHeader option)
        {
            BaseBinaryMatrixReader matrixReader = this.matrixReader;

            switch (option.MatrixType)
            {
            case MatrixType.Array:
                matrixReader = new BinaryArrayMatrixReader(Stream);
                break;

            case MatrixType.Vector:
                break;

            case MatrixType.Sparse:
                matrixReader = new BinaryArrayMatrixReader(Stream);
                break;

            case MatrixType.Float:
                break;

            case MatrixType.FloatWing:
                break;

            case MatrixType.Diagonal:
                matrixReader = new BinaryArrayMatrixReader(Stream);
                break;

            case MatrixType.Symmetric:
                matrixReader = new BinaryArrayMatrixReader(Stream);
                break;

            case MatrixType.VectorMatrix:
                break;

            case MatrixType.ZeroMatrix:
                break;

            case MatrixType.ConstMatrix:
                break;

            case MatrixType.ResizeableMatrix:
                break;

            case MatrixType.Unknow:
            default:
                matrixReader = new BinaryArrayMatrixReader(Stream);
                break;
            }
            return(matrixReader);
        }
示例#5
0
        public static MatrixHeader GetDefaultHeader(IMatrix matrix)
        {
            MatrixHeader header = new MatrixHeader(matrix.MatrixType, matrix.Name)
            {
                CreationTime = DateTime.Now,
                Creator      = "Gnsser",
                Version      = 1,
                ContentCount = matrix.ItemCount,
                RowCount     = matrix.RowCount,
                ColCount     = matrix.ColCount,
                ColNames     = matrix.ColNames,
                RowNames     = matrix.RowNames,
            };

            return(header);
        }
示例#6
0
        /// <summary>
        /// 写方法。Version 1.
        /// 内容区:
        /// 第1个数为byte,表示矩阵文件的版本,对应数字 1-255
        /// 第2个数为byte,表示矩阵的类型,对应C#的枚举类型
        /// 第3、4个数为int32,分别表示 矩阵的行和列。
        /// 第5个开始为浮点数(双精度、单精度或整型)记录
        /// </summary>
        /// <param name="matrix">待写成文件的矩阵。</param>
        public override void Write(IMatrix matrix)
        {
            MatrixHeader header;

            if (this.IsFloatWingCompress)
            {
                header            = MatrixHeader.GetDefaultHeader(matrix);
                header.MatrixType = MatrixType.FloatWing;
            }
            else
            {
                header = MatrixHeader.GetDefaultHeader(matrix);
            }

            WriteHeader(header);

            WriteMatrix(matrix);
        }
示例#7
0
        /// <summary>
        /// 写方法。Version 1.
        /// 内容区:
        /// 第1个数为byte,表示矩阵文件的版本,对应数字 1-255
        /// 第2个数为byte,表示矩阵的类型,对应C#的枚举类型
        /// 第3、4个数为int32,分别表示 矩阵的行和列。
        /// 第5个开始为浮点数(双精度、单精度或整型)记录
        /// </summary>
        public override IMatrix Read(MatrixHeader header)
        {
            SkipHeader();

            int row = header.RowCount;
            int col = header.ColCount;

            double [] vector = new double[row];

            for (int i = 0; i < row; i++)
            {
                vector[i] = BinaryReader.ReadDouble();
            }
            Char end = this.BinaryReader.ReadChar();

            if (end != BinarySpliter.EndOfContent)
            {
                throw new Exception("末尾数字匹配上啊!!!");
            }
            DiagonalMatrix dm = new DiagonalMatrix(vector);

            return(dm);
        }
示例#8
0
        protected virtual void WriteHeader(MatrixHeader header)
        {
            BinaryMatrixHeaderWriter HeaderWriter = new BinaryMatrixHeaderWriter(this.Stream);

            HeaderWriter.Write(header);
        }
示例#9
0
        public override IMatrix Read(MatrixHeader option)
        {
            this.matrixReader = InitWriter(option);

            return(matrixReader.Read(option));
        }