PGROUTING  3.2
lineGraph_driver.cpp File Reference
#include "drivers/lineGraph/lineGraph_driver.h"
#include <sstream>
#include <deque>
#include <vector>
#include <utility>
#include "dijkstra/pgr_dijkstra.hpp"
#include "cpp_common/pgr_alloc.hpp"
#include "cpp_common/pgr_assert.h"
#include "lineGraph/pgr_lineGraph.hpp"
#include "cpp_common/linear_directed_graph.h"
Include dependency graph for lineGraph_driver.cpp:

Go to the source code of this file.

Functions

void do_pgr_lineGraph (pgr_edge_t *data_edges, size_t total_edges, bool directed, Line_graph_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 
void get_postgres_result (std::vector< Line_graph_rt > edge_result, Line_graph_rt **return_tuples, size_t &sequence)
 

Function Documentation

◆ do_pgr_lineGraph()

void do_pgr_lineGraph ( pgr_edge_t data_edges,
size_t  total_edges,
bool  directed,
Line_graph_rt **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 60 of file lineGraph_driver.cpp.

68  {
69  std::ostringstream log;
70  std::ostringstream err;
71  std::ostringstream notice;
72  try {
73  pgassert(!(*log_msg));
74  pgassert(!(*notice_msg));
75  pgassert(!(*err_msg));
76  pgassert(!(*return_tuples));
77  pgassert(*return_count == 0);
78  pgassert(total_edges != 0);
79 
80  graphType gType = directed? DIRECTED: UNDIRECTED;
81 
82  pgrouting::DirectedGraph digraph(gType);
83  digraph.insert_edges_neg(data_edges, total_edges);
84 
85  log << digraph << "\n";
89  pgrouting::Basic_edge> line(digraph);
90  std::vector< Line_graph_rt > line_graph_edges;
91  line_graph_edges = line.get_postgres_results_directed();
92  auto count = line_graph_edges.size();
93 
94  if (count == 0) {
95  (*return_tuples) = NULL;
96  (*return_count) = 0;
97  notice <<
98  "Only vertices graph";
99  } else {
100  size_t sequence = 0;
101 
103  line_graph_edges,
104  return_tuples,
105  sequence);
106  (*return_count) = sequence;
107  }
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, get_postgres_result(), pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_edges_neg(), pgassert, pgr_free(), pgr_msg(), UNDIRECTED, and AssertFailedException::what().

Referenced by process().

◆ get_postgres_result()

void get_postgres_result ( std::vector< Line_graph_rt edge_result,
Line_graph_rt **  return_tuples,
size_t &  sequence 
)

Definition at line 46 of file lineGraph_driver.cpp.

49  {
50  (*return_tuples) = pgr_alloc(edge_result.size(), (*return_tuples));
51 
52  for (const auto &edge : edge_result) {
53  (*return_tuples)[sequence] = {edge.id, edge.source, edge.target,
55  sequence++;
56  }
57 }

References edge::cost, edge::id, pgr_alloc(), edge::reverse_cost, edge::source, and edge::target.

Referenced by do_pgr_contractGraph(), and do_pgr_lineGraph().

edge::reverse_cost
float8 reverse_cost
Definition: trsp.h:46
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
edge::target
int64 target
Definition: trsp.h:44
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::LinearDirectedGraph
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, Line_vertex, Basic_edge > LinearDirectedGraph
Data type to handle graph -> lineGaph transformation.
Definition: linear_directed_graph.h:55
pgrouting::Basic_edge
Definition: basic_edge.h:35
edge
Definition: trsp.h:41
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
pgrouting::graph::Pgr_lineGraph
Definition: pgr_lineGraph.hpp:49
edge::source
int64 source
Definition: trsp.h:43
graphType
graphType
Definition: graph_enum.h:30
DIRECTED
@ DIRECTED
Definition: graph_enum.h:30
edge::id
int64 id
Definition: trsp.h:42
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
pgrouting::Line_vertex
Definition: line_vertex.h:45
pgrouting::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
get_postgres_result
void get_postgres_result(std::vector< Line_graph_rt > edge_result, Line_graph_rt **return_tuples, size_t &sequence)
Definition: lineGraph_driver.cpp:46
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139