PGROUTING  3.2
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
7 
8 Function's developer:
9 Copyright (c) 2017 Vidhan Jain
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(edge_result.size(), (*return_tuples));
51 
52  for (const auto &edge : edge_result) {
53  (*return_tuples)[sequence] = {edge.id, edge.source, edge.target,
55  sequence++;
56  }
57 }
58 
59 void
61  pgr_edge_t *data_edges,
62  size_t total_edges,
63  bool directed,
64  Line_graph_rt **return_tuples,
65  size_t *return_count,
66  char ** log_msg,
67  char ** notice_msg,
68  char ** err_msg) {
69  std::ostringstream log;
70  std::ostringstream err;
71  std::ostringstream notice;
72  try {
73  pgassert(!(*log_msg));
74  pgassert(!(*notice_msg));
75  pgassert(!(*err_msg));
76  pgassert(!(*return_tuples));
77  pgassert(*return_count == 0);
78  pgassert(total_edges != 0);
79 
80  graphType gType = directed? DIRECTED: UNDIRECTED;
81 
82  pgrouting::DirectedGraph digraph(gType);
83  digraph.insert_edges_neg(data_edges, total_edges);
84 
85  log << digraph << "\n";
89  pgrouting::Basic_edge> line(digraph);
90  std::vector< Line_graph_rt > line_graph_edges;
91  line_graph_edges = line.get_postgres_results_directed();
92  auto count = line_graph_edges.size();
93 
94  if (count == 0) {
95  (*return_tuples) = NULL;
96  (*return_count) = 0;
97  notice <<
98  "Only vertices graph";
99  } else {
100  size_t sequence = 0;
101 
103  line_graph_edges,
104  return_tuples,
105  sequence);
106  (*return_count) = sequence;
107  }
108 
109  pgassert(*err_msg == NULL);
110  *log_msg = log.str().empty()?
111  *log_msg :
112  pgr_msg(log.str().c_str());
113  *notice_msg = notice.str().empty()?
114  *notice_msg :
115  pgr_msg(notice.str().c_str());
116  } catch (AssertFailedException &except) {
117  (*return_tuples) = pgr_free(*return_tuples);
118  (*return_count) = 0;
119  err << except.what();
120  *err_msg = pgr_msg(err.str().c_str());
121  *log_msg = pgr_msg(log.str().c_str());
122  } catch (std::exception &except) {
123  (*return_tuples) = pgr_free(*return_tuples);
124  (*return_count) = 0;
125  err << except.what();
126  *err_msg = pgr_msg(err.str().c_str());
127  *log_msg = pgr_msg(log.str().c_str());
128  } catch(...) {
129  (*return_tuples) = pgr_free(*return_tuples);
130  (*return_count) = 0;
131  err << "Caught unknown exception!";
132  *err_msg = pgr_msg(err.str().c_str());
133  *log_msg = pgr_msg(log.str().c_str());
134  }
135 }
edge::reverse_cost
float8 reverse_cost
Definition: trsp.h:46
pgr_lineGraph.hpp
pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
do_pgr_lineGraph
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)
Definition: lineGraph_driver.cpp:60
edge::cost
float8 cost
Definition: trsp.h:45
edge::target
int64 target
Definition: trsp.h:44
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
pgrouting::LinearDirectedGraph
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, Line_vertex, Basic_edge > LinearDirectedGraph
Data type to handle graph -> lineGaph transformation.
Definition: linear_directed_graph.h:55
pgrouting::Basic_edge
Definition: basic_edge.h:35
edge
Definition: trsp.h:41
Line_graph_rt
Definition: line_graph_rt.h:42
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
pgr_alloc.hpp
pgrouting::graph::Pgr_lineGraph
Definition: pgr_lineGraph.hpp:49
edge::source
int64 source
Definition: trsp.h:43
graphType
graphType
Definition: graph_enum.h:30
pgr_assert.h
An assert functionality that uses C++ throw().
pgr_dijkstra.hpp
DIRECTED
@ DIRECTED
Definition: graph_enum.h:30
pgrouting::graph::Pgr_base_graph::insert_edges_neg
void insert_edges_neg(const T *edges, size_t count)
Definition: pgr_base_graph.hpp:362
edge::id
int64 id
Definition: trsp.h:42
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
pgrouting::Line_vertex
Definition: line_vertex.h:45
pgrouting::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
linear_directed_graph.h
get_postgres_result
void get_postgres_result(std::vector< Line_graph_rt > edge_result, Line_graph_rt **return_tuples, size_t &sequence)
Definition: lineGraph_driver.cpp:46
lineGraph_driver.h
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139