PGROUTING  3.2
chinesePostman_driver.cpp File Reference
#include "drivers/chinese/chinesePostman_driver.h"
#include <sstream>
#include <deque>
#include <vector>
#include <set>
#include "chinese/pgr_chinesePostman.hpp"
#include "cpp_common/pgr_alloc.hpp"
#include "cpp_common/pgr_assert.h"
Include dependency graph for chinesePostman_driver.cpp:

Go to the source code of this file.

Functions

void do_pgr_directedChPP (pgr_edge_t *data_edges, size_t total_edges, 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_directedChPP()

void do_pgr_directedChPP ( pgr_edge_t data_edges,
size_t  total_edges,
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 44 of file chinesePostman_driver.cpp.

51  {
52  std::ostringstream log;
53  std::ostringstream err;
54  std::ostringstream notice;
55  try {
56  pgassert(!(*log_msg));
57  pgassert(!(*notice_msg));
58  pgassert(!(*err_msg));
59  pgassert(!(*return_tuples));
60  pgassert(*return_count == 0);
61  pgassert(total_edges != 0);
62 
64  data_edges, total_edges);
65 
66  double minCost;
67  minCost = digraph.DirectedChPP();
68 
69  std::vector<General_path_element_t> pathEdges;
70  if (only_cost) {
71  if (minCost >= 0.0) {
73  edge.seq = -1;
74  edge.node = edge.edge = -1;
75  edge.cost = edge.agg_cost = minCost;
76  pathEdges.push_back(edge);
77  }
78  } else {
79  pathEdges = digraph.GetPathEdges();
80  }
81 
82 
83  size_t count = pathEdges.size();
84 
85  if (count == 0) {
86  (*return_tuples) = NULL;
87  (*return_count) = 0;
88  notice <<
89  "No paths found";
90  *log_msg = pgr_msg(notice.str().c_str());
91  return;
92  }
93 
94 
95  (*return_tuples) = pgr_alloc(count, (*return_tuples));
96  for (size_t i = 0; i < count; i++) {
97  (*return_tuples)[i] = pathEdges[i];
98  }
99  *return_count = count;
100 
101  *log_msg = log.str().empty()?
102  *log_msg :
103  pgr_msg(log.str().c_str());
104  *notice_msg = notice.str().empty()?
105  *notice_msg :
106  pgr_msg(notice.str().c_str());
107  } catch (AssertFailedException &except) {
108  (*return_tuples) = pgr_free(*return_tuples);
109  (*return_count) = 0;
110  err << except.what();
111  *err_msg = pgr_msg(err.str().c_str());
112  *log_msg = pgr_msg(log.str().c_str());
113  } catch (std::exception &except) {
114  (*return_tuples) = pgr_free(*return_tuples);
115  (*return_count) = 0;
116  err << except.what();
117  *err_msg = pgr_msg(err.str().c_str());
118  *log_msg = pgr_msg(log.str().c_str());
119  } catch(...) {
120  (*return_tuples) = pgr_free(*return_tuples);
121  (*return_count) = 0;
122  err << "Caught unknown exception!";
123  *err_msg = pgr_msg(err.str().c_str());
124  *log_msg = pgr_msg(log.str().c_str());
125  }
126 }

References edge::cost, pgrouting::graph::PgrDirectedChPPGraph::DirectedChPP(), pgrouting::graph::PgrDirectedChPPGraph::GetPathEdges(), pgassert, pgr_alloc(), pgr_free(), pgr_msg(), and AssertFailedException::what().

Referenced by process().

pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
edge::cost
float8 cost
Definition: trsp.h:45
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
edge
Definition: trsp.h:41
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
General_path_element_t
Definition: general_path_element_t.h:37
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
pgrouting::graph::PgrDirectedChPPGraph
Definition: pgr_chinesePostman.hpp:49
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139