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
many_to_many_dijkstra_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: many_to_many_dijkstra_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 #endif
34 
35 #include <sstream>
36 #include <deque>
37 #include <vector>
38 #include <set>
39 #include "./pgr_dijkstra.hpp"
41 
42 #include "../../common/src/pgr_alloc.hpp"
43 #include "./../../common/src/pgr_types.h"
44 
45 // CREATE OR REPLACE FUNCTION pgr_dijkstra(
46 // sql text,
47 // start_vids anyarray,
48 // end_vids anyarray,
49 // directed boolean default true,
50 void
52  pgr_edge_t *data_edges,
53  size_t total_tuples,
54  int64_t *start_vidsArr,
55  size_t size_start_vidsArr,
56  int64_t *end_vidsArr,
57  size_t size_end_vidsArr,
58  bool directed,
59  bool only_cost,
60  General_path_element_t **return_tuples,
61  size_t *return_count,
62  char ** err_msg) {
63  std::ostringstream log;
64  try {
65  graphType gType = directed? DIRECTED: UNDIRECTED;
66 
67  std::deque< Path >paths;
68  log << "Inserting vertices into a c++ vector structure\n";
69  std::set< int64_t >
70  s_start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr);
71  std::set< int64_t >
72  s_end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr);
73 
74  std::vector< int64_t > start_vertices(s_start_vertices.begin(), s_start_vertices.end());
75  std::vector< int64_t > end_vertices(s_end_vertices.begin(), s_end_vertices.end());
76  if (directed) {
77  log << "Working with directed Graph\n";
78  pgrouting::DirectedGraph digraph(gType);
79  digraph.graph_insert_data(data_edges, total_tuples);
80  pgr_dijkstra(digraph, paths, start_vertices, end_vertices, only_cost);
81  } else {
82  log << "Working with Undirected Graph\n";
83  pgrouting::UndirectedGraph undigraph(gType);
84  undigraph.graph_insert_data(data_edges, total_tuples);
85  pgr_dijkstra(undigraph, paths, start_vertices, end_vertices, only_cost);
86  }
87 
88 
89  size_t count(0);
90 
91  count = count_tuples(paths);
92 
93  if (count == 0) {
94  (*return_tuples) = NULL;
95  (*return_count) = 0;
96  log <<
97  "No paths found between Starting and any of the Ending vertices\n";
98  *err_msg = strdup(log.str().c_str());
99  return;
100  }
101 
102  (*return_tuples) = pgr_alloc(count, (*return_tuples));
103  log << "Converting a set of paths into the tuples\n";
104  (*return_count) = (collapse_paths(return_tuples, paths));
105 
106 
107 #ifndef DEBUG
108  *err_msg = strdup("OK");
109 #else
110  *err_msg = strdup(log.str().c_str());
111 #endif
112 
113  return;
114  } catch ( ... ) {
115  log << "Caught unknown exception!\n";
116  *err_msg = strdup(log.str().c_str());
117  return;
118  }
119 }
120 
121 
122 
123 
124 
void pgr_dijkstra(G &graph, Path &path, int64_t source, int64_t target, bool only_cost=false)
graphType
Definition: pgr_types.h:192
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:52
void do_pgr_many_to_many_dijkstra(pgr_edge_t *data_edges, size_t total_tuples, int64_t *start_vidsArr, size_t size_start_vidsArr, int64_t *end_vidsArr, size_t size_end_vidsArr, bool directed, bool only_cost, General_path_element_t **return_tuples, size_t *return_count, char **err_msg)
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.