PGROUTING  3.2
bellman_ford_neg_driver.h File Reference
#include <stddef.h>
#include "c_types/pgr_edge_t.h"
#include "c_types/pgr_combination_t.h"
#include "c_types/general_path_element_t.h"
Include dependency graph for bellman_ford_neg_driver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void do_pgr_bellman_ford_neg (pgr_edge_t *positive_edges, size_t total_positive_edges, pgr_edge_t *negative_edges, size_t total_negative_edges, pgr_combination_t *combinations, size_t total_combinations, int64_t *start_vidsArr, size_t size_start_vidsArr, int64_t *end_vidsArr, size_t size_end_vidsArr, bool directed, bool only_cost, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 

Function Documentation

◆ do_pgr_bellman_ford_neg()

void do_pgr_bellman_ford_neg ( pgr_edge_t positive_edges,
size_t  total_positive_edges,
pgr_edge_t negative_edges,
size_t  total_negative_edges,
pgr_combination_t combinations,
size_t  total_combinations,
int64_t *  start_vidsArr,
size_t  size_start_vidsArr,
int64_t *  end_vidsArr,
size_t  size_end_vidsArr,
bool  directed,
bool  only_cost,
General_path_element_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 80 of file bellman_ford_neg_driver.cpp.

98  {
99  std::ostringstream log;
100  std::ostringstream err;
101  std::ostringstream notice;
102  size_t total_edges = total_positive_edges + total_negative_edges;
103  try {
104  pgassert(!(*log_msg));
105  pgassert(!(*notice_msg));
106  pgassert(!(*err_msg));
107  pgassert(!(*return_tuples));
108  pgassert(*return_count == 0);
109  pgassert(total_edges != 0);
110  pgassert(total_positive_edges || total_negative_edges);
111  pgassert((start_vidsArr && end_vidsArr) || combinations);
112  pgassert((size_start_vidsArr && size_end_vidsArr) || total_combinations);
113 
114  graphType gType = directed? DIRECTED: UNDIRECTED;
115 
116  log << "Inserting vertices into a c++ vector structure";
117 
118  std::vector<int64_t>
119  start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr);
120  std::vector< int64_t >
121  end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr);
122  std::vector< pgr_combination_t >
123  combinations_vector(combinations, combinations + total_combinations);
124 
125  std::deque< Path >paths;
126  std::string logstr;
127  if (directed) {
128  log << "Working with directed Graph\n";
129  pgrouting::DirectedGraph digraph(gType);
130  digraph.insert_edges(positive_edges, total_positive_edges);
131  digraph.insert_negative_edges(negative_edges, total_negative_edges);
132  log << digraph;
133  paths = pgr_bellman_ford(digraph,
134  combinations_vector,
135  start_vertices,
136  end_vertices,
137  logstr,
138  only_cost);
139  } else {
140  log << "Working with Undirected Graph\n";
141  pgrouting::UndirectedGraph undigraph(gType);
142  undigraph.insert_edges(positive_edges, total_positive_edges);
143  undigraph.insert_negative_edges(
144  negative_edges,
145  total_negative_edges);
146  log << undigraph;
147  paths = pgr_bellman_ford(
148  undigraph,
149  combinations_vector,
150  start_vertices,
151  end_vertices,
152  logstr,
153  only_cost);
154  }
155  log<< logstr;
156  size_t count(0);
157  count = count_tuples(paths);
158 
159  if (count == 0) {
160  (*return_tuples) = NULL;
161  (*return_count) = 0;
162  notice <<
163  "No paths found";
164  *log_msg = pgr_msg(notice.str().c_str());
165  return;
166  }
167 
168  (*return_tuples) = pgr_alloc(count, (*return_tuples));
169  log << "\nConverting a set of paths into the tuples";
170  (*return_count) = (collapse_paths(return_tuples, paths));
171 
172  *log_msg = log.str().empty()?
173  *log_msg :
174  pgr_msg(log.str().c_str());
175  *notice_msg = notice.str().empty()?
176  *notice_msg :
177  pgr_msg(notice.str().c_str());
178  } catch (AssertFailedException &except) {
179  (*return_tuples) = pgr_free(*return_tuples);
180  (*return_count) = 0;
181  err << except.what();
182  *err_msg = pgr_msg(err.str().c_str());
183  *log_msg = pgr_msg(log.str().c_str());
184  } catch (std::exception &except) {
185  (*return_tuples) = pgr_free(*return_tuples);
186  (*return_count) = 0;
187  err << except.what();
188  *err_msg = pgr_msg(err.str().c_str());
189  *log_msg = pgr_msg(log.str().c_str());
190  } catch(...) {
191  (*return_tuples) = pgr_free(*return_tuples);
192  (*return_count) = 0;
193  err << "Caught unknown exception!";
194  *err_msg = pgr_msg(err.str().c_str());
195  *log_msg = pgr_msg(log.str().c_str());
196  }
197 }

References collapse_paths(), count_tuples(), DIRECTED, pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_edges(), pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_negative_edges(), pgassert, pgr_alloc(), pgr_bellman_ford(), pgr_free(), pgr_msg(), UNDIRECTED, and AssertFailedException::what().

Referenced by process().

pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
count_tuples
size_t count_tuples(const std::deque< Path > &paths)
Definition: basePath_SSEC.cpp:387
pgr_msg
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
AssertFailedException::what
virtual const char * what() const
Definition: pgr_assert.cpp:67
collapse_paths
size_t collapse_paths(General_path_element_t **ret_path, const std::deque< Path > &paths)
Definition: basePath_SSEC.cpp:310
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
graphType
graphType
Definition: graph_enum.h:30
DIRECTED
@ DIRECTED
Definition: graph_enum.h:30
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
pgrouting::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
pgr_bellman_ford
std::deque< Path > pgr_bellman_ford(G &graph, std::vector< pgr_combination_t > &combinations, std::vector< int64_t > sources, std::vector< int64_t > targets, std::string &log, bool only_cost=false)
Definition: bellman_ford_neg_driver.cpp:54
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139