28#include <Eigen/SparseCore>
29#include <hash_tables/maps/open_address_map_st.h>
46template <
typename StorageIndex>
66 template <base::concepts::sparse_matrix MatrixType>
69 matrix.rows() == matrix.cols(),
"Square matrix is required.");
107 if (left.previous_level_order != right.previous_level_order) {
108 return left.previous_level_order < right.previous_level_order;
110 if (left.degree != right.degree) {
111 return left.degree < right.degree;
113 return left.index < right.index;
124 template <base::concepts::sparse_matrix MatrixType>
132 std::numeric_limits<storage_index_type>::max();
136 for (
typename MatrixType::InnerIterator iter(matrix, i); iter;
141 if (degree < lowest_degree) {
142 lowest_degree = degree;
143 lowest_degree_index = i;
147 return lowest_degree_index;
157 template <base::concepts::sparse_matrix MatrixType>
164 .index = first_index, .degree = 0, .previous_level_order = 0});
187 for (
typename MatrixType::InnerIterator iter(
192 if (degree ==
nullptr) {
197 .previous_level_order = order});
218 permutation.resize(size);
221 permutation.indices()(index) = moved_index;
247template <
typename StorageIndex>
270 template <base::concepts::sparse_matrix MatrixType>
273 matrix, permutation);
284 template <
typename MatrixType,
unsigned int Mode>
286 const Eigen::SparseSelfAdjointView<MatrixType, Mode>& matrix,
288 Eigen::SparseMatrix<
typename MatrixType::Scalar, Eigen::ColMajor,
290 matrix_as_ordinary_matrix = matrix;
291 operator()(matrix_as_ordinary_matrix, permutation);
Class of exception on failure in algorithm.
Class to perform Cuthill-McKee ordering method golub2013, knabner2003.
void operator()(const Eigen::SparseSelfAdjointView< MatrixType, Mode > &matrix, permutation_type &permutation)
Create a permutation matrix from SparseSelfAdjointView object.
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.
permutation_type PermutationType
Type of permutations (for Eigen library).
StorageIndex storage_index_type
Type of indices in storages of indices.
cuthill_mckee_ordering()=default
Constructor.
Class of the implementation of Cuthill-McKee ordering method golub2013, knabner2003.
void process_indices(const MatrixType &matrix, storage_index_type first_index)
Process indices.
void create_permutation(permutation_type &permutation, storage_index_type size)
Create a permutation matrix.
cuthill_mckee_ordering_impl()=default
Constructor.
hash_tables::maps::open_address_map_st< storage_index_type, storage_index_type > unused_index_to_degree_
Mapping of unused indices to degrees.
void operator()(const MatrixType &matrix, permutation_type &permutation)
Create a permutation matrix.
std::set< next_index_data, next_index_data_less > current_indices_
Indices processed in the current level.
StorageIndex storage_index_type
Type of indices in storages of indices.
std::vector< storage_index_type > processed_indices_
Processed indices.
auto calculate_degrees(const MatrixType &matrix) -> storage_index_type
Calculate degrees.
Eigen::PermutationMatrix< Eigen::Dynamic, Eigen::Dynamic, storage_index_type > permutation_type
Type of permutations.
std::set< next_index_data, next_index_data_less > next_indices_
Indices processed in the next level.
Definition of exceptions.
Definition of macros for logging.
#define NUM_COLLECT_LOG_AND_THROW(EXCEPTION_TYPE,...)
Write an error log and throw an exception for an error.
Namespace of solvers of linear equations.
Definition of NUM_COLLECT_PRECONDITION macro.
#define NUM_COLLECT_PRECONDITION(CONDITION,...)
Check whether a precondition is satisfied and throw an exception if not.
Definition of sparse_matrix concept.
Function object to compare next_index_data objects.
auto operator()(const next_index_data &left, const next_index_data &right) const noexcept -> bool
Compare two objects.
Struct of data of indices processed next.
storage_index_type previous_level_order
Order in the previous level.
storage_index_type index
Index.
storage_index_type degree
Degree.