PGROUTING  3.2
prim_driver.cpp File Reference
#include "drivers/spanningTree/prim_driver.h"
#include <sstream>
#include <deque>
#include <vector>
#include <string>
#include "cpp_common/pgr_alloc.hpp"
#include "cpp_common/pgr_assert.h"
#include "spanningTree/pgr_prim.hpp"
#include "spanningTree/details.hpp"
Include dependency graph for prim_driver.cpp:

Go to the source code of this file.

Functions

void do_pgr_prim (pgr_edge_t *data_edges, size_t total_edges, int64_t *rootsArr, size_t size_rootsArr, char *fn_suffix, int64_t max_depth, double distance, pgr_mst_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 

Function Documentation

◆ do_pgr_prim()

void do_pgr_prim ( pgr_edge_t data_edges,
size_t  total_edges,
int64_t *  rootsArr,
size_t  size_rootsArr,
char *  fn_suffix,
int64_t  max_depth,
double  distance,
pgr_mst_rt **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 44 of file prim_driver.cpp.

61  {
62  std::ostringstream log;
63  std::ostringstream err;
64  std::ostringstream notice;
65  try {
66  pgassert(!(*log_msg));
67  pgassert(!(*notice_msg));
68  pgassert(!(*err_msg));
69  pgassert(!(*return_tuples));
70  pgassert(*return_count == 0);
71 
72  std::vector<int64_t> roots(rootsArr, rootsArr + size_rootsArr);
73  std::string suffix(fn_suffix);
74 
75  std::vector<pgr_mst_rt> results;
76 
77  if (total_edges == 0) {
79  } else {
81  undigraph.insert_min_edges_no_parallel(data_edges, total_edges);
83  if (suffix == "") {
84  results = prim.prim(undigraph);
85  } else if (suffix == "BFS") {
86  results = prim.primBFS(undigraph, roots, max_depth);
87  } else if (suffix == "DFS") {
88  results = prim.primDFS(undigraph, roots, max_depth);
89  } else if (suffix == "DD") {
90  results = prim.primDD(undigraph, roots, distance);
91  } else {
92  err << "Unknown Prim function";
93  *err_msg = pgr_msg(err.str().c_str());
94  return;
95  }
96  }
97 
98  auto count = results.size();
99 
100  if (count == 0) {
101  (*return_tuples) = NULL;
102  (*return_count) = 0;
103  notice << "No spanning tree found";
104  return;
105  }
106 
107  (*return_tuples) = pgr_alloc(count, (*return_tuples));
108  for (size_t i = 0; i < count; i++) {
109  *((*return_tuples) + i) = results[i];
110  }
111  (*return_count) = count;
112 
113  pgassert(*err_msg == NULL);
114  *log_msg = log.str().empty()?
115  *log_msg :
116  pgr_msg(log.str().c_str());
117  *notice_msg = notice.str().empty()?
118  *notice_msg :
119  pgr_msg(notice.str().c_str());
120  } catch (AssertFailedException &except) {
121  (*return_tuples) = pgr_free(*return_tuples);
122  (*return_count) = 0;
123  err << except.what();
124  *err_msg = pgr_msg(err.str().c_str());
125  *log_msg = pgr_msg(log.str().c_str());
126  } catch (std::exception &except) {
127  (*return_tuples) = pgr_free(*return_tuples);
128  (*return_count) = 0;
129  err << except.what();
130  *err_msg = pgr_msg(err.str().c_str());
131  *log_msg = pgr_msg(log.str().c_str());
132  } catch(...) {
133  (*return_tuples) = pgr_free(*return_tuples);
134  (*return_count) = 0;
135  err << "Caught unknown exception!";
136  *err_msg = pgr_msg(err.str().c_str());
137  *log_msg = pgr_msg(log.str().c_str());
138  }
139 }

References pgrouting::details::get_no_edge_graph_result(), pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_min_edges_no_parallel(), pgassert, pgr_alloc(), pgr_free(), pgr_msg(), pgrouting::functions::Pgr_prim< G >::prim(), pgrouting::functions::Pgr_prim< G >::primBFS(), pgrouting::functions::Pgr_prim< G >::primDD(), pgrouting::functions::Pgr_prim< G >::primDFS(), 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
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
pgrouting::functions::Pgr_prim::prim
std::vector< pgr_mst_rt > prim(G &graph)
Definition: pgr_prim.hpp:165
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
pgrouting::functions::Pgr_prim::primBFS
std::vector< pgr_mst_rt > primBFS(G &graph, std::vector< int64_t > roots, int64_t max_depth)
Definition: pgr_prim.hpp:172
pgrouting::functions::Pgr_prim::primDD
std::vector< pgr_mst_rt > primDD(G &graph, std::vector< int64_t > roots, double distance)
Definition: pgr_prim.hpp:190
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
pgrouting::details::get_no_edge_graph_result
std::vector< pgr_mst_rt > get_no_edge_graph_result(std::vector< int64_t > vids)
Definition: details.cpp:45
pgrouting::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
pgrouting::functions::Pgr_prim
Definition: pgr_prim.hpp:47
pgrouting::functions::Pgr_prim::primDFS
std::vector< pgr_mst_rt > primDFS(G &graph, std::vector< int64_t > roots, int64_t max_depth)
Definition: pgr_prim.hpp:181
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139