コード例 #1
0
        /// <summary>
        /// Reads matrix and branches (if exists) from specified file.
        /// </summary>
        /// <param name="filePath">File path.</param>
        /// <param name="networkSize">The size of the network (matrix, which represents the network).</param>
        /// <param name="matrixType">The type of given matrix (content of the specified file)</param>
        /// <returns>Matrix and branches (if exists).</returns>
        /// <throws>CoreException, MatrixFormatException.</throws>
        public static MatrixInfoToRead Read(String filePath, int networkSize, AdjacencyMatrixType matrixType)
        {
            MatrixInfoToRead result = new MatrixInfoToRead();

            result.Matrix = MatrixReader(filePath, networkSize, matrixType);
            result.Branches = BranchesReader(filePath.Insert(filePath.Length - 4, "_branches"));

            return result;
        }
コード例 #2
0
        private static ArrayList MatrixReader(String filePath, int networkSize, AdjacencyMatrixType matrixType)
        {
            ArrayList matrix;

            bool r = false;
            try
            {
                switch (matrixType)
                {
                    case AdjacencyMatrixType.ClassicalMatrix:
                        r = TryReadClassicalMatrix(filePath, networkSize, out matrix);
                        break;
                    case AdjacencyMatrixType.Degrees:
                        r = TryReadDegreesMatrix(filePath, networkSize, out matrix);
                        break;
                    default:
                        throw new CoreException("Unknown matrix type.");
                }
            }
            catch (SystemException)
            {
                throw new MatrixFormatException();
            }

            if (!r)
                throw new MatrixFormatException();

            return matrix;
        }