numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
reverse_cuthill_mckee_ordering.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <Eigen/Core>
23#include <Eigen/SparseCore>
24
27
28namespace num_collect::linear {
29
34template <typename StorageIndex>
36public:
38 using storage_index_type = StorageIndex;
39
41 using permutation_type = Eigen::PermutationMatrix<Eigen::Dynamic,
42 Eigen::Dynamic, storage_index_type>;
43
46
49
57 template <base::concepts::sparse_matrix MatrixType>
58 void operator()(const MatrixType& matrix, permutation_type& permutation) {
59 cuthill_mckee_ordering<storage_index_type>()(matrix, permutation);
60 const auto size =
61 static_cast<storage_index_type>(permutation.indices().size());
62 const storage_index_type size_minus_one = size - 1;
63 for (storage_index_type& index : permutation.indices()) {
64 index = size_minus_one - index;
65 }
66 }
67
76 template <typename MatrixType, unsigned int Mode>
78 const Eigen::SparseSelfAdjointView<MatrixType, Mode>& matrix,
79 permutation_type& permutation) {
80 Eigen::SparseMatrix<typename MatrixType::Scalar, Eigen::ColMajor,
82 matrix_as_ordinary_matrix = matrix;
83 operator()(matrix_as_ordinary_matrix, permutation);
84 }
85};
86
87} // namespace num_collect::linear
Class to perform Cuthill-McKee ordering method golub2013, knabner2003.
Class to perform reverse Cuthill-McKee ordering method golub2013, knabner2003.
void operator()(const MatrixType &matrix, permutation_type &permutation)
Create a permutation matrix.
Eigen::PermutationMatrix< Eigen::Dynamic, Eigen::Dynamic, storage_index_type > permutation_type
Type of permutations.
StorageIndex storage_index_type
Type of indices in storages of indices.
permutation_type PermutationType
Type of permutations (for Eigen library).
void operator()(const Eigen::SparseSelfAdjointView< MatrixType, Mode > &matrix, permutation_type &permutation)
Create a permutation matrix from SparseSelfAdjointView object.
Definition of cuthill_mckee_ordering class.
Namespace of solvers of linear equations.
Definition of sparse_matrix concept.