Skip to content

Commit 8d1149f

Browse files
committed
[mst] organizing sql files & function names
1 parent 544b702 commit 8d1149f

11 files changed

Lines changed: 91 additions & 57 deletions

File tree

include/mst/pgr_randomSpanningTree.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3232
#include <boost/graph/graph_traits.hpp>
3333

3434
#include <vector>
35+
#include <random>
3536
#include <iostream>
3637
#include <exception>
3738

sql/mst/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11

22
SET(LOCAL_FILES
3-
kruskal.sql
43
_prim.sql
4+
_kruskal.sql
5+
#_randomSpanTree.sql
6+
57
prim.sql
6-
prim.sql
8+
kruskal.sql
9+
#randomSpanTree.sql
710
)
811

912
# Do not modify bellow this line

sql/mst/_kruskal.sql

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*PGR-GNU*****************************************************************
2+
File: kruskal.sql
3+
4+
Generated with Template by:
5+
Copyright (c) 2016 pgRouting developers
6+
7+
8+
Function's developer:
9+
Copyright (c) 2018 Aditya Pratap Singh
10+
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+
CREATE OR REPLACE FUNCTION _pgr_kruskal(
31+
TEXT, -- Edge sql
32+
33+
OUT seq INTEGER, -- Seq
34+
OUT component BIGINT, -- the lowest number of the node in the component
35+
OUT edge BIGINT, -- Edge linked to that node
36+
OUT cost FLOAT, -- Cost of edge
37+
OUT tree_cost FLOAT) -- Spanning tree cost
38+
RETURNS SETOF RECORD AS
39+
'MODULE_PATHNAME', 'kruskal'
40+
LANGUAGE C VOLATILE STRICT;

sql/mst/_prim.sql

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2828
********************************************************************PGR-GNU*/
2929

3030
CREATE OR REPLACE FUNCTION _pgr_prim(
31-
edges_sql TEXT, -- Edge sql
32-
root_vertex BIGINT, -- Root vertex
33-
use_root BOOLEAN, -- Use root_vertex
31+
TEXT, -- Edge sql
32+
BIGINT, -- Root vertex
3433

3534
OUT seq INTEGER, -- Seq
3635
Out root_vertex BIGINT, -- Root_vertex
@@ -41,4 +40,4 @@ CREATE OR REPLACE FUNCTION _pgr_prim(
4140
OUT tree_cost FLOAT) -- Spanning tree cost
4241
RETURNS SETOF RECORD AS
4342
'MODULE_PATHNAME', 'prim'
44-
LANGUAGE c VOLATILE STRICT;
43+
LANGUAGE C VOLATILE STRICT;
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2727
2828
********************************************************************PGR-GNU*/
2929

30-
CREATE OR REPLACE FUNCTION _pgr_randomSpanningTree(
31-
edges_sql TEXT, -- Edge sql
32-
root BIGINT,
33-
directed BOOLEAN,
34-
use_component BOOLEAN,
30+
CREATE OR REPLACE FUNCTION _pgr_randomSpanTree(
31+
TEXT, -- Edge sql
32+
BIGINT, -- Root
33+
BOOLEAN, -- directed
34+
BOOLEAN, -- use_component
3535

3636
OUT seq INTEGER, -- Seq
3737
OUT root_vertex BIGINT, -- Root_vetex
@@ -40,4 +40,4 @@ CREATE OR REPLACE FUNCTION _pgr_randomSpanningTree(
4040
OUT tree_cost FLOAT) -- Spanning tree cost
4141
RETURNS SETOF RECORD AS
4242
'MODULE_PATHNAME', 'randomSpanningTree'
43-
LANGUAGE c VOLATILE STRICT;
43+
LANGUAGE C VOLATILE STRICT;

sql/mst/kruskal.sql

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2828
********************************************************************PGR-GNU*/
2929

3030
CREATE OR REPLACE FUNCTION pgr_kruskal(
31-
edges_sql TEXT, -- Edge sql
31+
TEXT, -- Edge sql
3232

3333
OUT seq INTEGER, -- Seq
3434
OUT component BIGINT, -- the lowest number of the node in the component
3535
OUT edge BIGINT, -- Edge linked to that node
3636
OUT cost FLOAT, -- Cost of edge
3737
OUT tree_cost FLOAT) -- Spanning tree cost
3838
RETURNS SETOF RECORD AS
39-
'MODULE_PATHNAME', 'kruskal'
40-
LANGUAGE c VOLATILE STRICT;
39+
$BODY$
40+
SELECT *
41+
FROM _pgr_kruskal(_pgr_get_statement($1));
42+
$BODY$
43+
LANGUAGE SQL VOLATILE STRICT;
44+
45+
COMMENT ON FUNCTION pgr_kruskal(TEXT) IS 'pgr_kruskal(edge_sql): Experimental, Undirected Graph';

sql/mst/prim.sql

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2727
2828
********************************************************************PGR-GNU*/
2929

30+
-----------------------------------
31+
-- pgr_prim
32+
-----------------------------------
3033

3134

3235
CREATE OR REPLACE FUNCTION pgr_prim(
33-
edges_sql TEXT,
36+
TEXT, -- edges_sql
37+
BIGINT DEFAULT 0,
3438

3539
OUT seq INTEGER, -- Seq
36-
Out root_vertex BIGINT, -- Root_vertex
40+
Out root_vertex BIGINT, -- Root_vertex
3741
OUT node BIGINT, -- node of lightest weight
3842
OUT edge BIGINT, -- Edge linked to that node
3943
OUT cost FLOAT, -- Cost of edge
@@ -42,27 +46,8 @@ CREATE OR REPLACE FUNCTION pgr_prim(
4246
RETURNS SETOF RECORD AS
4347
$BODY$
4448
SELECT *
45-
FROM _pgr_prim(_pgr_get_statement($1), CAST(0 AS BIGINT), FALSE);
49+
FROM _pgr_prim(_pgr_get_statement($1), $2);
4650
$BODY$
4751
LANGUAGE sql VOLATILE STRICT;
4852

49-
CREATE OR REPLACE FUNCTION pgr_prim(
50-
edges_sql TEXT,
51-
root_vertex BIGINT,
52-
53-
OUT seq INTEGER, -- Seq
54-
Out root_vertex BIGINT, -- Root_vertex
55-
OUT node BIGINT, -- node of lightest weight
56-
OUT edge BIGINT, -- Edge linked to that node
57-
OUT cost FLOAT, -- Cost of edge
58-
OUT agg_cost FLOAT, -- Cost from root_vertex to node
59-
OUT tree_cost FLOAT) -- Spanning tree cost
60-
RETURNS SETOF RECORD AS
61-
$BODY$
62-
SELECT *
63-
FROM _pgr_prim(_pgr_get_statement($1), $2, TRUE);
64-
$BODY$
65-
LANGUAGE sql VOLATILE STRICT;
66-
67-
COMMENT ON FUNCTION pgr_prim(TEXT) IS 'pgr_prim()';
68-
COMMENT ON FUNCTION pgr_prim(TEXT, BIGINT) IS 'pgr_prim(use root vertex)';
53+
COMMENT ON FUNCTION pgr_prim(TEXT, BIGINT) IS 'pgr_prim: Undirected Graph only';
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,33 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2727
2828
********************************************************************PGR-GNU*/
2929

30-
CREATE OR REPLACE FUNCTION pgr_randomSpanningTree(
30+
CREATE OR REPLACE FUNCTION pgr_randomSpanTree(
3131
edges_sql TEXT, -- Edge sql
3232
root BIGINT,
33-
directed BOOLEAN,
33+
directed BOOLEAN DEFAULT TRUE,
3434

3535
OUT seq INTEGER, -- Seq
3636
OUT root_vertex BIGINT,
3737
OUT edge BIGINT, -- Edge linked to that node
3838
OUT cost FLOAT, -- Cost of edge
39-
OUT tree_cost FLOAT) -- Spanning tree cost
39+
OUT tree_cost FLOAT) -- Spanning tree cost
4040
RETURNS SETOF RECORD AS
4141
$BODY$
4242
DECLARE
4343
connectedComponent BIGINT;
4444
BEGIN
45-
SELECT COUNT(DISTINCT component) INTO connectedComponent
46-
FROM pgr_connectedComponents(
47-
'SELECT id, source, target, cost, reverse_cost
48-
FROM edge_table'
49-
);
45+
SELECT COUNT(DISTINCT component) INTO connectedComponent
46+
FROM pgr_connectedComponents(
47+
'SELECT id, source, target, cost, reverse_cost
48+
FROM edge_table'
49+
);
5050

51-
IF (connectedComponent == 1)THEN
51+
IF (connectedComponent = 1) THEN
5252
SELECT *
53-
FROM _pgr_randomSpanningTreee(_pgr_get_statement($1), $2, $3, TRUE);
54-
ELSE
53+
FROM _pgr_randomSpanTree(_pgr_get_statement($1), $2, $3, TRUE);
54+
ELSE
5555
SELECT *
56-
FROM _pgr_randomSpanningTreee(_pgr_get_statement($1), $2, $3, FALSE);
56+
FROM _pgr_randomSpanTree(_pgr_get_statement($1), $2, $3, FALSE);
5757
END IF;
5858
END;
5959
$BODY$

sql/sigs/pgrouting--3.0.0.sig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ _pgr_iscolumnindexed(text,text,integer,text)
106106
_pgr_iscolumnindexed(text,text,text,integer,text)
107107
_pgr_iscolumnintable(text,text)
108108
pgr_johnson(text,boolean)
109+
_pgr_kruskal(text)
109110
pgr_kruskal(text)
110111
pgr_ksp(text,bigint,bigint,integer,boolean,boolean)
111112
pgr_linegraphfull(text)
@@ -134,9 +135,8 @@ _pgr_pickdelivereuclidean(text,text,double precision,integer,integer)
134135
_pgr_pickdeliver(text,text,text,double precision,integer,integer)
135136
pgr_pointsaspolygon(character varying,double precision)
136137
_pgr_pointtoid(geometry,double precision,text,integer)
137-
pgr_prim(text)
138+
_pgr_prim(text,bigint)
138139
pgr_prim(text,bigint)
139-
_pgr_prim(text,bigint,boolean)
140140
pgr_pushrelabel(text,anyarray,anyarray)
141141
pgr_pushrelabel(text,anyarray,bigint)
142142
pgr_pushrelabel(text,bigint,anyarray)

src/mst/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
ADD_LIBRARY(mst OBJECT
22
kruskal.c
33
kruskal_driver.cpp
4+
45
prim.c
56
prim_driver.cpp
7+
8+
#randomSpanningTree.c
9+
#randomSpanningTree_driver.cpp
610
)

0 commit comments

Comments
 (0)