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_one_dijkstra_driver.cpp
Go to the documentation of this file.
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 #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 "./pgr_dijkstra.hpp"
40 
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 BIGINT,
48 // end_vid BIGINT,
49 // directed BOOLEAN default true,
50 
51 void
53  pgr_edge_t *data_edges,
54  size_t total_tuples,
55  int64_t start_vid,
56  int64_t end_vid,
57  bool directed,
58  bool only_cost,
59  General_path_element_t **return_tuples,
60  size_t *return_count,
61  char ** err_msg) {
62  std::ostringstream log;
63  try {
64  graphType gType = directed? DIRECTED: UNDIRECTED;
65 
66  Path path;
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, path, start_vid, end_vid, 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, path, start_vid, end_vid, only_cost);
78  }
79 
80  size_t count(0);
81 
82  count = path.size();
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  size_t sequence = 0;
95  path.generate_postgres_data(return_tuples, sequence);
96  (*return_count) = sequence;
97 
98 #ifndef DEBUG
99  *err_msg = strdup("OK");
100 #else
101  *err_msg = strdup(log.str().c_str());
102 #endif
103 
104  return;
105  } catch ( ... ) {
106  log << "Caught unknown exception!\n";
107  *err_msg = strdup(log.str().c_str());
108  return;
109  }
110 }
111 
112 
113 
114 
115 
void do_pgr_one_to_one_dijkstra(pgr_edge_t *data_edges, size_t total_tuples, int64_t start_vid, int64_t end_vid, bool directed, bool only_cost, General_path_element_t **return_tuples, size_t *return_count, char **err_msg)
void generate_postgres_data(General_path_element_t **postgres_data, size_t &sequence) const
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
path_element_t * path
Definition: BDATester.cpp:49
char * err_msg
Definition: BDATester.cpp:50
size_t size() const
void graph_insert_data(const T *edges, int64_t count)
Inserts count edges of type T into the graph.