33#ifndef UG_BASE_LIB_ALGEBRA_ORDERING_STRATEGIES_ALGORITHMS_BOOST_CUTHILL_MCKEE_ORDERING_H
34#define UG_BASE_LIB_ALGEBRA_ORDERING_STRATEGIES_ALGORITHMS_BOOST_CUTHILL_MCKEE_ORDERING_H
36#include <boost/graph/adjacency_list.hpp>
37#include <boost/graph/graph_traits.hpp>
38#include <boost/graph/properties.hpp>
40#include <boost/graph/cuthill_mckee_ordering.hpp>
52template <
typename G_t,
typename M_t>
54 size_t n = A->num_rows();
55 size_t k = inv_map.size();
58 std::vector<int> ind_map(n, -1);
59 for(
unsigned i = 0; i < k; ++i){
60 ind_map[inv_map[i]] = i;
63 typename boost::graph_traits<G_t>::adjacency_iterator nIt, nEnd;
64 for(
unsigned i = 0; i < inv_map.size(); ++i){
65 for(
typename M_t::row_iterator conn = A->begin_row(inv_map[i]); conn != A->end_row(inv_map[i]); ++conn){
66 if(conn.value() != 0.0 && conn.index() != i){
67 int idx = ind_map[conn.index()];
69 boost::add_edge(i, idx, ind_g);
81typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
82 boost::property<boost::vertex_color_t,
83 boost::default_color_type,
84 boost::property<boost::vertex_degree_t, int> > >
89template <
typename TAlgebra,
typename O_t=std::vector<
size_t> >
93 typedef typename TAlgebra::matrix_type
M_t;
94 typedef typename TAlgebra::vector_type
V_t;
96 typedef boost::graph_traits<G_t>::vertex_descriptor
Vertex_t;
113 boost::property_map<G_t, boost::vertex_index_t>::type index_map = get(boost::vertex_index,
g);
126 for(
unsigned i = 0; i != inv_perm.size(); ++i){
127 o[index_map[inv_perm[i]]] = i;
151 #ifdef UG_ENABLE_DEBUG_LOGS
155 unsigned rows = A->num_rows();
159 for(
unsigned i = 0; i < rows; i++){
160 for(
typename M_t::row_iterator conn = A->begin_row(i); conn != A->end_row(i); ++conn){
161 if(conn.value() != 0.0 && conn.index() != i){
162 if(!boost::edge(i, conn.index(),
g).second){
163 boost::add_edge(i, conn.index(),
g);
176 #ifdef UG_ENABLE_DEBUG_LOGS
177 UG_LOG(
"Using " <<
name() <<
" on induced matrix of size " << inv_map.size() <<
"\n");
180 induced_subgraph<G_t, M_t>(
g, A, inv_map);
187 virtual const char*
name()
const {
189 return "ReverseBoostCuthillMcKeeOrdering";
192 return "BoostCuthillMcKeeOrdering";
187 virtual const char*
name()
const {
…}
Definition smart_pointer.h:108
Definition boost_cuthill_mckee_ordering.h:91
void set_reverse(bool b)
Definition boost_cuthill_mckee_ordering.h:183
boost::graph_traits< G_t >::vertex_descriptor Vertex_t
Definition boost_cuthill_mckee_ordering.h:96
O_t o
Definition boost_cuthill_mckee_ordering.h:198
IOrderingAlgorithm< TAlgebra, O_t > baseclass
Definition boost_cuthill_mckee_ordering.h:97
Graph_t G_t
Definition boost_cuthill_mckee_ordering.h:95
BoostCuthillMcKeeOrdering(const BoostCuthillMcKeeOrdering< TAlgebra, O_t > &parent)
clone constructor
Definition boost_cuthill_mckee_ordering.h:102
bool m_bReverse
Definition boost_cuthill_mckee_ordering.h:200
void init(M_t *A)
Definition boost_cuthill_mckee_ordering.h:149
void check()
Definition boost_cuthill_mckee_ordering.h:137
void init(M_t *A, const V_t &, const O_t &inv_map)
Definition boost_cuthill_mckee_ordering.h:170
virtual const char * name() const
Definition boost_cuthill_mckee_ordering.h:187
TAlgebra::vector_type V_t
Definition boost_cuthill_mckee_ordering.h:94
G_t g
Definition boost_cuthill_mckee_ordering.h:197
void init(M_t *A, const O_t &inv_map)
Definition boost_cuthill_mckee_ordering.h:174
SmartPtr< IOrderingAlgorithm< TAlgebra, O_t > > clone()
Definition boost_cuthill_mckee_ordering.h:105
TAlgebra::matrix_type M_t
Definition boost_cuthill_mckee_ordering.h:93
O_t & ordering()
Definition boost_cuthill_mckee_ordering.h:141
void init(M_t *A, const V_t &)
Definition boost_cuthill_mckee_ordering.h:145
void compute()
Definition boost_cuthill_mckee_ordering.h:110
BoostCuthillMcKeeOrdering()
Definition boost_cuthill_mckee_ordering.h:99
Definition IOrderingAlgorithm.h:52
#define UG_LOG(msg)
Definition log.h:367
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition error.h:61
int num_vertices(ug::BidirectionalMatrix< T > const &M)
Definition bidirectional_boost.h:70
degree_property_map< ug::UndirectedMatrix< T > > make_degree_map(const ug::UndirectedMatrix< T > &g)
Definition undirected_boost.h:341
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, boost::property< boost::vertex_color_t, boost::default_color_type, boost::property< boost::vertex_degree_t, int > > > Graph_t
Definition boost_cuthill_mckee_ordering.h:85
bool is_permutation(O_t &o)
Definition permutation_util.h:135
void induced_subgraph(G_t &ind_g, M_t *A, const std::vector< size_t > &inv_map)
Definition boost_cuthill_mckee_ordering.h:53
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition smart_pointer.h:836