53 for (
auto v : boost::make_iterator_range(boost::vertices(graph.graph))) {
54 if (graph[v].has_contracted_vertices()) {
67 using E =
typename G::E;
69 for (
auto e : boost::make_iterator_range(boost::edges(graph.graph))) {
70 if (graph[e].
id < 0) {
72 pgassert(!graph[e].contracted_vertices().empty());
74 pgassert(graph[e].contracted_vertices().empty());
77 std::vector<E> o_eids(eids.
begin(), eids.
end());
78 std::sort(o_eids.begin(), o_eids.end(),
79 [&](
E lhs,
E rhs) {return -graph[lhs].id < -graph[rhs].id;});
87 const std::vector< pgr_edge_t > &edges,
88 const std::vector< int64_t > &forbidden_vertices,
89 const std::vector< int64_t > &contraction_order,
91 graph.insert_edges(edges);
93 for (
const auto &vertex : forbidden_vertices) {
94 if (graph.has_vertex(vertex)) {
95 forbid_vertices += graph.get_V(vertex);
110 template <
typename G>
118 (*count) = modified_vertices.size() + shortcut_edges.size();
119 (*return_tuples) =
pgr_alloc((*count), (*return_tuples));
122 for (
const auto id : modified_vertices) {
123 auto v = graph.get_V(
id);
124 int64_t* contracted_vertices = NULL;
125 auto vids = graph[v].contracted_vertices();
127 contracted_vertices =
pgr_alloc(vids.size(), contracted_vertices);
130 for (
const auto id : vids) {
131 contracted_vertices[count++] = id;
133 (*return_tuples)[sequence] = {
135 const_cast<char*
>(
"v"),
144 for (
auto e : shortcut_edges) {
145 auto edge = graph[e];
146 int64_t* contracted_vertices = NULL;
148 const auto vids(
edge.contracted_vertices());
151 contracted_vertices =
pgr_alloc(vids.size(), contracted_vertices);
153 for (
const auto vid : vids) {
154 contracted_vertices[count++] = vid;
156 (*return_tuples)[sequence] = {
158 const_cast<char*
>(
"e"),
160 contracted_vertices, count};
180 int64_t *forbidden_vertices,
181 size_t size_forbidden_vertices,
182 int64_t *contraction_order,
183 size_t size_contraction_order,
187 size_t *return_count,
191 std::ostringstream log;
192 std::ostringstream notice;
193 std::ostringstream err;
196 pgassert(size_contraction_order != 0);
207 std::vector<pgr_edge_t> edges(data_edges, data_edges + total_edges);
208 std::vector<int64_t> forbid(
210 forbidden_vertices + size_forbidden_vertices);
211 std::vector<int64_t> ordering(
213 contraction_order + size_contraction_order);
215 for (
const auto kind : ordering) {
217 *err_msg =
pgr_msg(
"Invalid contraction type found");
218 log <<
"Contraction type " << kind <<
" not valid";
219 *log_msg =
pgr_msg(log.str().c_str());
250 *log_msg = log.str().empty()?
253 *notice_msg = notice.str().empty()?
257 (*return_tuples) =
pgr_free(*return_tuples);
259 err << except.
what();
260 *err_msg =
pgr_msg(err.str().c_str());
261 *log_msg =
pgr_msg(log.str().c_str());
262 }
catch (std::exception &except) {
263 (*return_tuples) =
pgr_free(*return_tuples);
265 err << except.what();
266 *err_msg =
pgr_msg(err.str().c_str());
267 *log_msg =
pgr_msg(log.str().c_str());
269 (*return_tuples) =
pgr_free(*return_tuples);
271 err <<
"Caught unknown exception!";
272 *err_msg =
pgr_msg(err.str().c_str());
273 *log_msg =
pgr_msg(log.str().c_str());