PGROUTING  3.2
pgrouting::functions::Pgr_sequentialVertexColoring< G > Class Template Reference

#include "pgr_sequentialVertexColoring.hpp"

Public Types

typedef G::E E
 
typedef boost::adjacency_list< boost::listS, boost::vecS, boost::undirectedS > Graph
 
typedef G::V V
 
typedef boost::graph_traits< Graph >::vertices_size_type vertices_size_type
 

SequentialVertexColoring

std::vector< pgr_vertex_color_rtsequentialVertexColoring (G &graph)
 sequentialVertexColoring function More...
 
std::vector< pgr_vertex_color_rtget_results (std::vector< vertices_size_type > &colors, const G &graph)
 to get the results More...
 

Detailed Description

template<class G>
class pgrouting::functions::Pgr_sequentialVertexColoring< G >

Definition at line 58 of file pgr_sequentialVertexColoring.hpp.

Member Typedef Documentation

◆ E

template<class G >
typedef G::E pgrouting::functions::Pgr_sequentialVertexColoring< G >::E

Definition at line 61 of file pgr_sequentialVertexColoring.hpp.

◆ Graph

template<class G >
typedef boost::adjacency_list< boost::listS, boost::vecS, boost::undirectedS > pgrouting::functions::Pgr_sequentialVertexColoring< G >::Graph

Definition at line 62 of file pgr_sequentialVertexColoring.hpp.

◆ V

template<class G >
typedef G::V pgrouting::functions::Pgr_sequentialVertexColoring< G >::V

Definition at line 60 of file pgr_sequentialVertexColoring.hpp.

◆ vertices_size_type

template<class G >
typedef boost::graph_traits< Graph >::vertices_size_type pgrouting::functions::Pgr_sequentialVertexColoring< G >::vertices_size_type

Definition at line 63 of file pgr_sequentialVertexColoring.hpp.

Member Function Documentation

◆ get_results()

template<class G >
std::vector< pgr_vertex_color_rt > pgrouting::functions::Pgr_sequentialVertexColoring< G >::get_results ( std::vector< vertices_size_type > &  colors,
const G &  graph 
)
inlineprivate

to get the results

Uses the colors vector to get the results i.e. the color of every vertex.

Parameters
colorsvector which contains the color of every vertex
graphthe graph containing the edges
Returns
results vector

Definition at line 124 of file pgr_sequentialVertexColoring.hpp.

126  {
127  std::vector < pgr_vertex_color_rt > results;
128 
129  typename boost::graph_traits < Graph > ::vertex_iterator v, vend;
130 
131  for (boost::tie(v, vend) = vertices(graph.graph); v != vend; ++v) {
132  int64_t node = graph[*v].id;
133  auto color = colors[*v];
134  results.push_back({ node, static_cast<int64_t>(color + 1) });
135  }
136 
137  // ordering the results in an increasing order of the node id
138  std::sort(results.begin(), results.end(),
139  [](const pgr_vertex_color_rt row1, const pgr_vertex_color_rt row2) {
140  return row1.node < row2.node;
141  });
142 
143  return results;
144  }

Referenced by pgrouting::functions::Pgr_sequentialVertexColoring< G >::sequentialVertexColoring().

◆ sequentialVertexColoring()

template<class G >
std::vector< pgr_vertex_color_rt > pgrouting::functions::Pgr_sequentialVertexColoring< G >::sequentialVertexColoring ( G &  graph)
inline

sequentialVertexColoring function

It does all the processing and returns the results.

Parameters
graphthe graph containing the edges
Returns
results, when results are found
See also
boost::sequential_vertex_coloring

Definition at line 81 of file pgr_sequentialVertexColoring.hpp.

81  {
82  std::vector < pgr_vertex_color_rt > results;
83 
84  auto i_map = boost::get(boost::vertex_index, graph.graph);
85 
86  // vector which will store the color of all the vertices in the graph
87  std::vector < vertices_size_type > colors(boost::num_vertices(graph.graph));
88 
89  // An iterator property map which records the color of each vertex
90  auto color_map = boost::make_iterator_property_map(colors.begin(), i_map);
91 
92  /* abort in case of an interruption occurs (e.g. the query is being cancelled) */
93  CHECK_FOR_INTERRUPTS();
94 
95  try {
96  boost::sequential_vertex_coloring(graph.graph, color_map);
97  } catch (boost::exception const& ex) {
98  (void)ex;
99  throw;
100  } catch (std::exception &e) {
101  (void)e;
102  throw;
103  } catch (...) {
104  throw;
105  }
106 
107  results = get_results(colors, graph);
108 
109  return results;
110  }

References pgrouting::functions::Pgr_sequentialVertexColoring< G >::get_results().

Referenced by pgr_sequentialVertexColoring().


The documentation for this class was generated from the following file:
pgrouting::functions::Pgr_sequentialVertexColoring::get_results
std::vector< pgr_vertex_color_rt > get_results(std::vector< vertices_size_type > &colors, const G &graph)
to get the results
Definition: pgr_sequentialVertexColoring.hpp:124
pgr_vertex_color_rt
Definition: pgr_vertex_color_rt.h:36