PGROUTING  3.2
sequentialVertexColoring_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: sequentialVertexColoring_driver.cpp
3 
4 Generated with Template by:
5 Copyright (c) 2020 pgRouting developers
7 
8 Function's developer:
9 Copyright (c) 2020 Ashish Kumar
11 ------
12 
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17 
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22 
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 
27  ********************************************************************PGR-GNU*/
28 
30 
31 #include <sstream>
32 #include <vector>
33 #include <algorithm>
34 #include <string>
35 
36 #include "cpp_common/pgr_alloc.hpp"
37 #include "cpp_common/pgr_assert.h"
38 
40 
46 /***********************************************************************
47  *
48  * pgr_sequentialVertexColoring(edges_sql TEXT);
49  *
50  ***********************************************************************/
51 
60 template < class G >
61 std::vector < pgr_vertex_color_rt >
64  auto results = fn_sequentialVertexColoring.sequentialVertexColoring(graph);
65  return results;
66 }
67 
92 void
94  pgr_edge_t *data_edges,
95  size_t total_edges,
96 
97  pgr_vertex_color_rt **return_tuples,
98  size_t *return_count,
99 
100  char ** log_msg,
101  char ** notice_msg,
102  char ** err_msg) {
103  std::ostringstream log;
104  std::ostringstream err;
105  std::ostringstream notice;
106  try {
107  pgassert(!(*log_msg));
108  pgassert(!(*notice_msg));
109  pgassert(!(*err_msg));
110  pgassert(!(*return_tuples));
111  pgassert(*return_count == 0);
112 
113  std::vector < pgr_vertex_color_rt > results;
114 
115  graphType gType = UNDIRECTED;
116  pgrouting::UndirectedGraph undigraph(gType);
117 
118  undigraph.insert_edges(data_edges, total_edges);
119 
120  results = pgr_sequentialVertexColoring(undigraph);
121 
122  auto count = results.size();
123 
124  if (count == 0) {
125  (*return_tuples) = NULL;
126  (*return_count) = 0;
127  notice << "No traversal found";
128  *log_msg = pgr_msg(notice.str().c_str());
129  return;
130  }
131 
132  (*return_tuples) = pgr_alloc(count, (*return_tuples));
133  for (size_t i = 0; i < count; i++) {
134  *((*return_tuples) + i) = results[i];
135  }
136  (*return_count) = count;
137 
138  pgassert(*err_msg == NULL);
139  *log_msg = log.str().empty()?
140  *log_msg :
141  pgr_msg(log.str().c_str());
142  *notice_msg = notice.str().empty()?
143  *notice_msg :
144  pgr_msg(notice.str().c_str());
145  } catch (AssertFailedException &except) {
146  (*return_tuples) = pgr_free(*return_tuples);
147  (*return_count) = 0;
148  err << except.what();
149  *err_msg = pgr_msg(err.str().c_str());
150  *log_msg = pgr_msg(log.str().c_str());
151  } catch (std::exception &except) {
152  (*return_tuples) = pgr_free(*return_tuples);
153  (*return_count) = 0;
154  err << except.what();
155  *err_msg = pgr_msg(err.str().c_str());
156  *log_msg = pgr_msg(log.str().c_str());
157  } catch(...) {
158  (*return_tuples) = pgr_free(*return_tuples);
159  (*return_count) = 0;
160  err << "Caught unknown exception!";
161  *err_msg = pgr_msg(err.str().c_str());
162  *log_msg = pgr_msg(log.str().c_str());
163  }
164 }
pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
pgr_edge_t
Definition: pgr_edge_t.h:37
pgr_msg
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
AssertFailedException::what
virtual const char * what() const
Definition: pgr_assert.cpp:67
pgr_sequentialVertexColoring
std::vector< pgr_vertex_color_rt > pgr_sequentialVertexColoring(G &graph)
Calls the main function defined in the C++ Header file.
Definition: sequentialVertexColoring_driver.cpp:62
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
pgrouting::graph::Pgr_base_graph::insert_edges
void insert_edges(const T *edges, size_t count)
Inserts count edges of type T into the graph.
Definition: pgr_base_graph.hpp:357
pgrouting::functions::Pgr_sequentialVertexColoring
Definition: pgr_sequentialVertexColoring.hpp:58
pgr_alloc.hpp
do_pgr_sequentialVertexColoring
void do_pgr_sequentialVertexColoring(pgr_edge_t *data_edges, size_t total_edges, pgr_vertex_color_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Performs exception handling and converts the results to postgres.
Definition: sequentialVertexColoring_driver.cpp:93
pgr_sequentialVertexColoring.hpp
The main file which calls the respective boost function.
graphType
graphType
Definition: graph_enum.h:30
pgr_assert.h
An assert functionality that uses C++ throw().
pgrouting::functions::Pgr_sequentialVertexColoring::sequentialVertexColoring
std::vector< pgr_vertex_color_rt > sequentialVertexColoring(G &graph)
sequentialVertexColoring function
Definition: pgr_sequentialVertexColoring.hpp:81
pgrouting::alphashape::G
graph::Pgr_base_graph< BG, XY_vertex, Basic_edge > G
Definition: pgr_alphaShape.h:56
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
pgrouting::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
sequentialVertexColoring_driver.h
pgr_vertex_color_rt
Definition: pgr_vertex_color_rt.h:36
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139