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