PGROUTING  3.2
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
7 
8 Function's developer:
9 Copyright (c) 2015 Celia Virginia Vergara Castillo
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 
31 
32 #include <sstream>
33 #include <deque>
34 #include <vector>
35 
37 
38 #include "cpp_common/pgr_assert.h"
39 
40 
41 void
43  pgr_edge_t *data_edges,
44  size_t total_tuples,
45  bool directedFlag,
46 
47  Matrix_cell_t **return_tuples,
48  size_t *return_count,
49  char ** log_msg,
50  char ** err_msg) {
51  std::ostringstream log;
52  std::ostringstream err;
53 
54  try {
55  pgassert(!(*log_msg));
56  pgassert(!(*err_msg));
57  pgassert(!(*return_tuples));
58  pgassert(*return_count == 0);
59 
60  graphType gType = directedFlag? DIRECTED: UNDIRECTED;
61 
62 
63  if (directedFlag) {
64  log << "Processing Directed graph\n";
65  pgrouting::DirectedGraph digraph(gType);
66  digraph.insert_edges(data_edges, total_tuples);
67  pgr_floydWarshall(digraph, *return_count, return_tuples);
68  } else {
69  log << "Processing Undirected graph\n";
70  pgrouting::UndirectedGraph undigraph(gType);
71  undigraph.insert_edges(data_edges, total_tuples);
72  pgr_floydWarshall(undigraph, *return_count, return_tuples);
73  }
74 
75 
76  if (*return_count == 0) {
77  err << "No result generated, report this error\n";
78  *err_msg = pgr_msg(err.str().c_str());
79  *return_tuples = NULL;
80  *return_count = 0;
81  return;
82  }
83 
84  *log_msg = log.str().empty()?
85  *log_msg :
86  pgr_msg(log.str().c_str());
87  } catch (AssertFailedException &except) {
88  (*return_tuples) = pgr_free(*return_tuples);
89  (*return_count) = 0;
90  err << except.what();
91  *err_msg = pgr_msg(err.str().c_str());
92  *log_msg = pgr_msg(log.str().c_str());
93  } catch (std::exception &except) {
94  (*return_tuples) = pgr_free(*return_tuples);
95  (*return_count) = 0;
96  err << except.what();
97  *err_msg = pgr_msg(err.str().c_str());
98  *log_msg = pgr_msg(log.str().c_str());
99  } catch(...) {
100  (*return_tuples) = pgr_free(*return_tuples);
101  (*return_count) = 0;
102  err << "Caught unknown exception!";
103  *err_msg = pgr_msg(err.str().c_str());
104  *log_msg = pgr_msg(log.str().c_str());
105  }
106 }
pgr_edge_t
Definition: pgr_edge_t.h:37
pgr_msg
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
floydWarshall_driver.h
AssertFailedException::what
virtual const char * what() const
Definition: pgr_assert.cpp:67
pgr_allpairs.hpp
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
pgrouting::graph::Pgr_base_graph::insert_edges
void insert_edges(const T *edges, size_t count)
Inserts count edges of type T into the graph.
Definition: pgr_base_graph.hpp:357
pgr_floydWarshall
void pgr_floydWarshall(G &graph, std::vector< Matrix_cell_t > &rows)
Definition: pgr_allpairs.hpp:64
graphType
graphType
Definition: graph_enum.h:30
pgr_assert.h
An assert functionality that uses C++ throw().
DIRECTED
@ DIRECTED
Definition: graph_enum.h:30
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
pgrouting::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
do_pgr_floydWarshall
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)
Definition: floydWarshall_driver.cpp:42
matrix_cell
Definition: matrix_cell_t.h:37
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139