Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
iterator.hh
Go to the documentation of this file.
1#ifndef UTOPIA_CORE_GRAPH_ITERATORS_HH
2#define UTOPIA_CORE_GRAPH_ITERATORS_HH
3
4#include <boost/graph/adjacency_list.hpp>
5#include <boost/graph/adjacency_matrix.hpp>
6#include <boost/graph/subgraph.hpp>
7#include <boost/graph/filtered_graph.hpp>
8
9
10namespace Utopia {
19enum class IterateOver {
22
24 edges,
25
27
31
33
37
39
43
45
49};
50
51
52namespace GraphUtils
53{
54
56
67template<IterateOver iterate_over, typename Graph>
68decltype(auto) iterator_pair(const Graph& g){
69 using namespace boost;
70
71 if constexpr (iterate_over == IterateOver::vertices){
72 return vertices(g);
73 }
74 else if constexpr (iterate_over == IterateOver::edges){
75 return edges(g);
76 }
77 else {
78 static_assert((iterate_over == IterateOver::vertices)
80 "Only the iterator pairs of vertices and edges can be"
81 "returned: iterate_over is set wrong!");
82 }
83}
84
85
87
106template<IterateOver iterate_over, typename Graph, typename EntityDesc>
107decltype(auto) iterator_pair(EntityDesc e, const Graph& g){
108 using namespace boost;
109
110 if constexpr (iterate_over == IterateOver::neighbors){
111 return adjacent_vertices(e, g);
112 }
113 else if constexpr (iterate_over == IterateOver::inv_neighbors){
114 return inv_adjacent_vertices(e, g);
115 }
116 else if constexpr (iterate_over == IterateOver::in_edges){
117 return in_edges(e, g);
118 }
119 else if constexpr (iterate_over == IterateOver::out_edges){
120 return out_edges(e, g);
121 }
122 else {
123 static_assert((iterate_over == IterateOver::neighbors)
127 "Only the iterator pairs of neighbors, inv_neighbors, "
128 "in_edge, and out_edge can be returned: "
129 "iterate_over is set wrong!");
130 }
131}
132
133} // namespace --- Graph
134
135
137
148template<IterateOver iterate_over, typename Graph>
149decltype(auto) range(const Graph& g){
150 return boost::make_iterator_range(
151 GraphUtils::iterator_pair<iterate_over>(g));
152}
153
154
156
176template<IterateOver iterate_over, typename Graph, typename EntityDesc>
177decltype(auto) range(EntityDesc e, const Graph& g){
178 return boost::make_iterator_range(
179 GraphUtils::iterator_pair<iterate_over>(e, g));
180}
181
182// end group GraphIterators
187} // namespace Utopia
188
189#endif // UTOPIA_CORE_GRAPH_ITERATORS_HH
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
IterateOver
Over which graph entity to iterate.
Definition iterator.hh:19
decltype(auto) range(const Graph &g)
Get the iterator range over selected graph entities.
Definition iterator.hh:149
@ in_edges
Iterate over the in edges of a vertex.
@ out_edges
Iterate over the out edges of a vertex.
@ neighbors
Iterate over neighbors (adjacent_vertices).
@ inv_neighbors
Iterate inversely over neighbors (adjacent_vertices).
@ vertices
Iterate over vertices.
@ edges
Iterate over edges.
decltype(auto) iterator_pair(const Graph &g)
Get an iterator pair over selected graph entities.
Definition iterator.hh:68
Definition agent.hh:11