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
one_to_many_dijkstra_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: one_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(sql text, start_vid bigint, end_vids anyarray, directed boolean default true,
46 void
48  pgr_edge_t *data_edges,
49  size_t total_tuples,
50  int64_t start_vid,
51  int64_t *end_vidsArr,
52  size_t size_end_vidsArr,
53  bool directed,
54  bool only_cost,
55  General_path_element_t **return_tuples,
56  size_t *return_count,
57  char ** err_msg) {
58  std::ostringstream log;
59  try {
60  graphType gType = directed? DIRECTED: UNDIRECTED;
61 
62  std::deque< Path >paths;
63  log << "Inserting vertices into a c++ vector structure\n";
64  std::set< int64_t > s_end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr);
65  std::vector< int64_t > end_vertices(s_end_vertices.begin(), s_end_vertices.end());
66 
67 
68  if (directed) {
69  log << "Working with directed Graph\n";
70  pgrouting::DirectedGraph digraph(gType);
71  digraph.graph_insert_data(data_edges, total_tuples);
72  pgr_dijkstra(digraph, paths, start_vid, end_vertices, only_cost);
73  } else {
74  log << "Working with Undirected Graph\n";
75  pgrouting::UndirectedGraph undigraph(gType);
76  undigraph.graph_insert_data(data_edges, total_tuples);
77  pgr_dijkstra(undigraph, paths, start_vid, end_vertices, only_cost);
78  }
79 
80  size_t count(0);
81  count = count_tuples(paths);
82 
83 
84  if (count == 0) {
85  (*return_tuples) = NULL;
86  (*return_count) = 0;
87  log <<
88  "No paths found between Starting and any of the Ending vertices\n";
89  *err_msg = strdup(log.str().c_str());
90  return;
91  }
92 
93  (*return_tuples) = pgr_alloc(count, (*return_tuples));
94  log << "Converting a set of paths into the tuples\n";
95  (*return_count) = (collapse_paths(return_tuples, paths));
96 
97 #ifndef DEBUG
98  *err_msg = strdup("OK");
99 #else
100  *err_msg = strdup(log.str().c_str());
101 #endif
102 
103  return;
104  } catch ( ... ) {
105  log << "Caught unknown exception!\n";
106  *err_msg = strdup("Caught unknown exception!\n");
107  return;
108  }
109 }
110 
111 
112 
113 
114 
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
char * err_msg
Definition: BDATester.cpp:50
void do_pgr_one_to_many_dijkstra(pgr_edge_t *data_edges, size_t total_tuples, int64_t start_vid, 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)
void graph_insert_data(const T *edges, int64_t count)
Inserts count edges of type T into the graph.