PGROUTING  3.2
lineGraphFull_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: lineGraphFull_driver.cpp
3 
4 Generated with Template by:
5 Copyright (c) 2015 pgRouting developers
7 
8 Function's developer:
9 Copyright (c) 2017 Anthony Nicola Tasca
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 
37 
38 #include "cpp_common/pgr_alloc.hpp"
39 #include "cpp_common/pgr_assert.h"
40 
43 
45  std::vector< Line_graph_full_rt > edge_result,
46  Line_graph_full_rt **return_tuples,
47  size_t &sequence) {
48  (*return_tuples) = pgr_alloc(edge_result.size(), (*return_tuples));
49 
50  for (const auto &edge : edge_result) {
51  (*return_tuples)[sequence] =
52  {edge.id,
53  edge.source,
54  edge.target,
55  edge.cost,
56  edge.edge};
57  sequence++;
58  }
59 }
60 
61 void
63  pgr_edge_t *data_edges,
64  size_t total_edges,
65  Line_graph_full_rt **return_tuples,
66  size_t *return_count,
67  char ** log_msg,
68  char ** notice_msg,
69  char ** err_msg) {
70  std::ostringstream log;
71  std::ostringstream err;
72  std::ostringstream notice;
73  try {
74  pgassert(!(*log_msg));
75  pgassert(!(*notice_msg));
76  pgassert(!(*err_msg));
77  pgassert(!(*return_tuples));
78  pgassert(*return_count == 0);
79  pgassert(total_edges != 0);
80 
81  graphType gType = DIRECTED;
82 
83  pgrouting::DirectedGraph digraph(gType);
84  digraph.insert_edges_neg(data_edges, total_edges);
85 
86 #if 0
87  log << digraph << "\n";
88 #endif
92  pgrouting::Basic_edge > line(digraph);
93 
94  std::vector< Line_graph_full_rt > line_graph_edges;
95  line_graph_edges = line.get_postgres_results_directed();
96 
97  auto count = line_graph_edges.size();
98 
99  if (count == 0) {
100  (*return_tuples) = NULL;
101  (*return_count) = 0;
102  /* TODO change the notice message */
103  notice <<
104  "No paths found between start_vid and end_vid vertices";
105  } else {
106  size_t sequence = 0;
107 
109  line_graph_edges,
110  return_tuples,
111  sequence);
112  (*return_count) = sequence;
113  }
114 #if 1
115  log << line.log.str().c_str() << "\n\n\n";
116  log << line << "\n";
117 #endif
118  pgassert(*err_msg == NULL);
119  *log_msg = log.str().empty()?
120  *log_msg :
121  pgr_msg(log.str().c_str());
122  *notice_msg = notice.str().empty()?
123  *notice_msg :
124  pgr_msg(notice.str().c_str());
125  } catch (AssertFailedException &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 (std::exception &except) {
132  (*return_tuples) = pgr_free(*return_tuples);
133  (*return_count) = 0;
134  err << except.what();
135  *err_msg = pgr_msg(err.str().c_str());
136  *log_msg = pgr_msg(log.str().c_str());
137  } catch(...) {
138  (*return_tuples) = pgr_free(*return_tuples);
139  (*return_count) = 0;
140  err << "Caught unknown exception!";
141  *err_msg = pgr_msg(err.str().c_str());
142  *log_msg = pgr_msg(log.str().c_str());
143  }
144 }
pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
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
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pgrouting::graph::Pgr_lineGraphFull
Definition: pgr_lineGraphFull.hpp:47
pgr_alloc.hpp
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().
lineGraphFull_driver.h
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
get_turn_penalty_postgres_result
void get_turn_penalty_postgres_result(std::vector< Line_graph_full_rt > edge_result, Line_graph_full_rt **return_tuples, size_t &sequence)
Definition: lineGraphFull_driver.cpp:44
do_pgr_lineGraphFull
void do_pgr_lineGraphFull(pgr_edge_t *data_edges, size_t total_edges, Line_graph_full_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: lineGraphFull_driver.cpp:62
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
pgr_lineGraphFull.hpp
Line_graph_full_rt
Definition: line_graph_full_rt.h:42
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139