From f5602b10f55e83a15bd858c5284eebbf5c061363 Mon Sep 17 00:00:00 2001 From: nike0good Date: Fri, 7 Jun 2019 11:34:00 +0800 Subject: [PATCH 1/7] [toposort] change name --- configuration.conf | 2 +- ...gical_sort_t.h => pgr_topologicalSort_t.h} | 13 +++--- include/cpp_common/pgr_topological_sort_t.h | 42 ------------------- .../topologicalSort_driver.h} | 16 +++---- sql/sigs/pgrouting--3.0.0.sig | 4 +- .../CMakeLists.txt | 4 +- .../_topologicalSort.sql} | 9 ++-- .../topologicalSort.sql} | 14 +++---- src/topologicalSort/CMakeLists.txt | 4 ++ .../topologicalSort.c} | 22 +++++----- .../topologicalSort_driver.cpp} | 30 ++++++------- src/topological_sort/CMakeLists.txt | 4 -- 12 files changed, 63 insertions(+), 101 deletions(-) rename include/c_types/{pgr_topological_sort_t.h => pgr_topologicalSort_t.h} (79%) delete mode 100644 include/cpp_common/pgr_topological_sort_t.h rename include/drivers/{topological_sort/topological_sort_driver.h => topologicalSort/topologicalSort_driver.h} (77%) rename sql/{topological_sort => topologicalSort}/CMakeLists.txt (82%) rename sql/{topological_sort/_topological_sort.sql => topologicalSort/_topologicalSort.sql} (87%) rename sql/{topological_sort/topological_sort.sql => topologicalSort/topologicalSort.sql} (82%) create mode 100644 src/topologicalSort/CMakeLists.txt rename src/{topological_sort/topological_sort.c => topologicalSort/topologicalSort.c} (90%) rename src/{topological_sort/topological_sort_driver.cpp => topologicalSort/topologicalSort_driver.cpp} (82%) delete mode 100644 src/topological_sort/CMakeLists.txt diff --git a/configuration.conf b/configuration.conf index 3233fefbad..25b1e6c0b0 100644 --- a/configuration.conf +++ b/configuration.conf @@ -38,7 +38,7 @@ costFlow | Y | Y | Y ChPP | Y | Y | Y spanningTree | Y | Y | Y mincut | Y | Y | Y -topological_sort | Y | Y | N +topologicalSort | Y | Y | N #---------------------- # SQL only directories diff --git a/include/c_types/pgr_topological_sort_t.h b/include/c_types/pgr_topologicalSort_t.h similarity index 79% rename from include/c_types/pgr_topological_sort_t.h rename to include/c_types/pgr_topologicalSort_t.h index 9959338bcc..12d33496f1 100644 --- a/include/c_types/pgr_topological_sort_t.h +++ b/include/c_types/pgr_topologicalSort_t.h @@ -1,5 +1,8 @@ /*PGR-GNU***************************************************************** -File: pgr_topological_sort_t.h +File: pgr_topologicalSortt.h + +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org Function's developer: Copyright (c) 2019 Hang Wu @@ -20,8 +23,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ /*! @file */ -#ifndef INCLUDE_C_TYPES_PGR_TOPOLOGICAL_SORT_T_H_ -#define INCLUDE_C_TYPES_PGR_TOPOLOGICAL_SORT_T_H_ +#ifndef INCLUDE_C_TYPES_PGR_TOPOLOGICALSORT_T_H_ +#define INCLUDE_C_TYPES_PGR_TOPOLOGICALSORT_T_H_ #pragma once /* for int64_t */ @@ -34,6 +37,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. typedef struct { int seq; int sorted_v; -} pgr_topological_sort_t; +} pgr_topologicalSort_t; -#endif // INCLUDE_C_TYPES_PGR_TOPOLOGICAL_SORT_T_H_ +#endif // INCLUDE_C_TYPES_PGR_TOPOLOGICALSORT_T_H_ diff --git a/include/cpp_common/pgr_topological_sort_t.h b/include/cpp_common/pgr_topological_sort_t.h deleted file mode 100644 index 8dc420fcbf..0000000000 --- a/include/cpp_common/pgr_topological_sort_t.h +++ /dev/null @@ -1,42 +0,0 @@ -/*PGR-GNU***************************************************************** -File: pgr_topological_sort_t.h - -Copyright (c) 2015 Aditya Pratap Singh -Mail: adityapratap.singh28@gmail.com - -Function's developer: -Copyright (c) 2019 Hang Wu -mail: nike0good@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*/ -/*! @file */ - -#ifndef INCLUDE_C_TYPES_PGR_TOPOLOGICAL_SORT_T_H_ -#define INCLUDE_C_TYPES_PGR_TOPOLOGICAL_SORT_T_H_ -#pragma once - -/* for int64_t */ -#ifdef __cplusplus -# include -#else -# include -#endif - -typedef struct { - int seq; - int sorted_v; -} pgr_topological_sort_t; - -#endif // INCLUDE_C_TYPES_PGR_STOERWAGNER_T_H_ diff --git a/include/drivers/topological_sort/topological_sort_driver.h b/include/drivers/topologicalSort/topologicalSort_driver.h similarity index 77% rename from include/drivers/topological_sort/topological_sort_driver.h rename to include/drivers/topologicalSort/topologicalSort_driver.h index 91424eb7d4..e0d6c4de04 100644 --- a/include/drivers/topological_sort/topological_sort_driver.h +++ b/include/drivers/topologicalSort/topologicalSort_driver.h @@ -1,6 +1,6 @@ /*PGR-GNU***************************************************************** -File: topological_sort_driver.h +File: topologicalSort_driver.h Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -28,8 +28,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#ifndef INCLUDE_DRIVERS_TOPOLOGICAL_SORT_TOPOLOGICAL_SORT_DRIVER_H_ -#define INCLUDE_DRIVERS_TOPOLOGICAL_SORT_TOPOLOGICAL_SORT_DRIVER_H_ +#ifndef INCLUDE_DRIVERS_TOPOLOGICALSORT_TOPOLOGICALSORT_DRIVER_H_ +#define INCLUDE_DRIVERS_TOPOLOGICALSORT_TOPOLOGICALSORT_DRIVER_H_ /* for size-t */ #ifdef __cplusplus @@ -39,19 +39,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #endif #include "c_types/pgr_edge_t.h" -#include "c_types/pgr_topological_sort_t.h" +#include "c_types/pgr_topologicalSort_t.h" #ifdef __cplusplus extern "C" { #endif - // CREATE OR REPLACE FUNCTION pgr_topological_sort( + // CREATE OR REPLACE FUNCTION pgr_topologicalSort( // sql text, - void do_pgr_topological_sort( + void do_pgr_topologicalSort( pgr_edge_t *data_edges, size_t total_tuples, - pgr_topological_sort_t **return_tuples, + pgr_topologicalSort_t **return_tuples, size_t *return_count, char** log_msg, @@ -62,4 +62,4 @@ extern "C" { } #endif -#endif // INCLUDE_DRIVERS_TOPOLOGICAL_SORT_DRIVER_H_ +#endif // INCLUDE_DRIVERS_topologicalSort_DRIVER_H_ diff --git a/sql/sigs/pgrouting--3.0.0.sig b/sql/sigs/pgrouting--3.0.0.sig index 838849f5ea..def37c5e1b 100644 --- a/sql/sigs/pgrouting--3.0.0.sig +++ b/sql/sigs/pgrouting--3.0.0.sig @@ -178,8 +178,8 @@ _pgr_stoerwagner(text) pgr_stoerwagner(text) _pgr_strongcomponents(text) pgr_strongcomponents(text) -_pgr_topological_sort(text) -pgr_topological_sort(text) +_pgr_topologicalsort(text) +pgr_topologicalsort(text) _pgr_trsp(text,integer,double precision,integer,double precision,boolean,boolean,text) pgr_trsp(text,integer,double precision,integer,double precision,boolean,boolean,text) pgr_trsp(text,integer,integer,boolean,boolean,text) diff --git a/sql/topological_sort/CMakeLists.txt b/sql/topologicalSort/CMakeLists.txt similarity index 82% rename from sql/topological_sort/CMakeLists.txt rename to sql/topologicalSort/CMakeLists.txt index e668f6a5f0..348446734a 100644 --- a/sql/topological_sort/CMakeLists.txt +++ b/sql/topologicalSort/CMakeLists.txt @@ -1,7 +1,7 @@ SET(LOCAL_FILES - _topological_sort.sql - topological_sort.sql + _topologicalSort.sql + topologicalSort.sql ) foreach (f ${LOCAL_FILES}) diff --git a/sql/topological_sort/_topological_sort.sql b/sql/topologicalSort/_topologicalSort.sql similarity index 87% rename from sql/topological_sort/_topological_sort.sql rename to sql/topologicalSort/_topologicalSort.sql index 6188fddf45..eb63c6eea4 100644 --- a/sql/topological_sort/_topological_sort.sql +++ b/sql/topologicalSort/_topologicalSort.sql @@ -3,6 +3,7 @@ Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org +Function's developer: Copyright (c) 2019 Hang Wu mail: nike0good@gmail.com @@ -26,20 +27,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. --------------- --------------- --- topological_sort +-- topologicalSort --------------- --------------- -CREATE OR REPLACE FUNCTION _pgr_topological_sort( +CREATE OR REPLACE FUNCTION _pgr_topologicalSort( edges_sql TEXT, OUT seq INTEGER, OUT sorted_v INTEGER) RETURNS SETOF RECORD AS -'MODULE_PATHNAME', 'topological_sort' +'MODULE_PATHNAME', 'topologicalSort' LANGUAGE C VOLATILE STRICT; -- COMMENTS -COMMENT ON FUNCTION _pgr_topological_sort(TEXT) +COMMENT ON FUNCTION _pgr_topologicalSort(TEXT) IS 'pgRouting internal function'; diff --git a/sql/topological_sort/topological_sort.sql b/sql/topologicalSort/topologicalSort.sql similarity index 82% rename from sql/topological_sort/topological_sort.sql rename to sql/topologicalSort/topologicalSort.sql index 8398e60505..94889770d3 100644 --- a/sql/topological_sort/topological_sort.sql +++ b/sql/topologicalSort/topologicalSort.sql @@ -3,9 +3,9 @@ Copyright (c) 2015 pgRouting developers Mail: project@pgrouting.org +Function's developer: Copyright (c) 2019 Hang Wu mail: nike0good@gmail.com - ------ This program is free software; you can redistribute it and/or modify @@ -25,10 +25,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ --------------- --- pgr_topological_sort +-- pgr_topologicalSort --------------- -CREATE OR REPLACE FUNCTION pgr_topological_sort( +CREATE OR REPLACE FUNCTION pgr_topologicalSort( TEXT, -- edges_sql (required) OUT seq INTEGER, @@ -36,7 +36,7 @@ CREATE OR REPLACE FUNCTION pgr_topological_sort( RETURNS SETOF RECORD AS $BODY$ SELECT a.seq, a.sorted_v - FROM _pgr_topological_sort(_pgr_get_statement($1)) AS a; + FROM _pgr_topologicalSort(_pgr_get_statement($1)) AS a; $BODY$ LANGUAGE sql VOLATILE STRICT COST 100 @@ -45,12 +45,12 @@ ROWS 1000; -- COMMENTS -COMMENT ON FUNCTION pgr_topological_sort(TEXT) -IS 'pgr_topological_sort +COMMENT ON FUNCTION pgr_topologicalSort(TEXT) +IS 'pgr_topologicalSort - Parameters: - Edges SQL with columns: id, source, target, cost [,reverse_cost] - Documentation: - - ${PGROUTING_DOC_LINK}/pgr_topological_sort.html + - ${PGROUTING_DOC_LINK}/pgr_topologicalSort.html '; diff --git a/src/topologicalSort/CMakeLists.txt b/src/topologicalSort/CMakeLists.txt new file mode 100644 index 0000000000..980015576c --- /dev/null +++ b/src/topologicalSort/CMakeLists.txt @@ -0,0 +1,4 @@ +ADD_LIBRARY(topologicalSort OBJECT + topologicalSort.c + + topologicalSort_driver.cpp) diff --git a/src/topological_sort/topological_sort.c b/src/topologicalSort/topologicalSort.c similarity index 90% rename from src/topological_sort/topological_sort.c rename to src/topologicalSort/topologicalSort.c index fa13e3045b..f50012bef5 100644 --- a/src/topological_sort/topological_sort.c +++ b/src/topologicalSort/topologicalSort.c @@ -1,6 +1,6 @@ /*PGR-GNU***************************************************************** -File: many_to_many_dijkstra.c +File: topologicalSort.c Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -39,18 +39,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_common/time_msg.h" #include "c_common/edges_input.h" #include "c_common/arrays_input.h" -#include "drivers/topological_sort/topological_sort_driver.h" +#include "drivers/topologicalSort/topologicalSort_driver.h" #if 0 PG_MODULE_MAGIC; #endif -PGDLLEXPORT Datum topological_sort(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1(topological_sort); +PGDLLEXPORT Datum topologicalSort(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(topologicalSort); static void process( char* edges_sql, - pgr_topological_sort_t **result_tuples, + pgr_topologicalSort_t **result_tuples, size_t *result_count) { pgr_SPI_connect(); @@ -63,7 +63,7 @@ process( char* log_msg = NULL; char* notice_msg = NULL; char* err_msg = NULL; - do_pgr_topological_sort( + do_pgr_topologicalSort( edges, total_edges, result_tuples, @@ -73,7 +73,7 @@ process( ¬ice_msg, &err_msg); - time_msg("processing pgr_topological_sort", start_t, clock()); + time_msg("processing pgr_topologicalSort", start_t, clock()); if (err_msg && (*result_tuples)) { @@ -92,12 +92,12 @@ process( } PGDLLEXPORT Datum -topological_sort(PG_FUNCTION_ARGS) { +topologicalSort(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tuple_desc; /**********************************************************************/ - pgr_topological_sort_t *result_tuples = NULL; + pgr_topologicalSort_t *result_tuples = NULL; size_t result_count = 0; /**********************************************************************/ @@ -108,7 +108,7 @@ topological_sort(PG_FUNCTION_ARGS) { /**********************************************************************/ - // pgr_topological_sort( + // pgr_topologicalSort( // sql TEXT, process( @@ -139,7 +139,7 @@ topological_sort(PG_FUNCTION_ARGS) { funcctx = SRF_PERCALL_SETUP(); tuple_desc = funcctx->tuple_desc; - result_tuples = (pgr_topological_sort_t*) funcctx->user_fctx; + result_tuples = (pgr_topologicalSort_t*) funcctx->user_fctx; if (funcctx->call_cntr < funcctx->max_calls) { HeapTuple tuple; diff --git a/src/topological_sort/topological_sort_driver.cpp b/src/topologicalSort/topologicalSort_driver.cpp similarity index 82% rename from src/topological_sort/topological_sort_driver.cpp rename to src/topologicalSort/topologicalSort_driver.cpp index 7dc1a9b927..54dfa8d923 100644 --- a/src/topological_sort/topological_sort_driver.cpp +++ b/src/topologicalSort/topologicalSort_driver.cpp @@ -1,5 +1,5 @@ /*PGR-GNU***************************************************************** -File: topological_sort_driver.cpp +File: topologicalSort_driver.cpp Generated with Template by: Copyright (c) 2015 pgRouting developers @@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -#include "drivers/topological_sort/topological_sort_driver.h" +#include "drivers/topologicalSort/topologicalSort_driver.h" #include #include @@ -36,40 +36,40 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #if 0 -#include "topological_sort/pgr_topological_sort.hpp" +#include "topologicalSort/pgr_topologicalSort.hpp" #endif -//TODO(nike0good) : Remove below headers once pgr_topological_sort.hpp is implemented. +//TODO(nike0good) : Remove below headers once pgr_topologicalSort.hpp is implemented. #include "cpp_common/basePath_SSEC.hpp" #include "cpp_common/pgr_base_graph.hpp" -//TODO(nike0good) : Complete file once pgr_topological_sort.hpp is implemented. +//TODO(nike0good) : Complete file once pgr_topologicalSort.hpp is implemented. #include "cpp_common/pgr_alloc.hpp" #include "cpp_common/pgr_assert.h" template < class G > static -std::vector -pgr_topological_sort( +std::vector +pgr_topologicalSort( G &graph) { #if 0 - Pgr_topological_sort< G > fn_topological_sort; - return fn_topological_sort.topological_sort(graph); + Pgr_topologicalSort< G > fn_topologicalSort; + return fn_topologicalSort.topologicalSort(graph); #endif - std::vector vv; + std::vector vv; return vv; } -// CREATE OR REPLACE FUNCTION pgr_topological_sort( +// CREATE OR REPLACE FUNCTION pgr_topologicalSort( // sql text, void -do_pgr_topological_sort( +do_pgr_topologicalSort( pgr_edge_t *data_edges, size_t total_edges, - pgr_topological_sort_t **return_tuples, + pgr_topologicalSort_t **return_tuples, size_t *return_count, char ** log_msg, char ** notice_msg, @@ -88,12 +88,12 @@ do_pgr_topological_sort( graphType gType = DIRECTED; - std::vector results; + std::vector results; log << "Working with Directed Graph\n"; pgrouting::DirectedGraph digraph(gType); digraph.insert_edges(data_edges, total_edges); - results = pgr_topological_sort( + results = pgr_topologicalSort( digraph); auto count = results.size(); diff --git a/src/topological_sort/CMakeLists.txt b/src/topological_sort/CMakeLists.txt deleted file mode 100644 index 0f273c8b85..0000000000 --- a/src/topological_sort/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -ADD_LIBRARY(topological_sort OBJECT - topological_sort.c - - topological_sort_driver.cpp) From 53c485e470a43bbcb4c4d8a9486eb78d101e31b4 Mon Sep 17 00:00:00 2001 From: nike0good Date: Sat, 8 Jun 2019 16:12:05 +0800 Subject: [PATCH 2/7] [toposort] Add pgtap files --- .../topologicalSort/topologicalSort-innerQuery.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 pgtap/topologicalSort/topologicalSort-innerQuery.sql diff --git a/pgtap/topologicalSort/topologicalSort-innerQuery.sql b/pgtap/topologicalSort/topologicalSort-innerQuery.sql new file mode 100644 index 0000000000..ea85a62746 --- /dev/null +++ b/pgtap/topologicalSort/topologicalSort-innerQuery.sql @@ -0,0 +1,14 @@ +\i setup.sql + +SELECT plan(1); + +SELECT has_function('pgr_topologicalSort', + ARRAY['text']); + +SELECT function_returns('pgr_topologicalSort', + ARRAY['text'], + 'setof record'); + + +SELECT * FROM finish(); +ROLLBACK; From 78ceece73ecd612c84698ee8ea3451cc15732e5b Mon Sep 17 00:00:00 2001 From: nike0good Date: Sat, 8 Jun 2019 20:50:53 +0800 Subject: [PATCH 3/7] [toposort] fix plan time of innerQuery --- pgtap/topologicalSort/topologicalSort-innerQuery.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pgtap/topologicalSort/topologicalSort-innerQuery.sql b/pgtap/topologicalSort/topologicalSort-innerQuery.sql index ea85a62746..6358561219 100644 --- a/pgtap/topologicalSort/topologicalSort-innerQuery.sql +++ b/pgtap/topologicalSort/topologicalSort-innerQuery.sql @@ -1,6 +1,6 @@ \i setup.sql -SELECT plan(1); +SELECT plan(2); SELECT has_function('pgr_topologicalSort', ARRAY['text']); From ddb7d75e405627974b21db5ab8e74f51e2143c4d Mon Sep 17 00:00:00 2001 From: nike0good Date: Sun, 9 Jun 2019 21:36:01 +0800 Subject: [PATCH 4/7] [toposort] add hpp files. --- .../topologicalSort/topologicalSort_driver.h | 2 +- .../topologicalSort/pgr_topologicalSort.hpp | 121 ++++++++++++++++++ sql/topologicalSort/topologicalSort.sql | 7 +- .../topologicalSort_driver.cpp | 6 +- .../doc-topologicalSort.result | 0 .../doc-topologicalSort.test.sql | 31 +++++ test/topologicalSort/test.conf | 17 +++ 7 files changed, 175 insertions(+), 9 deletions(-) create mode 100644 include/topologicalSort/pgr_topologicalSort.hpp create mode 100644 test/topologicalSort/doc-topologicalSort.result create mode 100644 test/topologicalSort/doc-topologicalSort.test.sql create mode 100644 test/topologicalSort/test.conf diff --git a/include/drivers/topologicalSort/topologicalSort_driver.h b/include/drivers/topologicalSort/topologicalSort_driver.h index e0d6c4de04..9c7531d39e 100644 --- a/include/drivers/topologicalSort/topologicalSort_driver.h +++ b/include/drivers/topologicalSort/topologicalSort_driver.h @@ -62,4 +62,4 @@ extern "C" { } #endif -#endif // INCLUDE_DRIVERS_topologicalSort_DRIVER_H_ +#endif // INCLUDE_DRIVERS_TOPOLOGICALSORT_TOPOLOGICALSORT_DRIVER_H_ diff --git a/include/topologicalSort/pgr_topologicalSort.hpp b/include/topologicalSort/pgr_topologicalSort.hpp new file mode 100644 index 0000000000..9c2dd2a343 --- /dev/null +++ b/include/topologicalSort/pgr_topologicalSort.hpp @@ -0,0 +1,121 @@ +/*PGR-GNU***************************************************************** +File: pgr_topologicalSort.hpp + +Copyright (c) 2015 pgRouting developers +Mail: project@pgrouting.org + +Function's developer: +Copyright (c) 2019 Hang Wu +mail: nike0good@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_TOPOLOGICALSORT_PGR_TOPOLOGICALSORT_HPP_ +#define INCLUDE_TOPOLOGICALSORT_PGR_TOPOLOGICALSORT_HPP_ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "cpp_common/basePath_SSEC.hpp" +#include "cpp_common/pgr_base_graph.hpp" + +template < class G > class Pgr_topologicalSort; +// user's functions +// for development + +//****************************************** + +template < class G > +class Pgr_topologicalSort { + public: + typedef typename G::V V; + typedef typename G::E E; + typedef typename G::E_i E_i; + + std::vector topologicalSort( + G &graph); + + private: + std::vector< pgr_topologicalSort_t > + generatetopologicalSort( + const G &graph ) { + std::vector< pgr_topologicalSort_t > results; + + // auto parities = boost::make_one_bit_color_map( + // num_vertices(graph.graph), + // get(boost::vertex_index, graph.graph)); + + // double w = stoer_wagner_min_cut( + // graph.graph, + // get(&G::G_T_E::cost, graph.graph), + // boost::parity_map(parities)); + + // double totalcost = 0; + // E_i ei, ei_end; + // for (boost::tie(ei, ei_end) = edges(graph.graph); ei != ei_end; ei++) { + // auto s = source(*ei, graph.graph); + // auto t = target(*ei, graph.graph); + + // if (get(parities, s) != get(parities, t)) { + // pgr_topologicalSort_t tmp; + + // tmp.cost = graph[*ei].cost; + + // auto edge_id = + // graph.get_edge_id( + // source(*ei, graph.graph), + // target(*ei, graph.graph), + // tmp.cost); + + // tmp.edge = edge_id; + // totalcost += tmp.cost; + // tmp.mincut = totalcost; + // results.push_back(tmp); + // } + // } + + // pgassert(w == totalcost); + pgr_topologicalSort_t tmp; + tmp.seq=tmp.sorted_v=1; + results.push_back(v); + return results; + } +}; + +template < class G > +std::vector +Pgr_topologicalSort< G >::topologicalSort( + G &graph) { +// pgassert(num_vertices(graph.graph) > 1); + return generatetopologicalSort( + graph); +} + + +#endif // INCLUDE_TOPOLOGICALSORT_PGR_TOPOLOGICALSORT_HPP_ diff --git a/sql/topologicalSort/topologicalSort.sql b/sql/topologicalSort/topologicalSort.sql index 94889770d3..2f44c64497 100644 --- a/sql/topologicalSort/topologicalSort.sql +++ b/sql/topologicalSort/topologicalSort.sql @@ -35,12 +35,10 @@ CREATE OR REPLACE FUNCTION pgr_topologicalSort( OUT sorted_v INTEGER) RETURNS SETOF RECORD AS $BODY$ - SELECT a.seq, a.sorted_v - FROM _pgr_topologicalSort(_pgr_get_statement($1)) AS a; + SELECT * + FROM _pgr_topologicalSort(_pgr_get_statement($1)) ; $BODY$ LANGUAGE sql VOLATILE STRICT -COST 100 -ROWS 1000; -- COMMENTS @@ -53,4 +51,3 @@ IS 'pgr_topologicalSort - ${PGROUTING_DOC_LINK}/pgr_topologicalSort.html '; - diff --git a/src/topologicalSort/topologicalSort_driver.cpp b/src/topologicalSort/topologicalSort_driver.cpp index 54dfa8d923..916e60d9b8 100644 --- a/src/topologicalSort/topologicalSort_driver.cpp +++ b/src/topologicalSort/topologicalSort_driver.cpp @@ -51,12 +51,12 @@ static std::vector pgr_topologicalSort( G &graph) { -#if 0 + Pgr_topologicalSort< G > fn_topologicalSort; return fn_topologicalSort.topologicalSort(graph); -#endif +/* std::vector vv; - return vv; + return vv;*/ } diff --git a/test/topologicalSort/doc-topologicalSort.result b/test/topologicalSort/doc-topologicalSort.result new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/topologicalSort/doc-topologicalSort.test.sql b/test/topologicalSort/doc-topologicalSort.test.sql new file mode 100644 index 0000000000..21db5398c4 --- /dev/null +++ b/test/topologicalSort/doc-topologicalSort.test.sql @@ -0,0 +1,31 @@ +\echo -- q1 +SELECT * FROM pgr_topologicalSort( + 'SELECT id, source, target, cost, reverse_cost + FROM edge_table + WHERE id < 17' +); + +\echo -- q2 +SELECT * FROM pgr_topologicalSort( + 'SELECT id, source, target, cost, reverse_cost + FROM edge_table + WHERE id = 18' +); + +\echo -- q3 +SELECT * FROM pgr_topologicalSort( +$$ + SELECT id, source, target, cost, reverse_cost FROM edge_table + where source = any (ARRAY(SELECT node FROM pgr_connectedComponents( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table ') + WHERE component = 14) + ) + OR + target = any (ARRAY(SELECT node FROM pgr_connectedComponents( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table ') + WHERE component = 14) + ) +$$ + ); + +\echo -- q4 diff --git a/test/topologicalSort/test.conf b/test/topologicalSort/test.conf new file mode 100644 index 0000000000..46f7b0fb36 --- /dev/null +++ b/test/topologicalSort/test.conf @@ -0,0 +1,17 @@ +#!/usr/bin/perl -w + +%main::tests = ( + 'any' => { + 'comment' => 'topologicalSort algorithm tets.', + 'data' => [ ], + 'tests' => [qw( + doc-topologicalSort + )], + 'documentation' => [qw( + doc-topologicalSort + )] + }, + +); + +1; From 3bd820b62c426bb907efc6d8d41a413af18bb9d8 Mon Sep 17 00:00:00 2001 From: nike0good Date: Sun, 9 Jun 2019 22:09:39 +0800 Subject: [PATCH 5/7] [toposort] fix error of driver.cpp. --- src/topologicalSort/topologicalSort_driver.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/topologicalSort/topologicalSort_driver.cpp b/src/topologicalSort/topologicalSort_driver.cpp index 916e60d9b8..ed75e5f9e8 100644 --- a/src/topologicalSort/topologicalSort_driver.cpp +++ b/src/topologicalSort/topologicalSort_driver.cpp @@ -35,9 +35,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#if 0 +//#if 0 #include "topologicalSort/pgr_topologicalSort.hpp" -#endif +//#endif //TODO(nike0good) : Remove below headers once pgr_topologicalSort.hpp is implemented. #include "cpp_common/basePath_SSEC.hpp" #include "cpp_common/pgr_base_graph.hpp" From 5d76ad04eac425715668151707cbb58565cf9557 Mon Sep 17 00:00:00 2001 From: nike0good Date: Sun, 9 Jun 2019 22:57:15 +0800 Subject: [PATCH 6/7] [toposort] fix error of hpp file. --- include/topologicalSort/pgr_topologicalSort.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/topologicalSort/pgr_topologicalSort.hpp b/include/topologicalSort/pgr_topologicalSort.hpp index 9c2dd2a343..b579489118 100644 --- a/include/topologicalSort/pgr_topologicalSort.hpp +++ b/include/topologicalSort/pgr_topologicalSort.hpp @@ -103,7 +103,7 @@ class Pgr_topologicalSort { // pgassert(w == totalcost); pgr_topologicalSort_t tmp; tmp.seq=tmp.sorted_v=1; - results.push_back(v); + results.push_back(tmp); return results; } }; From 75c2cb30baa26b7638b3414a6032d1b5eadc9346 Mon Sep 17 00:00:00 2001 From: nike0good Date: Sun, 9 Jun 2019 23:38:19 +0800 Subject: [PATCH 7/7] [toposort] add queries files --- doc/queries/doc-topologicalSort.queries | 44 +++++++++++++++++++ .../doc-topologicalSort.result | 44 +++++++++++++++++++ .../doc-topologicalSort.test.sql | 4 ++ test/topologicalSort/test.conf | 2 +- 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 doc/queries/doc-topologicalSort.queries diff --git a/doc/queries/doc-topologicalSort.queries b/doc/queries/doc-topologicalSort.queries new file mode 100644 index 0000000000..80bbd23668 --- /dev/null +++ b/doc/queries/doc-topologicalSort.queries @@ -0,0 +1,44 @@ +BEGIN; +BEGIN +SET client_min_messages TO NOTICE; +SET +SELECT * FROM pgr_topologicalSort( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table' +); +ERROR: function pgr_topologicalsort(unknown) does not exist +LINE 1: SELECT * FROM pgr_topologicalSort( + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +-- q1 +SELECT * FROM pgr_topologicalSort( + 'SELECT id, source, target, cost, reverse_cost + FROM edge_table + WHERE id < 17' +); +ERROR: current transaction is aborted, commands ignored until end of transaction block +-- q2 +SELECT * FROM pgr_topologicalSort( + 'SELECT id, source, target, cost, reverse_cost + FROM edge_table + WHERE id = 18' +); +ERROR: current transaction is aborted, commands ignored until end of transaction block +-- q3 +SELECT * FROM pgr_topologicalSort( +$$ + SELECT id, source, target, cost, reverse_cost FROM edge_table + where source = any (ARRAY(SELECT node FROM pgr_connectedComponents( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table ') + WHERE component = 14) + ) + OR + target = any (ARRAY(SELECT node FROM pgr_connectedComponents( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table ') + WHERE component = 14) + ) +$$ + ); +ERROR: current transaction is aborted, commands ignored until end of transaction block +-- q4 +ROLLBACK; +ROLLBACK diff --git a/test/topologicalSort/doc-topologicalSort.result b/test/topologicalSort/doc-topologicalSort.result index e69de29bb2..a343387ddc 100644 --- a/test/topologicalSort/doc-topologicalSort.result +++ b/test/topologicalSort/doc-topologicalSort.result @@ -0,0 +1,44 @@ +BEGIN; +BEGIN +SET client_min_messages TO NOTICE; +SET +SELECT * FROM pgr_topologicalSort( + \'SELECT id, source, target, cost, reverse_cost FROM edge_table\' +); +ERROR: function pgr_topologicalsort(unknown) does not exist +LINE 1: SELECT * FROM pgr_topologicalSort( + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +-- q1 +SELECT * FROM pgr_topologicalSort( + \'SELECT id, source, target, cost, reverse_cost + FROM edge_table + WHERE id < 17\' +); +ERROR: current transaction is aborted, commands ignored until end of transaction block +-- q2 +SELECT * FROM pgr_topologicalSort( + \'SELECT id, source, target, cost, reverse_cost + FROM edge_table + WHERE id = 18\' +); +ERROR: current transaction is aborted, commands ignored until end of transaction block +-- q3 +SELECT * FROM pgr_topologicalSort( +$$ + SELECT id, source, target, cost, reverse_cost FROM edge_table + where source = any (ARRAY(SELECT node FROM pgr_connectedComponents( + \'SELECT id, source, target, cost, reverse_cost FROM edge_table \') + WHERE component = 14) + ) + OR + target = any (ARRAY(SELECT node FROM pgr_connectedComponents( + \'SELECT id, source, target, cost, reverse_cost FROM edge_table \') + WHERE component = 14) + ) +$$ + ); +ERROR: current transaction is aborted, commands ignored until end of transaction block +-- q4 +ROLLBACK; +ROLLBACK \ No newline at end of file diff --git a/test/topologicalSort/doc-topologicalSort.test.sql b/test/topologicalSort/doc-topologicalSort.test.sql index 21db5398c4..150245355b 100644 --- a/test/topologicalSort/doc-topologicalSort.test.sql +++ b/test/topologicalSort/doc-topologicalSort.test.sql @@ -1,3 +1,7 @@ +SELECT * FROM pgr_topologicalSort( + 'SELECT id, source, target, cost, reverse_cost FROM edge_table' +); + \echo -- q1 SELECT * FROM pgr_topologicalSort( 'SELECT id, source, target, cost, reverse_cost diff --git a/test/topologicalSort/test.conf b/test/topologicalSort/test.conf index 46f7b0fb36..1843c3d68c 100644 --- a/test/topologicalSort/test.conf +++ b/test/topologicalSort/test.conf @@ -2,7 +2,7 @@ %main::tests = ( 'any' => { - 'comment' => 'topologicalSort algorithm tets.', + 'comment' => 'topologicalSort algorithm tests.', 'data' => [ ], 'tests' => [qw( doc-topologicalSort