pgRouting
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide geospatial routing functionality.
 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 #if defined(__MINGW32__) || defined(_MSC_VER)
31 #include <winsock2.h>
32 #include <windows.h>
33 #ifdef open
34 #undef open
35 #endif
36 #endif
37 
38 
39 #include <sstream>
40 #include <deque>
41 #include <vector>
42 #include "./pgr_allpairs.hpp"
43 #include "./johnson_driver.h"
44 #include "./../../common/src/pgr_types.h"
45 
46 // CREATE OR REPLACE FUNCTION pgr_johnson(edges_sql TEXT, directed BOOLEAN,
47 void
49  pgr_edge_t *data_edges,
50  size_t total_tuples,
51  bool directed,
52  Matrix_cell_t **return_tuples,
53  size_t *return_count,
54  char **err_msg) {
55  std::ostringstream log;
56  try {
57  if (total_tuples == 1) {
58  log << "Required: more than one tuple\n";
59  (*return_tuples) = NULL;
60  (*return_count) = 0;
61  *err_msg = strdup(log.str().c_str());
62  return;
63  }
64 
65  graphType gType = directed? DIRECTED: UNDIRECTED;
66 
67  std::deque< Path >paths;
68 
69  if (directed) {
70  log << "Working with directed Graph\n";
71  pgrouting::DirectedGraph digraph(gType);
72  digraph.graph_insert_data(data_edges, total_tuples);
73  pgr_johnson(digraph, *return_count, return_tuples);
74  } else {
75  log << "Working with Undirected Graph\n";
76  pgrouting::UndirectedGraph undigraph(gType);
77  undigraph.graph_insert_data(data_edges, total_tuples);
78  pgr_johnson(undigraph, *return_count, return_tuples);
79  }
80 
81  if (*return_count == 0) {
82  log << "NOTICE: No Vertices found??? wiered error\n";
83  *err_msg = strdup(log.str().c_str());
84  (*return_tuples) = NULL;
85  (*return_count) = 0;
86  return;
87  }
88 
89 #ifndef DEBUG
90  *err_msg = strdup("OK");
91 #else
92  *err_msg = strdup(log.str().c_str());
93 #endif
94  } catch ( ... ) {
95  log << "Caught unknown exception!\n";
96  *err_msg = strdup(log.str().c_str());
97  }
98 }
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)
graphType
Definition: pgr_types.h:192
char * err_msg
Definition: BDATester.cpp:50
void pgr_johnson(G &graph, std::vector< Matrix_cell_t > &rows)
void graph_insert_data(const T *edges, int64_t count)
Inserts count edges of type T into the graph.