PGROUTING
3.2
chinesePostman_driver.cpp
Go to the documentation of this file.
1
/*PGR-GNU*****************************************************************
2
File: directedChPP_driver.cpp
3
4
Generated with Template by:
5
Copyright (c) 2015 pgRouting developers
6
Mail:
[email protected]
7
8
Function's developer:
9
Copyright (c) 2018 Maoguang Wang
10
Mail:
[email protected]
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
#include "
drivers/chinese/chinesePostman_driver.h
"
31
32
#include <sstream>
33
#include <deque>
34
#include <vector>
35
#include <set>
36
37
// work for only directed
38
#include "
chinese/pgr_chinesePostman.hpp
"
39
40
#include "
cpp_common/pgr_alloc.hpp
"
41
#include "
cpp_common/pgr_assert.h
"
42
43
void
44
do_pgr_directedChPP
(
45
pgr_edge_t
*data_edges,
size_t
total_edges,
46
bool
only_cost,
47
48
General_path_element_t
**return_tuples,
size_t
*return_count,
49
char
** log_msg,
50
char
** notice_msg,
51
char
** err_msg) {
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
63
pgrouting::graph::PgrDirectedChPPGraph
digraph(
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) {
72
General_path_element_t
edge
;
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
}
127
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_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
pgrouting::graph::PgrDirectedChPPGraph::DirectedChPP
double DirectedChPP() const
Definition:
pgr_chinesePostman.hpp:55
chinesePostman_driver.h
edge
Definition:
trsp.h:41
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition:
pgr_assert.h:94
pgrouting::graph::PgrDirectedChPPGraph::GetPathEdges
std::vector< General_path_element_t > GetPathEdges() const
Definition:
pgr_chinesePostman.hpp:59
pgr_alloc.hpp
pgr_assert.h
An assert functionality that uses C++ throw().
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
pgr_chinesePostman.hpp
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:
chinesePostman_driver.cpp:44
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition:
pgr_assert.h:139
src
chinese
chinesePostman_driver.cpp
Generated on Tue May 25 2021 15:09:47 for PGROUTING by
1.8.17