Пример #1
0
        public SparseRowMatrix(CoordinationalMatrix matrix)
        {
            if (matrix == null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }

            var elems = matrix.OrderBy(key => key.row).ThenBy(key => key.col);

            ia = new int[matrix.Size + 1];
            ja = new int[matrix.Count()];
            a  = new double[ja.Length];
            int i = 0, j = 0;

            ia[i]     = 0;
            ia[i + 1] = 0;

            foreach (var item in elems)
            {
                ja[j] = item.col;
                a[j]  = item.value;
                j++;
                ia[item.row + 1]++;
            }
            for (int k = 0; k < Size; k++)
            {
                ia[k + 1] += ia[k];
            }
        }
Пример #2
0
        public SkylineMatrix(CoordinationalMatrix coordinationalMatrix)
        {
            if (coordinationalMatrix == null)
            {
                throw new ArgumentNullException(nameof(coordinationalMatrix));
            }

            var size     = coordinationalMatrix.Size;
            var pattern  = new SortedSet <int> [size];
            var pattern2 = new Dictionary <(int i, int j), int>();

            for (int i = 0; i < size; i++)
            {
                pattern[i] = new SortedSet <int>();
            }

            foreach (var item in coordinationalMatrix)
            {
                (int i, int j) = item.row > item.col ? (item.row, item.col) : (item.col, item.row);

                if (i != j)
                {
                    pattern[i].Add(j);
                }
            }

            // добавление в шаблон нулей
            for (int i = 1; i < size; i++)
            {
                if (pattern[i].Count != 0)
                {
                    int j = pattern[i].First();

                    pattern2[(i, j)] = 1;
Пример #3
0
        public static IFactorization SpawnFactorization(FactorizersEnum factorizer, CoordinationalMatrix M)
        {
            IFactorization factorization;

            switch (factorizer)

            {
            case FactorizersEnum.IncompleteCholesky:
                return(factorization = new IncompleteCholesky(M));

            case FactorizersEnum.IncompleteLU:
                return(factorization = new IncompleteLU(M));

            case FactorizersEnum.IncompleteLUsq:
                return(factorization = new IncompleteLUsq(M));

            case FactorizersEnum.DiagonalFactorization:
                return(factorization = new DioganalFactorization(M));

            case FactorizersEnum.SimpleFactorization:
                return(factorization = new SimpleFactorization(M));

            case FactorizersEnum.WithoutFactorization:
                return(factorization = null);

            default: return(null);
            }
        }
        public SparseRowColumnMatrix(CoordinationalMatrix coordinationalMatrix)
        {
            if (coordinationalMatrix == null)
            {
                throw new ArgumentNullException(nameof(coordinationalMatrix));
            }

            var size    = coordinationalMatrix.Size;
            var pattern = new SortedSet <int> [size];

            for (int i = 0; i < size; i++)
            {
                pattern[i] = new SortedSet <int>();
            }

            foreach (var item in coordinationalMatrix)
            {
                (int i, int j) = item.row > item.col ? (item.row, item.col) : (item.col, item.row);

                if (i != j)
                {
                    pattern[i].Add(j);
                }
            }

            ia = new int[size + 1];

            for (int i = 0; i < size; i++)
            {
                ia[i + 1] = ia[i] + pattern[i].Count;
            }

            var count = ia[size];

            di = new double[size];
            ja = new int[count];
            al = new double[count];
            au = new double[count];

            var orderedItems = coordinationalMatrix.OrderBy(x => x.row).ThenBy(x => x.col);

            for (int i = 0, k = 0; i < Size; i++)
            {
                di[i] = coordinationalMatrix[i, i];

                foreach (var col in pattern[i])
                {
                    ja[k++] = col;
                }

                for (int j = ia[i]; j < ia[i + 1]; j++)
                {
                    var column = ja[j];
                    al[j] = coordinationalMatrix[i, column];
                    au[j] = coordinationalMatrix[column, i];
                }
            }
        }
Пример #5
0
        public DenseMatrix(CoordinationalMatrix coordinationalMatrix)
        {
            if (coordinationalMatrix == null)
            {
                throw new ArgumentNullException(nameof(coordinationalMatrix));
            }

            matrix = new double[coordinationalMatrix.Size, coordinationalMatrix.Size];

            foreach (var item in coordinationalMatrix)
            {
                matrix[item.row, item.col] = item.value;
            }
        }
Пример #6
0
        public SkylineMatrix(CoordinationalMatrix coordinationalMatrix)
        {
            if (coordinationalMatrix == null)
            {
                throw new ArgumentNullException(nameof(coordinationalMatrix));
            }

            var size = coordinationalMatrix.Size;

            ia = new int[size + 1];
            di = new double[size];

            var orderedMatrix         = coordinationalMatrix.OrderBy(key => key.row).ThenBy(key => key.col);
            var itemsSymmetricProfile = new Dictionary <(int i, int j), (double al, double au)>();

            int flag = 1, jj = 0; // флажок, обозначающий добавлены или нет нули в профиле (сохраняет номер строки/столбца, где добавлены)

            // заполнение симметричного профиля
            foreach (var item in orderedMatrix)
            {
                if (item.row == item.col)
                {
                    di[item.row] = item.value;
                }
                else
                {
                    (int i, int j) = item.row > item.col ? (item.row, item.col) : (item.col, item.row);

                    if (!itemsSymmetricProfile.ContainsKey((i, j)))
                    {
                        itemsSymmetricProfile[(i, j)] = (0, 0);
                    }

                    if (item.row > item.col)
                    {
                        var au = itemsSymmetricProfile[(i, j)].au;