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]; } }
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]; } } }
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;