PGROUTING  2.6-dev
lineGraph_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: lineGraph_driver.cpp
3 
4 Generated with Template by:
5 Copyright (c) 2015 pgRouting developers
6 Mail: project@pgrouting.org
7 
8 Function's developer:
9 Copyright (c) 2017 Vidhan Jain
10 Mail: vidhanj1307@gmail.com
11 
12 ------
13 
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18 
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23 
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 
28 ********************************************************************PGR-GNU*/
29 
31 
32 #include <sstream>
33 #include <deque>
34 #include <vector>
35 #include <utility>
36 
38 
39 #include "cpp_common/pgr_alloc.hpp"
40 #include "cpp_common/pgr_assert.h"
41 
44 
45 
47  std::vector< Line_graph_rt > edge_result,
48  Line_graph_rt **return_tuples,
49  size_t &sequence) {
50  (*return_tuples) = pgr_alloc(
51  static_cast<int>(edge_result.size()),
52  (*return_tuples));
53 
54  for (const auto &edge : edge_result) {
55  (*return_tuples)[sequence] = {edge.id, edge.source, edge.target,
57  sequence++;
58  }
59 }
60 
61 void
63  pgr_edge_t *data_edges,
64  size_t total_edges,
65  bool directed,
66  Line_graph_rt **return_tuples,
67  size_t *return_count,
68  char ** log_msg,
69  char ** notice_msg,
70  char ** err_msg) {
71  std::ostringstream log;
72  std::ostringstream err;
73  std::ostringstream notice;
74  try {
75  pgassert(!(*log_msg));
76  pgassert(!(*notice_msg));
77  pgassert(!(*err_msg));
78  pgassert(!(*return_tuples));
79  pgassert(*return_count == 0);
80  pgassert(total_edges != 0);
81 
82  std::vector< Line_graph_rt > results;
83  graphType gType = directed? DIRECTED: UNDIRECTED;
84 
85  pgrouting::DirectedGraph digraph(gType);
86  digraph.insert_edges_neg(data_edges, total_edges);
87 
88  log << digraph << "\n";
92  pgrouting::Basic_edge> line(digraph);
93  std::vector< Line_graph_rt > line_graph_edges;
94  line_graph_edges = line.get_postgres_results_directed();
95  auto count = line_graph_edges.size();
96 
97  if (count == 0) {
98  (*return_tuples) = NULL;
99  (*return_count) = 0;
100  notice <<
101  "Only vertices graph";
102  } else {
103  size_t sequence = 0;
104 
106  line_graph_edges,
107  return_tuples,
108  sequence);
109  (*return_count) = sequence;
110  }
111 
112  pgassert(*err_msg == NULL);
113  *log_msg = log.str().empty()?
114  *log_msg :
115  pgr_msg(log.str().c_str());
116  *notice_msg = notice.str().empty()?
117  *notice_msg :
118  pgr_msg(notice.str().c_str());
119  } catch (AssertFailedException &except) {
120  (*return_tuples) = pgr_free(*return_tuples);
121  (*return_count) = 0;
122  err << except.what();
123  *err_msg = pgr_msg(err.str().c_str());
124  *log_msg = pgr_msg(log.str().c_str());
125  } catch (std::exception &except) {
126  (*return_tuples) = pgr_free(*return_tuples);
127  (*return_count) = 0;
128  err << except.what();
129  *err_msg = pgr_msg(err.str().c_str());
130  *log_msg = pgr_msg(log.str().c_str());
131  } catch(...) {
132  (*return_tuples) = pgr_free(*return_tuples);
133  (*return_count) = 0;
134  err << "Caught unknown exception!";
135  *err_msg = pgr_msg(err.str().c_str());
136  *log_msg = pgr_msg(log.str().c_str());
137  }
138 }
float8 cost
Definition: trsp.h:35
void insert_edges_neg(const T *edges, int64_t count)
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
Definition: trsp.h:31
long id
Definition: trsp.h:32
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, Line_vertex, Basic_edge > LinearDirectedGraph
Data type to handle graph -> lineGaph transformation.
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
Assertions Handling.
virtual const char * what() const
Definition: pgr_assert.cpp:53
void get_postgres_result(std::vector< Line_graph_rt > edge_result, Line_graph_rt **return_tuples, size_t &sequence)
graphType
Definition: graph_enum.h:30
long target
Definition: trsp.h:34
void do_pgr_lineGraph(pgr_edge_t *data_edges, size_t total_edges, bool directed, Line_graph_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
float8 reverse_cost
Definition: trsp.h:36
long source
Definition: trsp.h:33