PGROUTING  2.4
 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 
30 #include "./johnson_driver.h"
31 
32 #include <sstream>
33 #include <deque>
34 #include <vector>
35 
36 #include "./pgr_allpairs.hpp"
37 
38 #include "./../../common/src/pgr_types.h"
39 
40 // CREATE OR REPLACE FUNCTION pgr_johnson(edges_sql TEXT, directed BOOLEAN,
41 void
43  pgr_edge_t *data_edges,
44  size_t total_tuples,
45  bool directed,
46  Matrix_cell_t **return_tuples,
47  size_t *return_count,
48  char **err_msg) {
49  std::ostringstream log;
50  try {
51  if (total_tuples == 1) {
52  log << "Required: more than one tuple\n";
53  (*return_tuples) = NULL;
54  (*return_count) = 0;
55  *err_msg = strdup(log.str().c_str());
56  return;
57  }
58 
59  graphType gType = directed? DIRECTED: UNDIRECTED;
60 
61  std::deque< Path >paths;
62 
63  if (directed) {
64  log << "Working with directed Graph\n";
65  pgrouting::DirectedGraph digraph(gType);
66  digraph.insert_edges(data_edges, total_tuples);
67  pgr_johnson(digraph, *return_count, return_tuples);
68  } else {
69  log << "Working with Undirected Graph\n";
70  pgrouting::UndirectedGraph undigraph(gType);
71  undigraph.insert_edges(data_edges, total_tuples);
72  pgr_johnson(undigraph, *return_count, return_tuples);
73  }
74 
75  if (*return_count == 0) {
76  log << "NOTICE: No Vertices found??? wiered error\n";
77  *err_msg = strdup(log.str().c_str());
78  (*return_tuples) = NULL;
79  (*return_count) = 0;
80  return;
81  }
82 
83 #ifndef DEBUG
84  *err_msg = strdup("OK");
85 #else
86  *err_msg = strdup(log.str().c_str());
87 #endif
88  } catch ( ... ) {
89  log << "Caught unknown exception!\n";
90  *err_msg = strdup(log.str().c_str());
91  }
92 }
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: pgr_types.h:222
char * err_msg
Definition: BDATester.cpp:50
void pgr_johnson(G &graph, std::vector< Matrix_cell_t > &rows)