Py2Cpp 1.6.3; VERSION ${PROJECT_VERSION}
Loading...
Searching...
No Matches
nx2bgl.hpp
Go to the documentation of this file.
1
9#pragma once
10
11#include <boost/graph/adjacency_list.hpp>
12#include <boost/graph/graph_traits.hpp>
13#include <boost/graph/graph_utility.hpp>
14#include <type_traits>
15
16namespace py {
17
26 template <typename Graph> class VertexView : public Graph {
27 public:
35 explicit VertexView(Graph&& gra) noexcept : Graph{std::forward<Graph>(gra)} {}
36
44 [[nodiscard]] auto begin() const {
45 // auto [v_iter, v_end] = boost::vertices(*this);
46 // return v_iter;
47 return boost::vertices(*this).first;
48 }
49
57 [[nodiscard]] auto end() const {
58 // auto [v_iter, v_end] = boost::vertices(*this);
59 // return v_end;
60 return boost::vertices(*this).second;
61 }
62
70 [[nodiscard]] auto cbegin() const {
71 // auto [v_iter, v_end] = boost::vertices(*this);
72 // return v_iter;
73 return boost::vertices(*this).first;
74 }
75
83 [[nodiscard]] auto cend() const {
84 // auto [v_iter, v_end] = boost::vertices(*this);
85 // return v_end;
86 return boost::vertices(*this).second;
87 }
88 };
89
98 template <typename Graph> class EdgeView {
99 private:
100 const Graph& gra;
101
102 public:
110 explicit EdgeView(const Graph& gra) : gra{gra} {}
111
119 [[nodiscard]] auto begin() const {
120 // auto [e_iter, e_end] = boost::edges(_gra);
121 // return e_iter;
122 return boost::edges(this->gra).first;
123 }
124
132 [[nodiscard]] auto end() const {
133 // auto [e_iter, e_end] = boost::edges(_gra);
134 // return e_end;
135 return boost::edges(this->gra).second;
136 }
137
145 [[nodiscard]] auto cbegin() const {
146 // auto [e_iter, e_end] = boost::edges(_gra);
147 // return e_iter;
148 return boost::edges(this->gra).first;
149 }
150
158 [[nodiscard]] auto cend() const {
159 // auto [e_iter, e_end] = boost::edges(_gra);
160 // return e_end;
161 return boost::edges(this->gra).second;
162 }
163 };
164
175 template <typename Vertex, typename Graph> class AtlasView {
176 private:
177 Vertex _v;
178 const Graph& gra;
179
180 public:
189 AtlasView(Vertex v, const Graph& gra) : _v{v}, gra{gra} {}
190
198 auto begin() const {
199 // auto [e_iter, e_end] = boost::out_edges(_v, _gra);
200 // return e_iter;
201 return boost::out_edges(this->_v, this->gra).first;
202 }
203
211 auto end() const {
212 // auto [e_iter, e_end] = boost::out_edges(_v, _gra);
213 // return e_end;
214 return boost::out_edges(this->_v, this->gra).second;
215 }
216
224 auto cbegin() const {
225 // auto [e_iter, e_end] = boost::out_edges(_v, _gra);
226 // return e_iter;
227 return boost::out_edges(this->_v, this->gra).first;
228 }
229
237 auto cend() const {
238 // auto [e_iter, e_end] = boost::out_edges(_v, _gra);
239 // return e_end;
240 return boost::out_edges(this->_v, this->gra).second;
241 }
242 };
243
252 template <typename _Graph> class GrAdaptor : public VertexView<_Graph> {
253 public:
254 using Vertex = typename boost::graph_traits<_Graph>::vertex_descriptor;
255 using node_t = Vertex;
256 using edge_t = typename boost::graph_traits<_Graph>::edge_descriptor;
257
258 // using edge_wt_t = decltype( boost::get(boost::edge_weight,
259 // std::declval<_Graph>()) );
260
266 GrAdaptor() = delete;
267
275 explicit GrAdaptor(_Graph&& gra) noexcept : VertexView<_Graph>{std::forward<_Graph>(gra)} {}
276
277 // GrAdaptor(const GrAdaptor&) = delete; // don't copy
278 // GrAdaptor& operator=(const GrAdaptor&) = delete; // don't assign
279 // GrAdaptor(GrAdaptor&&) noexcept = default; // don't copy
280
286 [[nodiscard]] auto number_of_nodes() const { return boost::num_vertices(*this); }
287
293 [[nodiscard]] auto number_of_edges() const { return boost::num_edges(*this); }
294
302 [[nodiscard]] auto edges() const -> EdgeView<_Graph> { return EdgeView<_Graph>(*this); }
303
312 [[nodiscard]] auto neighbors(Vertex v) const -> AtlasView<Vertex, _Graph> {
313 return AtlasView<Vertex, _Graph>(v, *this);
314 }
315
323 auto add_edge(int u, int v) {
324 return boost::add_edge(static_cast<Vertex>(u), static_cast<Vertex>(v), *this);
325 }
326
334 static auto null_vertex() -> Vertex { return boost::graph_traits<_Graph>::null_vertex(); }
335
345 template <typename Edge> auto source(const Edge& e) const -> Vertex {
346 return boost::source(e, *this);
347 }
348
358 template <typename Edge> auto target(const Edge& e) const -> Vertex {
359 return boost::target(e, *this);
360 }
361
369 template <typename Edge> [[nodiscard]] auto end_points(const Edge& e) const {
370 auto s = boost::source(e, *this);
371 auto t = boost::target(e, *this);
372 return std::make_pair(s, t);
373 }
374 };
375
376} // namespace py
Atlas view for vertex adjacency in Boost Graph Library graphs.
Definition nx2bgl.hpp:175
auto end() const
Get iterator to the end of adjacent edges.
Definition nx2bgl.hpp:211
AtlasView(Vertex v, const Graph &gra)
Construct a new Atlas View object.
Definition nx2bgl.hpp:189
auto cend() const
Get const iterator to the end of adjacent edges.
Definition nx2bgl.hpp:237
auto begin() const
Get iterator to the beginning of adjacent edges.
Definition nx2bgl.hpp:198
auto cbegin() const
Get const iterator to the beginning of adjacent edges.
Definition nx2bgl.hpp:224
Edge view for Boost Graph Library graphs.
Definition nx2bgl.hpp:98
auto begin() const
Get iterator to the beginning of edges.
Definition nx2bgl.hpp:119
auto cend() const
Get const iterator to the end of edges.
Definition nx2bgl.hpp:158
auto cbegin() const
Get const iterator to the beginning of edges.
Definition nx2bgl.hpp:145
EdgeView(const Graph &gra)
Construct a new Edge View object.
Definition nx2bgl.hpp:110
auto end() const
Get iterator to the end of edges.
Definition nx2bgl.hpp:132
Graph adapter for Boost Graph Library integration.
Definition nx2bgl.hpp:252
static auto null_vertex() -> Vertex
Get the null vertex descriptor.
Definition nx2bgl.hpp:334
auto source(const Edge &e) const -> Vertex
Get the source vertex of an edge.
Definition nx2bgl.hpp:345
auto end_points(const Edge &e) const
Get the source and target vertices of an edge.
Definition nx2bgl.hpp:369
typename boost::graph_traits< _Graph >::edge_descriptor edge_t
Definition nx2bgl.hpp:256
auto add_edge(int u, int v)
Add an edge between two vertices.
Definition nx2bgl.hpp:323
GrAdaptor()=delete
Default constructor (deleted)
typename boost::graph_traits< _Graph >::vertex_descriptor Vertex
Definition nx2bgl.hpp:254
auto neighbors(Vertex v) const -> AtlasView< Vertex, _Graph >
Get neighbors of a vertex.
Definition nx2bgl.hpp:312
auto number_of_nodes() const
Get the number of vertices in the graph.
Definition nx2bgl.hpp:286
Vertex node_t
Definition nx2bgl.hpp:255
auto number_of_edges() const
Get the number of edges in the graph.
Definition nx2bgl.hpp:293
auto edges() const -> EdgeView< _Graph >
Get an edge view for the graph.
Definition nx2bgl.hpp:302
GrAdaptor(_Graph &&gra) noexcept
Construct a new graph adaptor object.
Definition nx2bgl.hpp:275
auto target(const Edge &e) const -> Vertex
Get the target vertex of an edge.
Definition nx2bgl.hpp:358
Vertex view for Boost Graph Library graphs.
Definition nx2bgl.hpp:26
auto cend() const
Get const iterator to the end of vertices.
Definition nx2bgl.hpp:83
auto cbegin() const
Get const iterator to the beginning of vertices.
Definition nx2bgl.hpp:70
auto end() const
Get iterator to the end of vertices.
Definition nx2bgl.hpp:57
VertexView(Graph &&gra) noexcept
Construct a new Vertex View object.
Definition nx2bgl.hpp:35
auto begin() const
Get iterator to the beginning of vertices.
Definition nx2bgl.hpp:44
Python-like utilities and data structures for C++.
Definition dict.hpp:18