pgRouting  2.2
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide geospatial routing functionality.
 All Classes Functions Variables Pages
one_to_many_dijkstra_driver.cpp
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 #ifdef __MINGW32__
31 #include <winsock2.h>
32 #include <windows.h>
33 #endif
34 
35 
36 #include <sstream>
37 #include <deque>
38 #include <vector>
39 #include "./pgr_dijkstra.hpp"
40 #include "./one_to_many_dijkstra_driver.h"
41 
42 // #define DEBUG
43 #include "../../common/src/memory_func.hpp"
44 extern "C" {
45 #include "./../../common/src/pgr_types.h"
46 }
47 
48 // CREATE OR REPLACE FUNCTION pgr_dijkstra(sql text, start_vid bigint, end_vids anyarray, directed boolean default true,
49 void
50 do_pgr_one_to_many_dijkstra(
51  pgr_edge_t *data_edges,
52  size_t total_tuples,
53  int64_t start_vid,
54  int64_t *end_vidsArr,
55  size_t size_end_vidsArr,
56  bool directed,
57  bool only_cost,
58  General_path_element_t **return_tuples,
59  size_t *return_count,
60  char ** err_msg) {
61  std::ostringstream log;
62  try {
63  graphType gType = directed? DIRECTED: UNDIRECTED;
64  const auto initial_size = total_tuples;
65 
66  std::deque< Path >paths;
67  log << "Inserting vertices into a c++ vector structure\n";
68  std::set< int64_t > s_end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr);
69  std::vector< int64_t > end_vertices(s_end_vertices.begin(), s_end_vertices.end());
70 
71 
72  if (directed) {
73  log << "Working with directed Graph\n";
74  Pgr_base_graph< DirectedGraph > digraph(gType, initial_size);
75  digraph.graph_insert_data(data_edges, total_tuples);
76  pgr_dijkstra(digraph, paths, start_vid, end_vertices, only_cost);
77  } else {
78  log << "Working with Undirected Graph\n";
79  Pgr_base_graph< UndirectedGraph > undigraph(gType, initial_size);
80  undigraph.graph_insert_data(data_edges, total_tuples);
81  pgr_dijkstra(undigraph, paths, start_vid, end_vertices, only_cost);
82  }
83 
84  size_t count(0);
85  count = count_tuples(paths);
86 
87 
88  if (count == 0) {
89  (*return_tuples) = NULL;
90  (*return_count) = 0;
91  log <<
92  "No paths found between Starting and any of the Ending vertices\n";
93  *err_msg = strdup(log.str().c_str());
94  return;
95  }
96 
97  (*return_tuples) = get_memory(count, (*return_tuples));
98  log << "Converting a set of paths into the tuples\n";
99  (*return_count) = (collapse_paths(return_tuples, paths));
100 
101 #ifndef DEBUG
102  *err_msg = strdup("OK");
103 #else
104  *err_msg = strdup(log.str().c_str());
105 #endif
106 
107  return;
108  } catch ( ... ) {
109  log << "Caught unknown expection!\n";
110  *err_msg = strdup("Caught unknown expection!\n");
111  return;
112  }
113 }
114 
115 
116 
117 
118