Line data Source code
1 : /*
2 : * Copyright (c) 2022: G-CSC, Goethe University Frankfurt
3 : * Author: Felix Salfelder, 2022
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 UG4_GRAPH_INTERFACE_BIDIR_BOOST_H
34 : #define UG4_GRAPH_INTERFACE_BIDIR_BOOST_H
35 :
36 : #include "bidirectional.h"
37 :
38 : namespace boost{
39 :
40 : struct BS_traversal_tag
41 : : adjacency_graph_tag, bidirectional_graph_tag, vertex_list_graph_tag {};
42 :
43 : template <class T>
44 : struct graph_traits<ug::BidirectionalMatrix<T>>{
45 : typedef typename T::value_type value_type;
46 : typedef int vertex_descriptor;
47 : typedef SM_edge<value_type> edge_descriptor;
48 : typedef bidirectional_tag directed_category;
49 : typedef BS_traversal_tag traversal_category;
50 : typedef disallow_parallel_edge_tag edge_parallel_category;
51 : typedef counting_iterator<size_t> vertex_iterator;
52 : typedef SM_out_edge_iterator<value_type, true> out_edge_iterator;
53 : typedef SM_out_edge_iterator<value_type, false> in_edge_iterator;
54 : typedef SM_adjacency_iterator<value_type> adjacency_iterator;
55 : typedef int degree_size_type;
56 : typedef int vertices_size_type;
57 : };
58 :
59 : template<class T>
60 : std::pair<counting_iterator<size_t>, counting_iterator<size_t> > vertices(
61 : ug::BidirectionalMatrix<T> const& M)
62 : {
63 : counting_iterator<size_t> b(0);
64 0 : counting_iterator<size_t> e(M.num_rows());
65 :
66 : return std::make_pair(b,e);
67 : }
68 :
69 : template<class T>
70 : int num_vertices(ug::BidirectionalMatrix<T> const& M)
71 : {
72 : return M.num_rows();
73 : }
74 :
75 : template<class T>
76 : int out_degree(int v, ug::BidirectionalMatrix<T> const& M)
77 : {
78 : return M.out_degree(v);
79 : }
80 :
81 : template<class T>
82 : int in_degree(int v, ug::BidirectionalMatrix<T> const& M)
83 : {
84 : return M.in_degree(v);
85 : }
86 :
87 : template<class T>
88 : int degree(int v, ug::BidirectionalMatrix<T> const& M)
89 : { untested();
90 : return 2*M.degree(v);
91 : }
92 :
93 : template<class T>
94 : size_t source(SM_edge<typename T::value_type> const& e, ug::BidirectionalMatrix<T> const&)
95 : {
96 0 : return e.source();
97 : }
98 :
99 : template<class T>
100 : size_t target(SM_edge<typename T::value_type> const& e, ug::BidirectionalMatrix<T> const& m)
101 : {
102 : return e.target();
103 : }
104 :
105 : template<class T>
106 : std::pair<typename graph_traits<T>::adjacency_iterator,
107 : typename graph_traits<T>::adjacency_iterator>
108 : adjacent_vertices(size_t v, ug::BidirectionalMatrix<T> const& M)
109 : {
110 : typedef typename graph_traits<T>::adjacency_iterator a;
111 :
112 : typename T::const_row_iterator b = M.begin_row(v);
113 : typename T::const_row_iterator e = M.end_row(v);
114 :
115 : return std::make_pair(a(&b, &e), a(&e, &e));
116 : }
117 :
118 : template<class T>
119 : std::pair<typename graph_traits<T>::adjacency_iterator,
120 : typename graph_traits<T>::adjacency_iterator>
121 0 : coadjacent_vertices(size_t v, ug::BidirectionalMatrix<T> const& M)
122 : {
123 : typedef typename T::value_type value_type;
124 : typedef typename graph_traits<ug::SparseMatrix<value_type>>::adjacency_iterator a;
125 :
126 0 : typename T::const_row_iterator b = M.begin_col(v);
127 : typename T::const_row_iterator e = M.end_col(v);
128 :
129 0 : return std::make_pair(a(&b, &e), a(&e, &e));
130 : }
131 :
132 :
133 : template<class T>
134 : inline std::pair<SM_out_edge_iterator<typename T::value_type>,
135 : SM_out_edge_iterator<typename T::value_type>>
136 : out_edges(size_t v, ug::BidirectionalMatrix<T> const& g)
137 : {
138 : typedef typename T::value_type value_type;
139 : typedef SM_out_edge_iterator<value_type> Iter;
140 : auto a = adjacent_vertices(v, g);
141 : return std::make_pair(Iter(a.first, v), Iter(a.second, v));
142 : }
143 :
144 : template<class T>
145 : inline std::pair<SM_out_edge_iterator<typename T::value_type, false>,
146 : SM_out_edge_iterator<typename T::value_type, false>>
147 0 : in_edges(size_t v, ug::BidirectionalMatrix<T> const& g)
148 : {
149 : typedef typename T::value_type value_type;
150 : typedef SM_out_edge_iterator<value_type, false> Iter;
151 0 : auto a = coadjacent_vertices(v, g);
152 0 : return std::make_pair(Iter(a.first, v), Iter(a.second, v));
153 : }
154 :
155 : template<class T>
156 : inline SM_edge_weight_map<typename T::value_type, ug::BidirectionalMatrix<T>>
157 : get(edge_weight_t, ug::BidirectionalMatrix<T> const & g) {
158 : typedef typename T::value_type value_type;
159 : return SM_edge_weight_map<value_type, ug::BidirectionalMatrix<T>>(g);
160 : }
161 :
162 : template<class T>
163 : struct property_map<ug::BidirectionalMatrix<ug::SparseMatrix<T>>, vertex_index_t>{
164 : typedef sparse_matrix_index_map<T> type;
165 : typedef type const_type;
166 : };
167 :
168 : template<class T>
169 : inline typename property_map<ug::BidirectionalMatrix<ug::SparseMatrix<T>>, vertex_index_t>::const_type
170 : get(vertex_index_t, ug::BidirectionalMatrix<T> const& m)
171 : {
172 : return sparse_matrix_index_map<typename T::value_type>(m);
173 : }
174 :
175 : } // boost
176 :
177 : #endif // guard
|