pgRouting  2.2
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide geospatial routing functionality.
 All Classes Functions Variables Pages
one_to_one_dijkstra_driver.cpp
1 /*PGR-GNU*****************************************************************
2 File: one_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 ------
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_one_dijkstra_driver.h"
41 
42 //#define DEBUG
43 
44 #include "../../common/src/memory_func.hpp"
45 extern "C" {
46 #include "./../../common/src/pgr_types.h"
47 }
48 
49 // CREATE OR REPLACE FUNCTION pgr_dijkstra(
50 // sql text,
51 // start_vids BIGINT,
52 // end_vid BIGINT,
53 // directed BOOLEAN default true,
54 
55 void
56 do_pgr_one_to_one_dijkstra(
57  pgr_edge_t *data_edges,
58  size_t total_tuples,
59  int64_t start_vid,
60  int64_t end_vid,
61  bool directed,
62  bool only_cost,
63  General_path_element_t **return_tuples,
64  size_t *return_count,
65  char ** err_msg) {
66  std::ostringstream log;
67  try {
68  graphType gType = directed? DIRECTED: UNDIRECTED;
69  const auto initial_size = total_tuples;
70 
71  Path path;
72 
73  if (directed) {
74  log << "Working with directed Graph\n";
75  Pgr_base_graph< DirectedGraph > digraph(gType, initial_size);
76  digraph.graph_insert_data(data_edges, total_tuples);
77  pgr_dijkstra(digraph, path, start_vid, end_vid, only_cost);
78  } else {
79  log << "Working with Undirected Graph\n";
80  Pgr_base_graph< UndirectedGraph > undigraph(gType, initial_size);
81  undigraph.graph_insert_data(data_edges, total_tuples);
82  pgr_dijkstra(undigraph, path, start_vid, end_vid, only_cost);
83  }
84 
85  size_t count(0);
86 
87  count = path.size();
88 
89  if (count == 0) {
90  (*return_tuples) = NULL;
91  (*return_count) = 0;
92  log <<
93  "No paths found between Starting and any of the Ending vertices\n";
94  *err_msg = strdup(log.str().c_str());
95  return;
96  }
97 
98  (*return_tuples) = get_memory(count, (*return_tuples));
99  size_t sequence = 0;
100  path.generate_postgres_data(return_tuples, sequence);
101  (*return_count) = sequence;
102 
103 #ifndef DEBUG
104  *err_msg = strdup("OK");
105 #else
106  *err_msg = strdup(log.str().c_str());
107 #endif
108 
109  return;
110  } catch ( ... ) {
111  log << "Caught unknown expection!\n";
112  *err_msg = strdup(log.str().c_str());
113  return;
114  }
115 }
116 
117 
118 
119 
120