Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost_minimum_degree_ordering.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020: G-CSC, Goethe University Frankfurt
3 * Author: Lukas Larisch
4 *
5 * This file is part of UG4.
6 *
7 * UG4 is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License version 3 (as published by the
9 * Free Software Foundation) with the following additional attribution
10 * requirements (according to LGPL/GPL v3 §7):
11 *
12 * (1) The following notice must be displayed in the Appropriate Legal Notices
13 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 *
15 * (2) The following notice must be displayed at a prominent place in the
16 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 *
18 * (3) The following bibliography is recommended for citation and must be
19 * preserved in all covered files:
20 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 * parallel geometric multigrid solver on hierarchically distributed grids.
22 * Computing and visualization in science 16, 4 (2013), 151-164"
23 * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 * flexible software system for simulating pde based models on high performance
25 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 */
32
33#ifndef UG_BASE_LIB_ALGEBRA_ORDERING_STRATEGIES_ALGORITHMS_BOOST_MINIMUM_DEGREE_ORDERING_H
34#define UG_BASE_LIB_ALGEBRA_ORDERING_STRATEGIES_ALGORITHMS_BOOST_MINIMUM_DEGREE_ORDERING_H
35
36#include <boost/graph/adjacency_list.hpp>
37#include <boost/graph/graph_traits.hpp>
38#include <boost/graph/properties.hpp>
39
40#include <boost/graph/minimum_degree_ordering.hpp>
41
42#include "IOrderingAlgorithm.h"
43#include "util.h"
44
45//debug
46#include "common/error.h"
47#include "common/log.h"
48
49namespace ug{
50
51//Important Note: This implementation requires the BGL graph to be
52//directed. Therefore, nonzero entry (i, j) in a symmetrical matrix
53//A coresponds to two directed edges (i->j and j->i).
54template <typename TAlgebra, typename O_t>
55class BoostMinimumDegreeOrdering final : public IOrderingAlgorithm<TAlgebra, O_t>
56{
57public:
58 typedef typename TAlgebra::matrix_type M_t;
59 typedef typename TAlgebra::vector_type V_t;
60 typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS> G_t;
62
64
68
73
74 void compute(){
75 unsigned n = boost::num_vertices(g);
76 unsigned e = boost::num_edges(g);
77
78 O_t io(n, 0);
79
80 o.resize(n);
81 unsigned i = 0;
82
83 if(n == 0){
84 UG_THROW(name() << "::compute: Graph is empty!");
85 return;
86 }
87 else if(n*(n-1u)==e || e==0){
88 UG_LOG(name() << "::compute: Graph is complete or edgeless!");
89 typename boost::graph_traits<G_t>::vertex_iterator vIt, vEnd;
90 for(boost::tie(vIt, vEnd) = boost::vertices(g); vIt != vEnd; vIt++){
91 o[i++] = *vIt;
92 }
93 }
94
95 std::vector<int> inverse_perm(n, 0);
96 std::vector<int> supernode_sizes(n, 1);
97 auto id = boost::get(boost::vertex_index, g);
98 std::vector<int> degree(n, 0);
99
100 /*
101 * (Graph& G,
102 * DegreeMap degree,
103 * InversePermutationMap inverse_perm,
104 * PermutationMap perm,
105 * SuperNodeMap supernode_size,
106 * int delta,
107 * VertexIndexMap vertex_index_map)
108 */
109
110 boost::minimum_degree_ordering
111 (g,
112 boost::make_iterator_property_map(&degree[0], id, degree[0]),
113 &io[0],
114 &(o[0]),
115 boost::make_iterator_property_map(&supernode_sizes[0], id, supernode_sizes[0]),
116 0,
117 id
118 );
119
120 g = G_t(0);
121
122 #ifdef UG_DEBUG
123 check();
124 #endif
125 }
126
127 void check(){
128 UG_COND_THROW(!is_permutation(o), name() << "::check: Not a permutation!");
129 }
130
131 O_t& ordering(){
132 return o;
133 }
134
135 void init(M_t* A, const V_t&){
136 init(A);
137 }
138
139 void init(M_t* A){
140 //TODO: replace this by UG_DLOG if permutation_util does not depend on this file anymore
141 #ifdef UG_ENABLE_DEBUG_LOGS
142 UG_LOG("Using " << name() << "\n");
143 #endif
144
145 unsigned rows = A->num_rows();
146
147 g = G_t(rows);
148
149 for(unsigned i = 0; i < rows; i++){
150 for(typename M_t::row_iterator conn = A->begin_row(i); conn != A->end_row(i); ++conn){
151 if(conn.value() != 0.0 && conn.index() != i){ //TODO: think about this!!
152 boost::add_edge(i, conn.index(), g);
153 }
154 }
155 }
156 }
157
158 void init(M_t*, const V_t&, const O_t&){
159 UG_THROW(name() << "::init: induced subgraph version not implemented yet!");
160 }
161
162 void init(M_t*, const O_t&){
163 UG_THROW(name() << "::init: induced subgraph version not implemented yet!");
164 }
165
166 virtual const char* name() const {return "BoostMinimumDegreeOrdering";}
167
168private:
170 O_t o;
171};
172
173}
174
175#endif
Definition smart_pointer.h:108
Definition boost_minimum_degree_ordering.h:56
TAlgebra::matrix_type M_t
Definition boost_minimum_degree_ordering.h:58
SmartPtr< IOrderingAlgorithm< TAlgebra, O_t > > clone()
Definition boost_minimum_degree_ordering.h:69
void init(M_t *A, const V_t &)
Definition boost_minimum_degree_ordering.h:135
virtual const char * name() const
Definition boost_minimum_degree_ordering.h:166
O_t o
Definition boost_minimum_degree_ordering.h:170
void init(M_t *A)
Definition boost_minimum_degree_ordering.h:139
void init(M_t *, const V_t &, const O_t &)
Definition boost_minimum_degree_ordering.h:158
void init(M_t *, const O_t &)
Definition boost_minimum_degree_ordering.h:162
TAlgebra::vector_type V_t
Definition boost_minimum_degree_ordering.h:59
void check()
Definition boost_minimum_degree_ordering.h:127
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS > G_t
Definition boost_minimum_degree_ordering.h:60
BoostMinimumDegreeOrdering()
Definition boost_minimum_degree_ordering.h:63
BoostMinimumDegreeOrdering(const BoostMinimumDegreeOrdering< TAlgebra, O_t > &parent)
clone constructor
Definition boost_minimum_degree_ordering.h:66
O_t & ordering()
Definition boost_minimum_degree_ordering.h:131
IOrderingAlgorithm< TAlgebra, O_t > baseclass
Definition boost_minimum_degree_ordering.h:61
void compute()
Definition boost_minimum_degree_ordering.h:74
G_t g
Definition boost_minimum_degree_ordering.h:169
Definition IOrderingAlgorithm.h:52
virtual void init()
#define UG_THROW(msg)
Definition error.h:57
#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
std::pair< counting_iterator< size_t >, counting_iterator< size_t > > vertices(ug::BidirectionalMatrix< T > const &M)
Definition bidirectional_boost.h:60
int num_vertices(ug::BidirectionalMatrix< T > const &M)
Definition bidirectional_boost.h:70
SM_edge_weight_map< typename T::value_type, ug::BidirectionalMatrix< T > > get(edge_weight_t, ug::BidirectionalMatrix< T > const &g)
Definition bidirectional_boost.h:157
the ug namespace
bool is_permutation(O_t &o)
Definition permutation_util.h:135
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition smart_pointer.h:836