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_one_dijkstra_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: many_to_one_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 Copyright (c) 2015 pgRouting developers
13 
14 ------
15 
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version.
20 
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25 
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 
30 ********************************************************************PGR-GNU*/
31 
32 #if defined(__MINGW32__) || defined(_MSC_VER)
33 #include <winsock2.h>
34 #include <windows.h>
35 #endif
36 
37 #include <sstream>
38 #include <deque>
39 #include <vector>
40 #include <set>
41 #include "./pgr_dijkstra.hpp"
43 
44 #include "../../common/src/pgr_alloc.hpp"
45 #include "./../../common/src/pgr_types.h"
46 
47 // CREATE OR REPLACE FUNCTION pgr_dijkstra(
48 // sql text,
49 // start_vids anyarray,
50 // end_vid BIGINT,
51 // directed BOOLEAN default true,
52 void
54  pgr_edge_t *data_edges,
55  size_t total_tuples,
56  int64_t *start_vidsArr,
57  size_t size_start_vidsArr,
58  int64_t end_vid,
59  bool directed,
60  bool only_cost,
61  General_path_element_t **return_tuples,
62  size_t *return_count,
63  char ** err_msg) {
64  std::ostringstream log;
65  try {
66  graphType gType = directed? DIRECTED: UNDIRECTED;
67 
68  std::deque< Path >paths;
69  log << "Inserting vertices into a c++ vector structure\n";
70  std::set< int64_t > s_start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr);
71  std::vector< int64_t > start_vertices(s_start_vertices.begin(), s_start_vertices.end());
72 
73  if (directed) {
74  log << "Working with directed Graph\n";
75  pgrouting::DirectedGraph digraph(gType);
76  digraph.graph_insert_data(data_edges, total_tuples);
77  pgr_dijkstra(digraph, paths, start_vertices, end_vid, only_cost);
78  } else {
79  log << "Working with Undirected Graph\n";
80  pgrouting::UndirectedGraph undigraph(gType);
81  undigraph.graph_insert_data(data_edges, total_tuples);
82  pgr_dijkstra(undigraph, paths, start_vertices, end_vid, only_cost);
83  }
84 
85 
86  size_t count(0);
87  count = count_tuples(paths);
88 
89 
90  if (count == 0) {
91  (*return_tuples) = NULL;
92  (*return_count) = 0;
93  log <<
94  "No paths found between Starting and any of the Ending vertices\n";
95  *err_msg = strdup(log.str().c_str());
96  return;
97  }
98 
99  (*return_tuples) = pgr_alloc(count, (*return_tuples));
100  log << "Converting a set of paths into the tuples\n";
101  (*return_count) = (collapse_paths(return_tuples, paths));
102 
103 
104 #ifndef DEBUG
105  *err_msg = strdup("OK");
106 #else
107  *err_msg = strdup(log.str().c_str());
108 #endif
109 
110  return;
111  } catch ( ... ) {
112  log << "Caught unknown exception!\n";
113  *err_msg = strdup(log.str().c_str());
114  return;
115  }
116 }
117 
118 
119 
120 
121 
void do_pgr_many_to_one_dijkstra(pgr_edge_t *data_edges, size_t total_tuples, int64_t *start_vidsArr, size_t size_start_vidsArr, int64_t end_vid, bool directed, bool only_cost, General_path_element_t **return_tuples, size_t *return_count, char **err_msg)
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 graph_insert_data(const T *edges, int64_t count)
Inserts count edges of type T into the graph.