pgRouting  2.2
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide geospatial routing functionality.
 All Classes Functions Variables Pages
floydWarshall_driver.cpp
1 /*PGR-GNU*****************************************************************
2 File: floydWarshall_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 "./floydWarshall_driver.h"
41 
42 extern "C" {
43 #include "./../../common/src/pgr_types.h"
44 }
45 
46 
47 void
48 do_pgr_floydWarshall(
49  pgr_edge_t *data_edges,
50  size_t total_tuples,
51  bool directedFlag,
52 
53  // return values
54  Matrix_cell_t **postgres_rows,
55  size_t *result_tuple_count,
56  char ** err_msg) {
57 // function starts
58  std::ostringstream log;
59  try {
60  graphType gType = directedFlag? DIRECTED: UNDIRECTED;
61  const size_t initial_size = total_tuples;
62 
63 
64  if (directedFlag) {
65  log << "Processing Directed graph\n";
66  Pgr_base_graph< DirectedGraph > digraph(gType, initial_size);
67  digraph.graph_insert_data(data_edges, total_tuples);
68  pgr_floydWarshall(digraph, *result_tuple_count, postgres_rows);
69  } else {
70  log << "Processing Undirected graph\n";
71  Pgr_base_graph< UndirectedGraph > undigraph(gType, initial_size);
72  undigraph.graph_insert_data(data_edges, total_tuples);
73  pgr_floydWarshall(undigraph, *result_tuple_count, postgres_rows);
74  }
75 
76 
77  if (*result_tuple_count == 0) {
78  log << "NOTICE: No Vertices found??? wiered error\n";
79  *err_msg = strdup(log.str().c_str());
80  *postgres_rows = NULL;
81  *result_tuple_count = 0;
82  return;
83  }
84 #ifndef DEBUG
85  *err_msg = strdup("OK");
86 #else
87  *err_msg = strdup(log.str().c_str());
88 #endif
89  return;
90  } catch ( ... ) {
91  log << "Caught unknown expection!\n";
92  *err_msg = strdup(log.str().c_str());
93  *postgres_rows = NULL;
94  *result_tuple_count = 0;
95  return;
96  }
97 }
98 
99