diff --git a/doc/spanningTree/CMakeLists.txt b/doc/spanningTree/CMakeLists.txt index fd9443defe..2cbe8ba11e 100644 --- a/doc/spanningTree/CMakeLists.txt +++ b/doc/spanningTree/CMakeLists.txt @@ -3,7 +3,6 @@ # License: GPL-2 See https://github.com/pgRouting/pgrouting/blob/main/LICENSE set(LOCAL_FILES - #pgr_randomSpanTree.rst kruskal-family.rst prim-family.rst pgr_kruskal.rst @@ -15,7 +14,7 @@ set(LOCAL_FILES pgr_primDD.rst pgr_primDFS.rst pgr_primBFS.rst - ) +) foreach (f ${LOCAL_FILES}) configure_file(${f} "${PGR_DOCUMENTATION_SOURCE_DIR}/${f}") @@ -23,4 +22,3 @@ foreach (f ${LOCAL_FILES}) endforeach() set(PROJECT_DOC_FILES ${PROJECT_DOC_FILES} ${LOCAL_DOC_FILES} PARENT_SCOPE) - diff --git a/doc/spanningTree/pgr_randomSpanTree.rst b/doc/spanningTree/pgr_randomSpanTree.rst deleted file mode 100644 index 90bad3f308..0000000000 --- a/doc/spanningTree/pgr_randomSpanTree.rst +++ /dev/null @@ -1,72 +0,0 @@ -:file: This file is part of the pgRouting project. -:copyright: Copyright (c) 2013-2026 pgRouting developers -:license: Creative Commons Attribution-Share Alike 3.0 https://creativecommons.org/licenses/by-sa/3.0 - -| - - -pgr_randomSpanTree - Experimental -=============================================================================== - -``pgr_randomSpanTree`` — Random spanning tree of a graph using the algorithm -implemented by Boost.Graph. - -.. figure:: images/boost-inside.jpeg - :target: https://www.boost.org/libs/graph/doc/kruskal_min_spanning_tree.html - - Boost Graph Inside - -.. include:: experimental.rst - :start-after: begin-warn-expr - :end-before: end-warn-expr - -.. rubric:: Availability - -* **TBD** - -Description -------------------------------------------------------------------------------- - -* TBD - -The main characteristics are: - - **CRASHES THE SERVER** - -* TBD - -Signatures -------------------------------------------------------------------------------- - -* TBD - -.. rubric:: Summary - -* TBD - -Parameters -------------------------------------------------------------------------------- - -* TBD - -Inner Queries -------------------------------------------------------------------------------- - -*Description of the edges_sql query for pgr_randomSpanTree functions* - -* TBD - -Result columns -------------------------------------------------------------------------------- - -*Description of the return values for pgr_randomSpanTree algorithms* - -* TBD - -See Also -------------------------------------------------------------------------------- - -.. rubric:: Indices and tables - -* :ref:`genindex` -* :ref:`search` - diff --git a/docqueries/spanningTree/randomSpanTree.pg b/docqueries/spanningTree/randomSpanTree.pg deleted file mode 100644 index 08cc653993..0000000000 --- a/docqueries/spanningTree/randomSpanTree.pg +++ /dev/null @@ -1,12 +0,0 @@ -/* :file: This file is part of the pgRouting project. -:copyright: Copyright (c) 2016-2026 pgRouting developers -:license: Creative Commons Attribution-Share Alike 3.0 https://creativecommons.org/licenses/by-sa/3.0 */ -/* -- q1 */ -SELECT * FROM pgr_randomSpanTree( - 'SELECT id, source, target, cost, reverse_cost FROM edges', - 7); -/* -- q2 */ -SELECT * FROM pgr_randomSpanTree( - 'SELECT id, source, target, cost, reverse_cost FROM edges', - 15, false); -/* -- q3 */ diff --git a/docqueries/spanningTree/randomSpanTree.result b/docqueries/spanningTree/randomSpanTree.result deleted file mode 100644 index 48a9fc368d..0000000000 --- a/docqueries/spanningTree/randomSpanTree.result +++ /dev/null @@ -1,23 +0,0 @@ -BEGIN; -BEGIN -SET client_min_messages TO NOTICE; -SET -/* :file: This file is part of the pgRouting project. -:copyright: Copyright (c) 2018-2026 pgRouting developers -:license: Creative Commons Attribution-Share Alike 3.0 https://creativecommons.org/licenses/by-sa/3.0 */ --- q1 -SELECT * FROM pgr_randomSpanTree( - 'SELECT id, source, target, cost, reverse_cost FROM edge_table', 5 -); -ERROR: function pgr_randomspantree(unknown, integer) does not exist -LINE 1: SELECT * FROM pgr_randomSpanTree( - ^ -HINT: No function matches the given name and argument types. You might need to add explicit type casts. --- q2 -SELECT * FROM pgr_randomSpanTree( - 'SELECT id, source, target, cost, reverse_cost FROM edge_table', 4, false -); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- q3 -ROLLBACK; -ROLLBACK diff --git a/include/drivers/spanningTree/randomSpanningTree_driver.h b/include/drivers/spanningTree/randomSpanningTree_driver.h deleted file mode 100644 index d220b56f86..0000000000 --- a/include/drivers/spanningTree/randomSpanningTree_driver.h +++ /dev/null @@ -1,73 +0,0 @@ -/*PGR-GNU***************************************************************** -File: randomSpanningTree_driver.h - -Generated with Template by: -Copyright (c) 2007-2026 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2018 Aditya Pratap Singh -Mail: adityapratap.singh28@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#ifndef INCLUDE_DRIVERS_SPANNINGTREE_RANDOMSPANNINGTREE_DRIVER_H_ -#define INCLUDE_DRIVERS_SPANNINGTREE_RANDOMSPANNINGTREE_DRIVER_H_ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#ifdef __cplusplus -} -#endif - -#include "cpp_common/undefPostgresDefine.hpp" - -#ifdef __cplusplus -# include -using SpanTree_rt = struct SpanTree_rt; -#else -# include -typedef SpanTree_rt SpanTree_rt; -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -void pgr_do_randomSpanningTree( - const char*, - ArrayType*, - - int64_t, double, - - SpanTree_rt**, size_t*, - char**, char**, char**); - -#ifdef __cplusplus -} -#endif - -#endif // INCLUDE_DRIVERS_SPANNINGTREE_RANDOMSPANNINGTREE_DRIVER_H_ diff --git a/include/spanningTree/pgr_randomSpanningTree.hpp b/include/spanningTree/pgr_randomSpanningTree.hpp deleted file mode 100644 index 2c16e82855..0000000000 --- a/include/spanningTree/pgr_randomSpanningTree.hpp +++ /dev/null @@ -1,151 +0,0 @@ -/*PGR-GNU***************************************************************** -File: pgr_randomSpanningTree.hpp - -Copyright (c) 2018-2026 pgRouting developers -Mail: project@pgrouting.org - -Copyright (c) 2018 Aditya Pratap Singh -adityapratap.singh28@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#ifndef INCLUDE_SPANNINGTREE_PGR_RANDOMSPANNINGTREE_HPP_ -#define INCLUDE_SPANNINGTREE_PGR_RANDOMSPANNINGTREE_HPP_ -#pragma once - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "cpp_common/path.hpp" -#include "cpp_common/pgr_base_graph.hpp" -#include "cpp_common/interruption.hpp" - -template < class G > class Pgr_randomSpanningTree; -// user's functions -// for development - -//****************************************** - -template < class G > -class Pgr_randomSpanningTree { - public: - typedef typename G::V V; - typedef typename G::E E; - - std::vector randomSpanningTree( - G &graph, - int64_t root_vertex); - - private: - // Member - std::vector< V > predecessors; - - // Function - std::vector< SpanTree_rt > - undirectedGraph( - const G &graph, - int64_t root_vertex) { - std::ostringstream log; - auto v_root(graph.get_V(root_vertex)); - - std::minstd_rand rng; - - /* abort in case of an interruption occurs (e.g. the query is being cancelled) */ - CHECK_FOR_INTERRUPTS(); - - // TODO(aps) - // This function is running in infinite loop - try { - boost::random_spanning_tree( - graph.graph, - rng, - boost::root_vertex(v_root) - .predecessor_map(&predecessors[0]) - .weight_map(get(&G::G_T_E::cost, graph.graph))); - } catch (std::exception const &ex) { - log << ex.what(); - } catch (...) { - log << "Unknown exception caught"; - } - - std::vector< SpanTree_rt > result; - return result; -#if 0 - std::vector< SpanTree_rt > results; - double totalcost = 0; - SpanTree_rt tmp; - - tmp.root_vertex = root_vertex; - tmp.edge = -1; - tmp.cost = 0; - tmp.tree_cost = totalcost; - - results.push_back(tmp); - - for (size_t j = 0; j < predecessors.size(); j++) { - if (j != v_root) { - SpanTree_rt tmp; - - auto start_node = graph.graph[predecessors[j]].id; - auto end_node = graph.graph[j].id; // node - - auto v_sn(graph.get_V(start_node)); - auto v_en(graph.get_V(end_node)); - - auto cost = graph[boost::edge( - predecessors[j], j, graph.graph).first].cost; - auto edge_id = - graph.get_edge_id(v_sn, v_en, cost); - totalcost += cost; - - tmp.root_vertex = root_vertex; - tmp.edge = edge_id; // edge_id - tmp.cost = cost; // cost - tmp.tree_cost = totalcost; // tree_cost - results.push_back(tmp); - } - } - return results; - } -#endif -}; - -template < class G > -std::vector -Pgr_randomSpanningTree< G >::randomSpanningTree( - G &graph, - int64_t root_vertex ) { - predecessors.clear(); - // TODO(aps) - // Currently only running for undirected graph - return undirectedGraph( - graph, - root_vertex); -} - - -#endif // INCLUDE_SPANNINGTREE_PGR_RANDOMSPANNINGTREE_HPP_ diff --git a/sql/spanningTree/CMakeLists.txt b/sql/spanningTree/CMakeLists.txt index 7c0f2a4e03..5da649a738 100644 --- a/sql/spanningTree/CMakeLists.txt +++ b/sql/spanningTree/CMakeLists.txt @@ -5,7 +5,6 @@ set(LOCAL_FILES _prim.sql _kruskal.sql - #_randomSpanTree.sql prim.sql primDFS.sql @@ -16,10 +15,7 @@ set(LOCAL_FILES kruskalDFS.sql kruskalBFS.sql kruskalDD.sql - #randomSpanTree.sql - ) - -# Do not modify below this line +) foreach (f ${LOCAL_FILES}) configure_file(${f} ${f}) diff --git a/sql/spanningTree/_randomSpanTree.sql b/sql/spanningTree/_randomSpanTree.sql deleted file mode 100644 index 66dddf20a9..0000000000 --- a/sql/spanningTree/_randomSpanTree.sql +++ /dev/null @@ -1,56 +0,0 @@ -/*PGR-GNU***************************************************************** -File: _randomSpanTree.sql - -Generated with Template by: -Copyright (c) 2007-2026 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2018 Aditya Pratap Singh -Mail: adityapratap.singh28@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - ------------------------ --- _pgr_randomSpanTree ------------------------ - ---v3.0 -CREATE FUNCTION _pgr_randomSpanTree( - TEXT, -- Edge sql - BIGINT, -- Root - BOOLEAN, -- directed - BOOLEAN, -- use_component - - OUT seq BIGINT, -- Seq - OUT root_vertex BIGINT, -- Root_vetex - OUT edge BIGINT, -- Edge linked to that node - OUT cost FLOAT, -- Cost of edge - OUT tree_cost FLOAT) -- Spanning tree cost -RETURNS SETOF RECORD AS -'MODULE_PATHNAME' -LANGUAGE C VOLATILE STRICT -COST ${COST_HIGH} ROWS ${ROWS_HIGH}; - - - - -COMMENT ON FUNCTION _pgr_randomSpanTree(TEXT, BIGINT, BOOLEAN, BOOLEAN) -IS 'pgRouting internal function'; - diff --git a/sql/spanningTree/randomSpanTree.sql b/sql/spanningTree/randomSpanTree.sql deleted file mode 100644 index e80c8fe875..0000000000 --- a/sql/spanningTree/randomSpanTree.sql +++ /dev/null @@ -1,80 +0,0 @@ -/*PGR-GNU***************************************************************** -File: randomSpanTree.sql - -Generated with Template by: -Copyright (c) 2007-2026 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2018 Aditya Pratap Singh -Mail: adityapratap.singh28@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - ------------------------ --- pgr_randomSpanTree ------------------------ - - ---vnone -CREATE FUNCTION pgr_randomSpanTree( - TEXT, -- edges_sql (required) - BIGINT, -- root (required) - - directed BOOLEAN DEFAULT TRUE, - - OUT seq BIGINT, -- Seq - OUT root_vertex BIGINT, - OUT edge BIGINT, -- Edge linked to that node - OUT cost FLOAT, -- Cost of edge - OUT tree_cost FLOAT) -- Spanning tree cost -RETURNS SETOF RECORD AS -$BODY$ -DECLARE - connectedComponent BIGINT; -BEGIN - SELECT COUNT(DISTINCT component) INTO connectedComponent - FROM pgr_connectedComponents( - 'SELECT id, source, target, cost, reverse_cost - FROM edge_table' - ); - - IF (connectedComponent = 1) THEN - SELECT seq, root_vertex, edge, cost, tree_cost - FROM _pgr_randomSpanTree(_pgr_get_statement($1), $2, $3, TRUE); - ELSE - SELECT seq, root_vertex, edge, cost, tree_cost - FROM _pgr_randomSpanTree(_pgr_get_statement($1), $2, $3, FALSE); - END IF; -END; -$BODY$ -LANGUAGE plpgsql VOLATILE STRICT; - -COMMENT ON FUNCTION pgr_randomSpanTree(TEXT, BIGINT) -IS 'pgr_randomSpanTree -- EXPERIMENTAL -- Undirected graph -- Parameters: - - Edges SQL with columns: id, source, target, cost [,reverse_cost] - - Root vertex identifier -- Optional Parameters - - directed: default := ''true'' -- Documentation: - - ${PROJECT_DOC_LINK}/pgr_randomSpanTree.html -'; diff --git a/src/spanningTree/CMakeLists.txt b/src/spanningTree/CMakeLists.txt index 7c3400a9b4..001a86e874 100644 --- a/src/spanningTree/CMakeLists.txt +++ b/src/spanningTree/CMakeLists.txt @@ -1,6 +1,7 @@ # This file is part of the pgRouting project. # Copyright (c) 2018-2026 pgRouting developers # License: GPL-2 See https://github.com/pgRouting/pgrouting/blob/main/LICENSE + ADD_LIBRARY(spanningTree OBJECT mst_common.cpp details.cpp @@ -10,7 +11,4 @@ ADD_LIBRARY(spanningTree OBJECT prim.c prim_driver.cpp - - #randomSpanningTree.c - #randomSpanningTree_driver.cpp - ) +) diff --git a/src/spanningTree/randomSpanningTree.c b/src/spanningTree/randomSpanningTree.c deleted file mode 100644 index fb4efe0a4c..0000000000 --- a/src/spanningTree/randomSpanningTree.c +++ /dev/null @@ -1,151 +0,0 @@ -/*PGR-GNU***************************************************************** -File: randomSpanningTree.c -Generated with Template by: - -Copyright (c) 2015-2026 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2018 Aditya Pratap Singh -Mail: adityapratap.singh28@gmail.com ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include -#include "c_common/postgres_connection.h" -#include "c_types/spanTree_rt.h" -#include "c_common/debug_macro.h" -#include "c_common/e_report.h" -#include "c_common/time_msg.h" - - -#include "drivers/spanningTree/randomSpanningTree_driver.h" - -PGDLLEXPORT Datum randomSpanningTree(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1(randomSpanningTree); - -static -void -process( - char* edges_sql, - int64_t root_vertex, - bool directed, - SpanTree_rt **result_tuples, - size_t *result_count) { - pgr_SPI_connect(); - char* log_msg = NULL; - char* notice_msg = NULL; - char* err_msg = NULL; - - (*result_tuples) = NULL; - (*result_count) = 0; - - clock_t start_t = clock(); - pgr_do_randomSpanningTree( - edges, - total_edges, - root_vertex, - directed, - result_tuples, - result_count, - &log_msg, - ¬ice_msg, - &err_msg); - - time_msg(" processing pgr_randomSpanningTree", start_t, clock()); - PGR_DBG("Returning %ld tuples", *result_count); - - if (err_msg) { - if (*result_tuples) pfree(*result_tuples); - } - pgr_global_report(&log_msg, ¬ice_msg, &err_msg); - - pgr_SPI_finish(); -} -/* */ - -PGDLLEXPORT Datum randomSpanningTree(PG_FUNCTION_ARGS) { - FuncCallContext *funcctx; - TupleDesc tuple_desc; - - SpanTree_rt *result_tuples = NULL; - size_t result_count = 0; - - if (SRF_IS_FIRSTCALL()) { - MemoryContext oldcontext; - funcctx = SRF_FIRSTCALL_INIT(); - oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); - - - PGR_DBG("Calling process"); - process( - text_to_cstring(PG_GETARG_TEXT_P(0)), - PG_GETARG_INT64(1), - PG_GETARG_BOOL(2), - &result_tuples, - &result_count); - - funcctx->max_calls = result_count; - funcctx->user_fctx = result_tuples; - if (get_call_result_type(fcinfo, NULL, &tuple_desc) - != TYPEFUNC_COMPOSITE) { - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("function returning record called in context " - "that cannot accept type record"))); - } - - funcctx->tuple_desc = tuple_desc; - MemoryContextSwitchTo(oldcontext); - } - - funcctx = SRF_PERCALL_SETUP(); - tuple_desc = funcctx->tuple_desc; - result_tuples = (SpanTree_rt*) funcctx->user_fctx; - - if (funcctx->call_cntr < funcctx->max_calls) { - HeapTuple tuple; - Datum result; - Datum *values; - bool* nulls; - - values = palloc(5 * sizeof(Datum)); - nulls = palloc(5 * sizeof(bool)); - - - size_t i; - for (i = 0; i < 5; ++i) { - nulls[i] = false; - } - - values[0] = Int64GetDatum((int64_t)funcctx->call_cntr + 1); - values[1] = - Int64GetDatum(result_tuples[funcctx->call_cntr].root_vertex); - values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge); - values[3] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); - values[4] = Float8GetDatum(result_tuples[funcctx->call_cntr].tree_cost); - - tuple = heap_form_tuple(tuple_desc, values, nulls); - result = HeapTupleGetDatum(tuple); - SRF_RETURN_NEXT(funcctx, result); - } else { - PGR_DBG("Clean up code"); - - SRF_RETURN_DONE(funcctx); - } -} diff --git a/src/spanningTree/randomSpanningTree_driver.cpp b/src/spanningTree/randomSpanningTree_driver.cpp deleted file mode 100644 index 68a34501d8..0000000000 --- a/src/spanningTree/randomSpanningTree_driver.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/*PGR-GNU***************************************************************** -File: randomSpanningTree_driver.cpp - -Generated with Template by: -Copyright (c) 2015-2026 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2018 Aditya Pratap Singh -Mail: adityapratap.singh28@gmail.com ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include "drivers/spanningTree/randomSpanningTree_driver.h" - -#include -#include -#include -#include - - -#include "cpp_common/pgdata_getters.hpp" -#include "cpp_common/alloc.hpp" -#include "cpp_common/assert.hpp" -#include "spanningTree/randomSpanningTree.hpp" - -template < class G > -static -std::vector -pgr_randomSpanningTree( - G &graph, - int64_t root_vertex ) { - Pgr_randomSpanningTree< G > fn_randomSpanningTree; - return fn_randomSpanningTree.randomSpanningTree(graph, root_vertex); -} - - -void -pgr_do_randomSpanningTree( - const char *edges_sql, - int64_t root_vertex, - bool directed, - SpanTree_rt **return_tuples, - size_t *return_count, - char ** log_msg, - char ** notice_msg, - char ** err_msg) { - using pgrouting::pgr_alloc; - using pgrouting::to_pg_msg; - using pgrouting::pgr_free; - - std::ostringstream log; - std::ostringstream err; - std::ostringstream notice; - const char *hint = nullptr; - - try { - pgassert(!(*log_msg)); - pgassert(!(*notice_msg)); - pgassert(!(*err_msg)); - pgassert(!(*return_tuples)); - pgassert(*return_count == 0); - pgassert(total_edges != 0); - - hint = edges_sql; - auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false); - - if (edges.empty()) { - *notice_msg = to_pg_msg("No edges found"); - *log_msg = hint? to_pg_msg(hint) : to_pg_msg(log); - return; - } - hint = nullptr; - - - - std::vector results; - - if (directed) { - log << "Working with directed Graph\n"; - pgrouting::DirectedGraph digraph(directed); - digraph.insert_edges(data_edges, total_edges); - results = pgr_randomSpanningTree( - digraph, - root_vertex); - } else { - log << "Working with Undirected Graph\n"; - pgrouting::UndirectedGraph undigraph(directed); - undigraph.insert_edges(data_edges, total_edges); - results = pgr_randomSpanningTree( - undigraph, - root_vertex); - } - - auto count = results.size(); - - if (count == 0) { - (*return_tuples) = NULL; - (*return_count) = 0; - notice << "No paths found"; - return; - } - - (*return_tuples) = pgr_alloc(count, (*return_tuples)); - for (size_t i = 0; i < count; i++) { - *((*return_tuples) + i) = results[i]; - } - (*return_count) = count; - - pgassert(*err_msg == NULL); - *log_msg = to_pg_msg(log); - *notice_msg = to_pg_msg(notice); - } catch (AssertFailedException &except) { - (*return_tuples) = pgr_free(*return_tuples); - (*return_count) = 0; - err << except.what(); - *err_msg = to_pg_msg(err); - *log_msg = to_pg_msg(log); - } catch (const std::string &ex) { - *err_msg = to_pg_msg(ex); - *log_msg = hint? to_pg_msg(hint) : to_pg_msg(log); - } catch (std::exception &except) { - (*return_tuples) = pgr_free(*return_tuples); - (*return_count) = 0; - err << except.what(); - *err_msg = to_pg_msg(err); - *log_msg = to_pg_msg(log); - } catch(...) { - (*return_tuples) = pgr_free(*return_tuples); - (*return_count) = 0; - err << "Caught unknown exception!"; - *err_msg = to_pg_msg(err); - *log_msg = to_pg_msg(log); - } -}