PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
astar_driver.cpp File Reference
#include "drivers/astar/astar_driver.h"
#include <sstream>
#include <deque>
#include <algorithm>
#include <vector>
#include "astar/pgr_astar.hpp"
#include "cpp_common/pgr_alloc.hpp"
#include "cpp_common/pgr_assert.h"
Include dependency graph for astar_driver.cpp:

Go to the source code of this file.

Functions

void check_parameters (int heuristic, double factor, double epsilon)
 
void do_pgr_astarManyToMany (Pgr_edge_xy_t *edges, size_t total_edges, int64_t *start_vidsArr, size_t size_start_vidsArr, int64_t *end_vidsArr, size_t size_end_vidsArr, bool directed, int heuristic, double factor, double epsilon, bool only_cost, bool normal, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 
template<class G >
std::deque< Pathpgr_astar (G &graph, std::vector< int64_t > sources, std::vector< int64_t > targets, int heuristic, double factor, double epsilon, bool only_cost, bool normal)
 

Function Documentation

void check_parameters ( int  heuristic,
double  factor,
double  epsilon 
)

Definition at line 44 of file astar_driver.cpp.

Referenced by process().

47  {
48  if (heuristic > 5 || heuristic < 0) {
49  ereport(ERROR,
50  (errmsg("Unknown heuristic"),
51  errhint("Valid values: 0~5")));
52  }
53  if (factor <= 0) {
54  ereport(ERROR,
55  (errmsg("Factor value out of range"),
56  errhint("Valid values: positive non zero")));
57  }
58  if (epsilon < 1) {
59  ereport(ERROR,
60  (errmsg("Epsilon value out of range"),
61  errhint("Valid values: 1 or greater than 1")));
62  }
63 }

Here is the caller graph for this function:

void do_pgr_astarManyToMany ( Pgr_edge_xy_t edges,
size_t  total_edges,
int64_t *  start_vidsArr,
size_t  size_start_vidsArr,
int64_t *  end_vidsArr,
size_t  size_end_vidsArr,
bool  directed,
int  heuristic,
double  factor,
double  epsilon,
bool  only_cost,
bool  normal,
General_path_element_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 105 of file astar_driver.cpp.

References collapse_paths(), count_tuples(), DIRECTED, pgrouting::extract_vertices(), pgrouting::graph::Pgr_base_graph< G, Vertex, Edge >::insert_edges(), pgassert, pgr_alloc(), pgr_astar(), pgr_free(), pgr_msg(), UNDIRECTED, and AssertFailedException::what().

Referenced by process().

119  {
120  std::ostringstream log;
121  std::ostringstream notice;
122  std::ostringstream err;
123  try {
124  pgassert(!(*log_msg));
125  pgassert(!(*err_msg));
126  pgassert(!(*return_tuples));
127  pgassert(*return_count == 0);
128  pgassert(total_edges != 0);
129 
130 
131  log << "Inserting target vertices into a c++ vector structure\n";
132  std::vector< int64_t > end_vids(
133  end_vidsArr,
134  end_vidsArr + size_end_vidsArr);
135  std::vector< int64_t > start_vids(
136  start_vidsArr,
137  start_vidsArr + size_start_vidsArr);
138 
139  graphType gType = directed? DIRECTED: UNDIRECTED;
140 
141  std::deque< Path >paths;
142  if (directed) {
143  log << "Working with directed Graph\n";
145  pgrouting::extract_vertices(edges, total_edges),
146  gType);
147  digraph.insert_edges(edges, total_edges);
148  paths = pgr_astar(digraph, start_vids, end_vids,
149  heuristic, factor, epsilon, only_cost, normal);
150  } else {
151  log << "Working with Undirected Graph\n";
153  pgrouting::extract_vertices(edges, total_edges),
154  gType);
155  undigraph.insert_edges(edges, total_edges);
156  paths = pgr_astar(undigraph, start_vids, end_vids,
157  heuristic, factor, epsilon, only_cost, normal);
158  }
159 
160  size_t count(0);
161  count = count_tuples(paths);
162 
163 
164  if (count == 0) {
165  (*return_tuples) = NULL;
166  (*return_count) = 0;
167  notice <<
168  "No paths found\n";
169  *log_msg = pgr_msg(notice.str().c_str());
170  return;
171  }
172 
173  (*return_tuples) = pgr_alloc(count, (*return_tuples));
174  log << "Converting a set of paths into the tuples\n";
175  (*return_count) = (collapse_paths(return_tuples, paths));
176 
177  *log_msg = log.str().empty()?
178  *log_msg :
179  pgr_msg(log.str().c_str());
180  *notice_msg = notice.str().empty()?
181  *notice_msg :
182  pgr_msg(notice.str().c_str());
183  } catch (AssertFailedException &except) {
184  (*return_tuples) = pgr_free(*return_tuples);
185  (*return_count) = 0;
186  err << except.what();
187  *err_msg = pgr_msg(err.str().c_str());
188  *log_msg = pgr_msg(log.str().c_str());
189  } catch (std::exception &except) {
190  (*return_tuples) = pgr_free(*return_tuples);
191  (*return_count) = 0;
192  err << except.what();
193  *err_msg = pgr_msg(err.str().c_str());
194  *log_msg = pgr_msg(log.str().c_str());
195  } catch(...) {
196  (*return_tuples) = pgr_free(*return_tuples);
197  (*return_count) = 0;
198  err << "Caught unknown exception!";
199  *err_msg = pgr_msg(err.str().c_str());
200  *log_msg = pgr_msg(log.str().c_str());
201  }
202 }
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
size_t collapse_paths(General_path_element_t **ret_path, const std::deque< Path > &paths)
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:75
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
std::deque< Path > pgr_astar(G &graph, std::vector< int64_t > sources, std::vector< int64_t > targets, int heuristic, double factor, double epsilon, bool only_cost, bool normal)
std::vector< Basic_vertex > extract_vertices(std::vector< Basic_vertex > vertices, const std::vector< pgr_edge_t > data_edges)
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:29
size_t count_tuples(const std::deque< Path > &paths)
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:64
virtual const char * what() const
Definition: pgr_assert.cpp:53
graphType
Definition: graph_enum.h:30

Here is the call graph for this function:

Here is the caller graph for this function:

template<class G >
std::deque<Path> pgr_astar ( G &  graph,
std::vector< int64_t >  sources,
std::vector< int64_t >  targets,
int  heuristic,
double  factor,
double  epsilon,
bool  only_cost,
bool  normal 
)

Definition at line 67 of file astar_driver.cpp.

References pgrouting::algorithms::Pgr_astar< G >::astar(), and Path::reverse().

Referenced by do_pgr_astarManyToMany().

75  {
76  std::sort(sources.begin(), sources.end());
77  sources.erase(
78  std::unique(sources.begin(), sources.end()),
79  sources.end());
80 
81  std::sort(targets.begin(), targets.end());
82  targets.erase(
83  std::unique(targets.begin(), targets.end()),
84  targets.end());
85 
87  auto paths = fn_astar.astar(graph, sources, targets,
88  heuristic, factor, epsilon, only_cost);
89 
90  if (!normal) {
91  for (auto &path : paths) {
92  path.reverse();
93  }
94  }
95  return paths;
96 }
Path astar(G &graph, int64_t start_vertex, int64_t end_vertex, int heuristic, double factor, double epsilon, bool only_cost)
one to one astar 1 to 1
Definition: pgr_astar.hpp:67
void reverse()

Here is the call graph for this function:

Here is the caller graph for this function: