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

Go to the source code of this file.

Functions

void do_pgr_randomSpanningTree (pgr_edge_t *data_edges, size_t total_edges, int64_t root_vertex, bool directed, pgr_randomSpanningTree_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 
template<class G >
static std::vector< pgr_randomSpanningTree_tpgr_randomSpanningTree (G &graph, int64_t root_vertex)
 

Function Documentation

◆ do_pgr_randomSpanningTree()

void do_pgr_randomSpanningTree ( pgr_edge_t data_edges,
size_t  total_edges,
int64_t  root_vertex,
bool  directed,
pgr_randomSpanningTree_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 52 of file randomSpanningTree_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  pgassert(total_edges != 0);
72 
73  graphType gType = directed? DIRECTED: UNDIRECTED;
74 
75  std::vector<pgr_randomSpanningTree_t> results;
76 
77  if (directed) {
78  log << "Working with directed Graph\n";
79  pgrouting::DirectedGraph digraph(gType);
80  digraph.insert_edges(data_edges, total_edges);
81  results = pgr_randomSpanningTree(
82  digraph,
83  root_vertex);
84  } else {
85  log << "Working with Undirected Graph\n";
86  pgrouting::UndirectedGraph undigraph(gType);
87  undigraph.insert_edges(data_edges, total_edges);
88  results = pgr_randomSpanningTree(
89  undigraph,
90  root_vertex);
91  }
92 
93  auto count = results.size();
94 
95  if (count == 0) {
96  (*return_tuples) = NULL;
97  (*return_count) = 0;
98  notice <<
99  "No paths found";
100  return;
101  }
102 
103  (*return_tuples) = pgr_alloc(count, (*return_tuples));
104  for (size_t i = 0; i < count; i++) {
105  *((*return_tuples) + i) = results[i];
106  }
107  (*return_count) = count;
108 
109  pgassert(*err_msg == NULL);
110  *log_msg = log.str().empty()?
111  *log_msg :
112  pgr_msg(log.str().c_str());
113  *notice_msg = notice.str().empty()?
114  *notice_msg :
115  pgr_msg(notice.str().c_str());
116  } catch (AssertFailedException &except) {
117  (*return_tuples) = pgr_free(*return_tuples);
118  (*return_count) = 0;
119  err << except.what();
120  *err_msg = pgr_msg(err.str().c_str());
121  *log_msg = pgr_msg(log.str().c_str());
122  } catch (std::exception &except) {
123  (*return_tuples) = pgr_free(*return_tuples);
124  (*return_count) = 0;
125  err << except.what();
126  *err_msg = pgr_msg(err.str().c_str());
127  *log_msg = pgr_msg(log.str().c_str());
128  } catch(...) {
129  (*return_tuples) = pgr_free(*return_tuples);
130  (*return_count) = 0;
131  err << "Caught unknown exception!";
132  *err_msg = pgr_msg(err.str().c_str());
133  *log_msg = pgr_msg(log.str().c_str());
134  }
135 }

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

Referenced by process().

◆ pgr_randomSpanningTree()

template<class G >
static std::vector<pgr_randomSpanningTree_t> pgr_randomSpanningTree ( G &  graph,
int64_t  root_vertex 
)
static

Definition at line 43 of file randomSpanningTree_driver.cpp.

45  {
46  Pgr_randomSpanningTree< G > fn_randomSpanningTree;
47  return fn_randomSpanningTree.randomSpanningTree(graph, root_vertex);
48 }

References Pgr_randomSpanningTree< G >::randomSpanningTree().

Referenced by do_pgr_randomSpanningTree().

pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
Pgr_randomSpanningTree::randomSpanningTree
std::vector< pgr_randomSpanningTree_t > randomSpanningTree(G &graph, int64_t root_vertex)
Definition: pgr_randomSpanningTree.hpp:137
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
pgr_randomSpanningTree
static std::vector< pgr_randomSpanningTree_t > pgr_randomSpanningTree(G &graph, int64_t root_vertex)
Definition: randomSpanningTree_driver.cpp:43
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
Pgr_randomSpanningTree
Definition: pgr_randomSpanningTree.hpp:47
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
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139