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
floydWarshall_driver.cpp
Go to the documentation of this file.
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 #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 "./floydWarshall_driver.h"
44 #include "./../../common/src/pgr_assert.h"
45 #include "./../../common/src/pgr_types.h"
46 
47 
48 void
50  pgr_edge_t *data_edges,
51  size_t total_tuples,
52  bool directedFlag,
53 
54  // return values
55  Matrix_cell_t **return_tuples,
56  size_t *return_count,
57  char ** log_msg,
58  char ** err_msg) {
59  // function starts
60  std::ostringstream log;
61  try {
62  pgassert(!(*log_msg));
63  pgassert(!(*err_msg));
64  pgassert(!(*return_tuples));
65  pgassert(*return_count == 0);
66 
67  graphType gType = directedFlag? DIRECTED: UNDIRECTED;
68 
69 
70  if (directedFlag) {
71  log << "Processing Directed graph\n";
72  pgrouting::DirectedGraph digraph(gType);
73  digraph.graph_insert_data(data_edges, total_tuples);
74  log << digraph;
75  pgr_floydWarshall(digraph, *return_count, return_tuples);
76  } else {
77  log << "Processing Undirected graph\n";
78  pgrouting::UndirectedGraph undigraph(gType);
79  undigraph.graph_insert_data(data_edges, total_tuples);
80  log << undigraph;
81  pgr_floydWarshall(undigraph, *return_count, return_tuples);
82  }
83 
84 
85  if (*return_count == 0) {
86  log << "NOTICE: No Vertices found??? wiered error\n";
87  *err_msg = strdup(log.str().c_str());
88  *return_tuples = NULL;
89  *return_count = 0;
90  return;
91  }
92 
93  *log_msg = strdup(log.str().c_str());
94  return;
95  } catch (AssertFailedException &except) {
96  if (*return_tuples) free(*return_tuples);
97  (*return_count) = 0;
98  log << except.what() << "\n";
99  *err_msg = strdup(log.str().c_str());
100  } catch (std::exception& except) {
101  if (*return_tuples) free(*return_tuples);
102  (*return_count) = 0;
103  log << except.what() << "\n";
104  *err_msg = strdup(log.str().c_str());
105  } catch(...) {
106  if (*return_tuples) free(*return_tuples);
107  (*return_count) = 0;
108  log << "Caught unknown exception!\n";
109  *err_msg = strdup(log.str().c_str());
110  }
111 }
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
void do_pgr_floydWarshall(pgr_edge_t *data_edges, size_t total_tuples, bool directedFlag, Matrix_cell_t **return_tuples, size_t *return_count, char **log_msg, char **err_msg)
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
graphType
Definition: pgr_types.h:192
virtual const char * what() const
Definition: pgr_assert.cpp:62
void pgr_floydWarshall(G &graph, std::vector< Matrix_cell_t > &rows)
char * err_msg
Definition: BDATester.cpp:50
void graph_insert_data(const T *edges, int64_t count)
Inserts count edges of type T into the graph.