1#ifndef BOOST_SERIAL_GRAPH_H
2#define BOOST_SERIAL_GRAPH_H
7#include <boost/graph/graph_traits.hpp>
8#include <boost/graph/adjacency_list.hpp>
9#include <boost/graph/undirected_graph.hpp>
26template<
typename VertexData,
typename EdgeData>
72 typedef boost::undirected_graph<vertex_t, edge_t> graph_type;
73 typedef typename boost::graph_traits<graph_type>::vertex_descriptor vertex_descriptor_t;
74 typedef typename boost::graph_traits<graph_type>::edge_descriptor edge_descriptor_t;
140 std::pair<edge_iterator,edge_iterator>
edges()
const;
191template<
typename VertexData,
typename EdgeData>
197template<
typename VertexData,
typename EdgeData>
202 typedef typename BoostSerialGraph<VertexData,EdgeData>::vertex_descriptor_t vertex_descriptor_t;
203 uint_t idx = n_vertices();
206 vertex_descriptor_t
a = boost::add_vertex(g_);
213template<
typename VertexData,
typename EdgeData>
219 if(
v1>=n_vertices() ||
v2 >=n_vertices())
220 throw std::logic_error(
"Invalid vertex index v1/v2: "+
225 std::to_string(n_vertices())+
227 typedef typename BoostSerialGraph<VertexData,EdgeData>::vertex_descriptor_t vertex_descriptor_t;
228 typedef typename BoostSerialGraph<VertexData,EdgeData>::edge_descriptor_t edge_descriptor_t;
230 edge_descriptor_t
et;
234 vertex_descriptor_t
a = boost::vertex(
v1, g_);
235 vertex_descriptor_t
b = boost::vertex(
v2, g_);
246template<
typename VertexData,
typename EdgeData>
251 throw std::logic_error(
"Invalid vertex index. Index "+
254 std::to_string(n_vertices())+
258 typedef typename BoostSerialGraph<VertexData,EdgeData>::vertex_descriptor_t vertex_descriptor_t;
259 vertex_descriptor_t
a = boost::vertex(
i,g_);
263template<
typename VertexData,
typename EdgeData>
270template<
typename VertexData,
typename EdgeData>
277template<
typename VertexData,
typename EdgeData>
287template<
typename VertexData,
typename EdgeData>
291 if(
id >=n_vertices()){
292 throw std::logic_error(
"Invalid vertex index. Index "+
295 std::to_string(n_vertices())+
300 auto vneighs = get_vertex_neighbors(
id);
316template<
typename VertexData,
typename EdgeData>
322 if(
v1>=n_vertices() ||
v2 >=n_vertices())
323 throw std::logic_error(
"Invalid vertex index v1/v2. Indeces "+
328 std::to_string(n_vertices())+
331 typedef typename BoostSerialGraph<VertexData,EdgeData>::vertex_descriptor_t vertex_descriptor_t;
332 typedef typename BoostSerialGraph<VertexData,EdgeData>::edge_descriptor_t edge_descriptor_t;
333 vertex_descriptor_t
a = boost::vertex(
v1,g_);
334 vertex_descriptor_t
b = boost::vertex(
v2,g_);
336 std::pair<edge_descriptor_t,bool>
rslt = boost::edge(
a,
b,g_);
338 return g_[
rslt.first];
342template<
typename VertexData,
typename EdgeData>
352template<
typename VertexData,
typename EdgeData>
353std::pair<typename BoostSerialGraph<VertexData,EdgeData>::adjacency_iterator,
358 throw std::logic_error(
"Invalid vertex index. Index "+
361 std::to_string(n_vertices())+
365 typedef typename BoostSerialGraph<VertexData,EdgeData>::vertex_descriptor_t vertex_descriptor_t;
366 vertex_descriptor_t
a = boost::vertex(
i,g_);
367 return boost::adjacent_vertices(
a, g_);
370template<
typename VertexData,
typename EdgeData>
371std::pair<typename BoostSerialGraph<VertexData,EdgeData>::adjacency_iterator,
374 return get_vertex_neighbors(
v.id);
377template<
typename VertexData,
typename EdgeData>
378std::pair<typename BoostSerialGraph<VertexData,EdgeData>::edge_iterator,
381 return boost::edges(g_);
385template<
typename VertexData,
typename EdgeData>
389id(
bitrl::consts::INVALID_ID)
392template<
typename VertexData,
typename EdgeData>
396id(
bitrl::consts::INVALID_ID)
401template<
typename VertexData,
typename EdgeData>
409template<
typename VertexData,
typename EdgeData>
410typename BoostSerialGraph<VertexData,EdgeData>::SerialGraphNode&
. Representation of a graph using adjacency lists. The underlying implementation uses Boost Graph lib...
Definition boost_serial_graph.h:28
GenericLine< vertex_t, EdgeData > edge_t
edge_t The edge type
Definition boost_serial_graph.h:68
const edge_t & get_edge(uint_t v1, uint_t v2) const
Access the i-th edge of the graph with endpoints the given vertices.
Definition boost_serial_graph.h:318
EdgeData edge_data_t
edge_data_t The type of the edge data
Definition boost_serial_graph.h:40
std::vector< uint_t > get_vertex_neighbors_ids(uint_t id) const
get_vertex_neighbors_ids Returns the ids of the vertices connectected with this vertex
Definition boost_serial_graph.h:289
uint_t n_vertices() const
Returns the number of vertices.
Definition boost_serial_graph.h:161
uint_t max_vertex_index() const noexcept
Returns the maximum vertex index.
Definition boost_serial_graph.h:166
std::pair< adjacency_iterator, adjacency_iterator > get_vertex_neighbors(const vertex_t &v) const
Returns the neighboring vertices for the given vertex id.
const vertex_t & get_vertex(uint_t i) const
Access the i-th vertex of the graph.
Definition boost_serial_graph.h:248
vertex_t & add_vertex(const VertexData &data)
Add a vertex to the graph by providing the data.
Definition boost_serial_graph.h:199
graph_type::edge_iterator edge_iterator
edge_iterator Edge iterator
Definition boost_serial_graph.h:81
edge_t & add_edge(uint_t v1, uint_t v2)
Add an edge formed by the two given vertices.
Definition boost_serial_graph.h:215
VertexData vertex_data_t
vertex_data_t The type of the vertex data
Definition boost_serial_graph.h:35
BoostSerialGraph(uint_t nvs=0)
Constructor.
Definition boost_serial_graph.h:192
uint_t n_edges() const
Returns the number of edges.
Definition boost_serial_graph.h:171
SerialGraphNode vertex_t
vertex_t The vertex type
Definition boost_serial_graph.h:63
void clear()
Clear the graph.
Definition boost_serial_graph.h:181
std::pair< edge_iterator, edge_iterator > edges() const
edges Access the edges of the tree
Definition boost_serial_graph.h:380
graph_type::adjacency_iterator adjacency_iterator
adjacency_iterator Adjacency iterator
Definition boost_serial_graph.h:86
uint_t max_edge_index() const noexcept
Returns the maximum edge index.
Definition boost_serial_graph.h:176
std::pair< adjacency_iterator, adjacency_iterator > get_vertex_neighbors(uint_t id) const
Returns the neighboring vertices for the given vertex id.
Definition boost_serial_graph.h:355
const uint_t INVALID_ID
Invalid id.
Definition bitrl_consts.h:21
OutT resolve(const std::string &name, const std::map< std::string, std::any > &input)
Definition std_map_utils.h:25
Definition bitrl_consts.h:14
std::size_t uint_t
uint_t
Definition bitrl_types.h:43
Class that represents the Node of a graph.
Definition boost_serial_graph.h:46
vertex_data_t data
Definition boost_serial_graph.h:47
bool operator!=(const SerialGraphNode &o) const
Definition boost_serial_graph.h:57
SerialGraphNode(vertex_data_t &&data)
SerialGraphNode(const SerialGraphNode &o)
SerialGraphNode(const vertex_data_t &data)
uint_t id
Definition boost_serial_graph.h:48
bool operator==(const SerialGraphNode &o) const
Definition boost_serial_graph.h:56
SerialGraphNode()=default
SerialGraphNode & operator=(const SerialGraphNode &o)
Definition boost_serial_graph.h:411