PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
johnson_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: johnson_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) 2015 Celia Virginia Vergara Castillo
10 Mail: vicky_vergara@hotmail.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 
37 
38 
39 // CREATE OR REPLACE FUNCTION pgr_johnson(edges_sql TEXT, directed BOOLEAN,
40 void
42  pgr_edge_t *data_edges,
43  size_t total_tuples,
44  bool directed,
45  Matrix_cell_t **return_tuples,
46  size_t *return_count,
47  char **err_msg) {
48  std::ostringstream log;
49  try {
50  if (total_tuples == 1) {
51  log << "Required: more than one tuple\n";
52  (*return_tuples) = NULL;
53  (*return_count) = 0;
54  *err_msg = strdup(log.str().c_str());
55  return;
56  }
57 
58  graphType gType = directed? DIRECTED: UNDIRECTED;
59 
60  std::deque< Path >paths;
61 
62  if (directed) {
63  log << "Working with directed Graph\n";
64  pgrouting::DirectedGraph digraph(gType);
65  digraph.insert_edges(data_edges, total_tuples);
66  pgr_johnson(digraph, *return_count, return_tuples);
67  } else {
68  log << "Working with Undirected Graph\n";
69  pgrouting::UndirectedGraph undigraph(gType);
70  undigraph.insert_edges(data_edges, total_tuples);
71  pgr_johnson(undigraph, *return_count, return_tuples);
72  }
73 
74  if (*return_count == 0) {
75  log << "NOTICE: No Vertices found??? wiered error\n";
76  *err_msg = strdup(log.str().c_str());
77  (*return_tuples) = NULL;
78  (*return_count) = 0;
79  return;
80  }
81 
82 #ifndef DEBUG
83  *err_msg = strdup("OK");
84 #else
85  *err_msg = strdup(log.str().c_str());
86 #endif
87  } catch ( ... ) {
88  log << "Caught unknown exception!\n";
89  *err_msg = strdup(log.str().c_str());
90  }
91 }
void do_pgr_johnson(pgr_edge_t *data_edges, size_t total_tuples, bool directed, Matrix_cell_t **return_tuples, size_t *return_count, char **err_msg)
void insert_edges(const T *edges, int64_t count)
Inserts count edges of type T into the graph.
graphType
Definition: graph_enum.h:30
void pgr_johnson(G &graph, std::vector< Matrix_cell_t > &rows)