PGROUTING  3.2
stoerWagner_driver.h File Reference
#include <stddef.h>
#include "c_types/pgr_edge_t.h"
#include "c_types/pgr_stoerWagner_t.h"
Include dependency graph for stoerWagner_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_stoerWagner (pgr_edge_t *data_edges, size_t total_edges, pgr_stoerWagner_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 

Function Documentation

◆ do_pgr_stoerWagner()

void do_pgr_stoerWagner ( pgr_edge_t data_edges,
size_t  total_edges,
pgr_stoerWagner_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 51 of file stoerWagner_driver.cpp.

58  {
59  std::ostringstream log;
60  std::ostringstream err;
61  std::ostringstream notice;
62  try {
63  pgassert(!(*log_msg));
64  pgassert(!(*notice_msg));
65  pgassert(!(*err_msg));
66  pgassert(!(*return_tuples));
67  pgassert(*return_count == 0);
68  pgassert(total_edges != 0);
69 
70  graphType gType = UNDIRECTED;
71 
72  std::vector<pgr_stoerWagner_t> results;
73 
74  log << "Working with Undirected Graph\n";
75 
76  pgrouting::UndirectedGraph undigraph(gType);
77  undigraph.insert_edges(data_edges, total_edges);
78  results = pgr_stoerWagner(
79  undigraph);
80 
81  auto count = results.size();
82 
83  if (count == 0) {
84  (*return_tuples) = NULL;
85  (*return_count) = 0;
86  notice <<
87  "No paths found";
88  return;
89  }
90 
91  (*return_tuples) = pgr_alloc(count, (*return_tuples));
92  for (size_t i = 0; i < count; i++) {
93  *((*return_tuples) + i) = results[i];
94  }
95  (*return_count) = count;
96 
97  pgassert(*err_msg == NULL);
98  *log_msg = log.str().empty()?
99  *log_msg :
100  pgr_msg(log.str().c_str());
101  *notice_msg = notice.str().empty()?
102  *notice_msg :
103  pgr_msg(notice.str().c_str());
104  } catch (AssertFailedException &except) {
105  (*return_tuples) = pgr_free(*return_tuples);
106  (*return_count) = 0;
107  err << except.what();
108  *err_msg = pgr_msg(err.str().c_str());
109  *log_msg = pgr_msg(log.str().c_str());
110  } catch (std::exception &except) {
111  (*return_tuples) = pgr_free(*return_tuples);
112  (*return_count) = 0;
113  err << except.what();
114  *err_msg = pgr_msg(err.str().c_str());
115  *log_msg = pgr_msg(log.str().c_str());
116  } catch(...) {
117  (*return_tuples) = pgr_free(*return_tuples);
118  (*return_count) = 0;
119  err << "Caught unknown exception!";
120  *err_msg = pgr_msg(err.str().c_str());
121  *log_msg = pgr_msg(log.str().c_str());
122  }
123 }

References pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_edges(), pgassert, pgr_alloc(), pgr_free(), pgr_msg(), pgr_stoerWagner(), 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
graphType
graphType
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_stoerWagner
static std::vector< pgr_stoerWagner_t > pgr_stoerWagner(G &graph)
Definition: stoerWagner_driver.cpp:43
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139