PGROUTING  2.6-dev
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 
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 directed,
46  Matrix_cell_t **return_tuples,
47  size_t *return_count,
48  char ** log_msg,
49  char ** err_msg) {
50  std::ostringstream log;
51  std::ostringstream err;
52 
53  try {
54  pgassert(!(*log_msg));
55  pgassert(!(*err_msg));
56  pgassert(!(*return_tuples));
57  pgassert(*return_count == 0);
58 
59  graphType gType = directed? DIRECTED: UNDIRECTED;
60 
61  std::deque< Path >paths;
62 
63  if (directed) {
64  log << "Processing Directed graph\n";
65  pgrouting::DirectedGraph digraph(gType);
66  digraph.insert_edges(data_edges, total_tuples);
67  pgr_johnson(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_johnson(undigraph, *return_count, return_tuples);
73  }
74 
75 
76  if (*return_count == 0) {
77  log << "No result generated, report this error\n";
78  *log_msg = pgr_msg(err.str().c_str());
79  *return_tuples = NULL;
80  *return_count = 0;
81  return;
82  }
83 
84 
85  *log_msg = log.str().empty()?
86  *log_msg :
87  pgr_msg(log.str().c_str());
88  } catch (AssertFailedException &except) {
89  (*return_tuples) = pgr_free(*return_tuples);
90  (*return_count) = 0;
91  err << except.what();
92  *err_msg = pgr_msg(err.str().c_str());
93  *log_msg = pgr_msg(log.str().c_str());
94  } catch (std::exception &except) {
95  (*return_tuples) = pgr_free(*return_tuples);
96  (*return_count) = 0;
97  err << except.what();
98  *err_msg = pgr_msg(err.str().c_str());
99  *log_msg = pgr_msg(log.str().c_str());
100  } catch(...) {
101  (*return_tuples) = pgr_free(*return_tuples);
102  (*return_count) = 0;
103  err << "Caught unknown exception!";
104  *err_msg = pgr_msg(err.str().c_str());
105  *log_msg = pgr_msg(log.str().c_str());
106  }
107 }
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
void insert_edges(const T *edges, int64_t count)
Inserts count edges of type T into the graph.
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 **log_msg, char **err_msg)
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
Assertions Handling.
virtual const char * what() const
Definition: pgr_assert.cpp:53
graphType
Definition: graph_enum.h:30
void pgr_johnson(G &graph, std::vector< Matrix_cell_t > &rows)