PGROUTING  3.2
bipartite_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: bipartite_driver.cpp
3 
4 Generated with Template by:
5 Copyright (c) 2015 pgRouting developers
7 
8 Function's developer:
9 Copyright (c) 2020 Prakash Tiwari
11 
12 ------
13 
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18 
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23 
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 
28  ********************************************************************PGR-GNU*/
29 
30 
31 /************************************************************
32  edges_sql TEXT
33  ***********************************************************/
34 
35 #include <string>
36 #include <sstream>
37 #include <deque>
38 #include <vector>
39 #include <algorithm>
41 #include "cpp_common/pgr_alloc.hpp"
47 
48 
49 /************************************************************
50  edges_sql TEXT
51  ***********************************************************/
52 void
54  pgr_edge_t *data_edges,
55  size_t total_edges,
56  pgr_bipartite_rt **return_tuples,
57  size_t *return_count,
58  char **log_msg,
59  char **notice_msg,
60  char **err_msg) {
61  std::ostringstream log;
62  std::ostringstream notice;
63  std::ostringstream err;
64 
65 
66  try {
67  pgassert(total_edges != 0);
68  pgassert(!(*log_msg));
69  pgassert(!(*notice_msg));
70  pgassert(!(*err_msg));
71  pgassert(!(*return_tuples));
72  pgassert(*return_count == 0);
73 
74  std::string logstr;
75  graphType gType = UNDIRECTED;
76  pgrouting::UndirectedGraph undigraph(gType);
77  undigraph.insert_edges(data_edges, total_edges);
78  std::vector<pgr_bipartite_rt> results;
80  results = fn_Bipartite.pgr_bipartite(undigraph);
81  logstr += fn_Bipartite.get_log();
82  log << logstr;
83  auto count = results.size();
84  if (count == 0) {
85  (*return_tuples) = NULL;
86  (*return_count) = 0;
87  *log_msg = log.str().empty()?
88  *log_msg :
89  pgr_msg(log.str().c_str());
90  *notice_msg = notice.str().empty()?
91  *notice_msg :
92  pgr_msg(notice.str().c_str());
93  return;
94  }
95  (*return_tuples) = pgr_alloc(count, (*return_tuples));
96  for (size_t i = 0; i < count; i++) {
97  *((*return_tuples) + i) = results[i];
98  }
99  (*return_count) = count;
100 
101  pgassert(*err_msg == NULL);
102  *log_msg = log.str().empty()?
103  *log_msg :
104  pgr_msg(log.str().c_str());
105  *notice_msg = notice.str().empty()?
106  *notice_msg :
107  pgr_msg(notice.str().c_str());
108  } catch (AssertFailedException &except) {
109  (*return_tuples) = pgr_free(*return_tuples);
110  (*return_count) = 0;
111  err << except.what();
112  *err_msg = pgr_msg(err.str().c_str());
113  *log_msg = pgr_msg(log.str().c_str());
114  } catch (std::exception &except) {
115  (*return_tuples) = pgr_free(*return_tuples);
116  (*return_count) = 0;
117  err << except.what();
118  *err_msg = pgr_msg(err.str().c_str());
119  *log_msg = pgr_msg(log.str().c_str());
120  } catch(...) {
121  (*return_tuples) = pgr_free(*return_tuples);
122  (*return_count) = 0;
123  err << "Caught unknown exception!";
124  *err_msg = pgr_msg(err.str().c_str());
125  *log_msg = pgr_msg(log.str().c_str());
126  }
127 }
pgrouting::functions::Pgr_Bipartite
Definition: pgr_bipartite_driver.hpp:53
pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
pgr_base_graph.hpp
pgrouting::functions::Pgr_Bipartite::pgr_bipartite
std::vector< pgr_bipartite_rt > pgr_bipartite(G &graph)
Definition: pgr_bipartite_driver.hpp:85
pgr_edge_t
Definition: pgr_edge_t.h:37
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_bipartite_rt
Definition: pgr_bipartite_rt.h:36
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pgr_bipartite_driver.hpp
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
pgrouting::graph::Pgr_base_graph::insert_edges
void insert_edges(const T *edges, size_t count)
Inserts count edges of type T into the graph.
Definition: pgr_base_graph.hpp:357
pgr_alloc.hpp
pgr_bipartite_rt.h
pgrouting::Pgr_messages::get_log
std::string get_log() const
get_log
Definition: pgr_messages.cpp:36
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
do_pgr_bipartite
void do_pgr_bipartite(pgr_edge_t *data_edges, size_t total_edges, pgr_bipartite_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: bipartite_driver.cpp:53
bipartite_driver.h
identifiers.hpp
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139
basePath_SSEC.hpp