PGROUTING  3.2
kruskal_driver.cpp File Reference
#include "drivers/spanningTree/kruskal_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_kruskal.hpp"
#include "spanningTree/details.hpp"
Include dependency graph for kruskal_driver.cpp:

Go to the source code of this file.

Functions

void do_pgr_kruskal (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_kruskal()

void do_pgr_kruskal ( 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 kruskal_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_edges(data_edges, total_edges);
82 
85 
86  if (suffix == "") {
87  results = kruskal.kruskal(undigraph);
88  } else if (suffix == "BFS") {
89  results = kruskal.kruskalBFS(undigraph, roots, max_depth);
90  } else if (suffix == "DFS") {
91  results = kruskal.kruskalDFS(undigraph, roots, max_depth);
92  } else if (suffix == "DD") {
93  results = kruskal.kruskalDD(undigraph, roots, distance);
94  } else {
95  err << "Unknown Kruskal function";
96  *err_msg = pgr_msg(err.str().c_str());
97  return;
98  }
99  }
100 
101  auto count = results.size();
102 
103  if (count == 0) {
104  (*return_tuples) = NULL;
105  (*return_count) = 0;
106  notice << "No spanning tree found";
107  return;
108  }
109 
110  (*return_tuples) = pgr_alloc(count, (*return_tuples));
111  for (size_t i = 0; i < count; i++) {
112  *((*return_tuples) + i) = results[i];
113  }
114  (*return_count) = count;
115 
116  pgassert(*err_msg == NULL);
117  *log_msg = log.str().empty()?
118  *log_msg :
119  pgr_msg(log.str().c_str());
120  *notice_msg = notice.str().empty()?
121  *notice_msg :
122  pgr_msg(notice.str().c_str());
123  } catch (AssertFailedException &except) {
124  (*return_tuples) = pgr_free(*return_tuples);
125  (*return_count) = 0;
126  err << except.what();
127  *err_msg = pgr_msg(err.str().c_str());
128  *log_msg = pgr_msg(log.str().c_str());
129  } catch (std::exception &except) {
130  (*return_tuples) = pgr_free(*return_tuples);
131  (*return_count) = 0;
132  err << except.what();
133  *err_msg = pgr_msg(err.str().c_str());
134  *log_msg = pgr_msg(log.str().c_str());
135  } catch(...) {
136  (*return_tuples) = pgr_free(*return_tuples);
137  (*return_count) = 0;
138  err << "Caught unknown exception!";
139  *err_msg = pgr_msg(err.str().c_str());
140  *log_msg = pgr_msg(log.str().c_str());
141  }
142 }

References pgrouting::details::get_no_edge_graph_result(), pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_edges(), pgassert, pgr_alloc(), 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
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
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
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_kruskal
Definition: pgr_kruskal.hpp:41
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139