Skip to content

pgr_transitiveClosure GSOC-2019 week 11 #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
767f202
[transitiveClosure] recover transitiveClosure. 2
Aug 5, 2019
77d861e
[transitiveClosure] Update hpp file.
Aug 5, 2019
220daec
[transitiveClosure] Add pgtap file.
Aug 6, 2019
e80be18
[transitiveClosure] Add sigs file.
Aug 6, 2019
0e445f2
[transitiveClosure] Fix bugs of transitiveClosure_driver.h
Aug 6, 2019
0fc322e
[transitiveClosure] Comment code.
Aug 6, 2019
44808b5
[transitiveClosure] Update no_crash_test-transitiveClosure.sql.
Aug 6, 2019
1b04edb
[transitiveClosure] Modify plan number of no_crash_test-transitiveClo…
Aug 6, 2019
4447920
[transitiveClosure] ERROR: function no_crash_test(unknown, text[]) d…
Aug 6, 2019
f4ba485
[transitiveClosure] Add docqueries files.
Aug 6, 2019
f5ff2a1
[transitiveClosure] Update pgtap file.
Aug 6, 2019
a804ac2
[transitiveClosure] Update pgtap file again.
Aug 6, 2019
ece8687
[transitiveClosure] Update no_crash_test-transitiveClosure.sql.
Aug 6, 2019
741a5ad
[transitiveClosure] Add doc-transitiveClosure.result.
Aug 6, 2019
210d31f
[transitiveClosure] Update no_crash_test.
Aug 6, 2019
4e577a4
[lint] code quality check.
Aug 6, 2019
4ea028a
[transitiveClosure] Add doc files.
Aug 6, 2019
c33c053
[transitiveClosure] Update doc files.
Aug 7, 2019
bec00ab
[transitiveClosure] Modify configuration.conf.
Aug 7, 2019
ac7ca38
[transitiveClosure] Modify configuration.conf again.
Aug 7, 2019
ca659d7
[transitiveClosure] Fix pgtap bugs.
Aug 7, 2019
e3f2745
[transitiveClosure] Checkout sigs file again and add pgr_transitivecl…
Aug 7, 2019
9e2237f
[transitiveClosure] Update configuration.conf.
Aug 7, 2019
a1d070a
[transitiveClosure] MODULE_PATHNAME change.
Aug 7, 2019
cdd1a0e
[transitiveClosure] MODULE_PATHNAME change 2.
Aug 7, 2019
1476e91
[transitiveClosure] Update doc.
Aug 9, 2019
8426e5c
[toposort] Update comment.
Aug 10, 2019
e586227
[toposort] Update driver file.
Aug 11, 2019
ae6b529
[Doc] Add Availability.
Aug 11, 2019
a6f5b6c
[Doc] Add Availability. 2
Aug 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions configuration.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ chinese | Y | Y | Y
spanningTree | Y | Y | Y
mincut | Y | Y | Y
version | Y | Y | Y
topologicalSort | Y | Y | Y
#transitiveClosure | Y | Y | N
topologicalSort | Y | Y | Y
transitiveClosure | Y | Y | Y


#----------------------
Expand Down
29 changes: 13 additions & 16 deletions doc/topologicalSort/pgr_topologicalSort.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ In particular, the topological sort algorithm implemented by Boost.Graph.

.. rubric:: Availability

* Version 3.0.0

* New **experimental** function

.. rubric:: Support

* **Supported versions:**
current(`3.0 <https://docs.pgrouting.org/dev/en/pgr_topologicalSort.html>`__)

* **TBD**

Description
Expand All @@ -35,8 +44,7 @@ in the graph, then v comes before u in the ordering.
This implementation can only be used with a **directed** graph with no cycles i.e. directed acyclic graph.

The main characteristics are:
- Process is valid for weighted directed acyclic graphs only. otherwise it will throw warnings.
- Values are returned when there is a path.
- Process is valid for directed acyclic graphs only. otherwise it will throw warnings.

- For optimization purposes, if there are more than one answer, the function will return one of them.

Expand All @@ -57,22 +65,11 @@ Signatures
RETURNS SET OF (seq, sorted_v)
OR EMPTY SET


.. index::
single: topologicalSort(One to One) - Experimental

One to One
...............................................................................

.. code-block:: none

pgr_dagShortestPath(edges_sql)
RETURNS SET OF (seq, sorted_v)
OR EMPTY SET

:Example: From vertex :math:`1` to vertex :math:`6`
:Example: For a **directed** graph

.. literalinclude:: doc-pgr_topologicalSort.queries
:start-after: -- q1
:end-before: -- q2

Parameters
-------------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions doc/transitiveClosure/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

SET(LOCAL_FILES
pgr_transitiveClosure.rst
)

foreach (f ${LOCAL_FILES})
configure_file(${f} "${PGR_DOCUMENTATION_SOURCE_DIR}/${f}")
list(APPEND LOCAL_DOC_FILES ${PGR_DOCUMENTATION_SOURCE_DIR}/${f})
endforeach()

set(PGROUTING_DOC_FILES ${PGROUTING_DOC_FILES} ${LOCAL_DOC_FILES} PARENT_SCOPE)

122 changes: 122 additions & 0 deletions doc/transitiveClosure/pgr_transitiveClosure.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
..
****************************************************************************
pgRouting Manual
Copyright(c) pgRouting Contributors

This documentation is licensed under a Creative Commons Attribution-Share
Alike 3.0 License: https://creativecommons.org/licenses/by-sa/3.0/
****************************************************************************

pgr_transitiveClosure
===============================================================================

``pgr_transitiveClosure`` — Returns the transitive closure graph of the input graph.
In particular, the transitive closure algorithm implemented by Boost.Graph.

.. figure:: images/boost-inside.jpeg
:target: https://www.boost.org/doc/libs/1_70_0/libs/graph/doc/transitive_closure.html

Boost Graph Inside

.. include:: proposed.rst
:start-after: begin-warn-expr
:end-before: end-warn-expr

.. rubric:: Availability

* Version 3.0.0

* New **experimental** function

.. rubric:: Support

* **Supported versions:**
current(`3.0 <https://docs.pgrouting.org/dev/en/pgr_transitiveClosure.html>`__)

Description
-------------------------------------------------------------------------------

The transitive_closure() function transforms the input graph g into the transitive closure graph tc.

This implementation can only be used with a **directed** graph with no cycles i.e. directed acyclic graph.

The main characteristics are:
- Process is valid for directed acyclic graphs only. otherwise it will throw warnings.

- The returned values are not ordered:

* Running time: :math:`O(|V||E|)`


Signatures
-------------------------------------------------------------------------------

.. rubric:: Summary

The pgr_transitiveClosure function has the following signature:

.. index::
single: transitiveClosure

.. code-block:: none

pgr_transitiveClosure(Edges SQL)
RETURNS SETOF (id, vid, target_array)

:Example: Complete Graph of 3 vertexs

.. literalinclude:: doc-pgr_transitiveClosure.queries
:start-after: -- q1
:end-before: -- q2

Parameters
-------------------------------------------------------------------------------

======================= ====================== =================================================
Column Type Description
======================= ====================== =================================================
**Edges SQL** ``TEXT`` SQL query as described in `Inner query`_
======================= ====================== =================================================

Inner query
-------------------------------------------------------------------------------

.. include:: pgRouting-concepts.rst
:start-after: basic_edges_sql_start
:end-before: basic_edges_sql_end

Result Columns
-------------------------------------------------------------------------------

RETURNS SETOF (seq, vid, target_array)

The function returns a single row. The columns of the row are:

============================ ================= ===================================================================
Column Type Description
============================ ================= ===================================================================
**seq** ``INTEGER`` Sequential value starting from **1**.
**vid** ``BIGINT`` Identifier of the vertex.
**target_array** ``ARRAY[BIGINT]`` Array of identifiers of the vertices that are reachable from vertex v.
============================ ================= ===================================================================

Additional Examples
-------------------------------------------------------------------------------

:Example: Some sub graphs of the sample data

.. literalinclude:: doc-pgr_transitiveClosure.queries
:start-after: -- q2
:end-before: -- q4


See Also
-------------------------------------------------------------------------------

* https://en.wikipedia.org/wiki/Transitive_closure
* The queries use the :doc:`sampledata` network.

.. rubric:: Indices and tables

* :ref:`genindex`
* :ref:`search`
11 changes: 11 additions & 0 deletions docqueries/transitiveClosure/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Do not use extensions
SET(LOCAL_FILES
doc-transitiveClosure
)

foreach (f ${LOCAL_FILES})
configure_file("${f}.result" "${PGR_DOCUMENTATION_SOURCE_DIR}/${f}.queries")
list(APPEND LOCAL_DOC_FILES "${PGR_DOCUMENTATION_SOURCE_DIR}/${f}.queries")
endforeach()

set(PGROUTING_DOC_FILES ${PGROUTING_DOC_FILES} ${LOCAL_DOC_FILES} PARENT_SCOPE)
92 changes: 92 additions & 0 deletions docqueries/transitiveClosure/doc-transitiveClosure.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
BEGIN;
BEGIN
SET client_min_messages TO NOTICE;
SET
CREATE TABLE edge_table1 (
id serial,
source integer,
target integer,
cost double precision,
reverse_cost double precision
);
CREATE TABLE
INSERT INTO edge_table1 (source,target,cost,reverse_cost) VALUES (0,1,1,-1);
INSERT 0 1
INSERT INTO edge_table1 (source,target,cost,reverse_cost) VALUES (0,3,1,-1);
INSERT 0 1
INSERT INTO edge_table1 (source,target,cost,reverse_cost) VALUES (0,2,1,-1);
INSERT 0 1
INSERT INTO edge_table1 (source,target,cost,reverse_cost) VALUES (1,3,1,-1);
INSERT 0 1
INSERT INTO edge_table1 (source,target,cost,reverse_cost) VALUES (1,2,1,-1);
INSERT 0 1
INSERT INTO edge_table1 (source,target,cost,reverse_cost) VALUES (3,2,1,-1);
INSERT 0 1
-- q1
SELECT * FROM pgr_transitiveclosure(
'SELECT id,source,target,cost,reverse_cost FROM edge_table1'
);
seq | vid | target_array
-----+-----+--------------
1 | 0 | {1,3,2}
2 | 1 | {3,2}
3 | 3 | {2}
4 | 2 | {}
(4 rows)

-- q2
SELECT * FROM pgr_transitiveclosure(
'SELECT id,source,target,cost,reverse_cost FROM edge_table where id=2'
);
seq | vid | target_array
-----+-----+--------------
1 | 2 | {}
2 | 3 | {2}
(2 rows)

SELECT * FROM pgr_transitiveclosure(
'SELECT id,source,target,cost,reverse_cost FROM edge_table where id=3'
);
seq | vid | target_array
-----+-----+--------------
1 | 3 | {}
2 | 4 | {3}
(2 rows)

SELECT * FROM pgr_transitiveclosure(
'SELECT id,source,target,cost,reverse_cost FROM edge_table where id=2 or id=3'
);
seq | vid | target_array
-----+-----+--------------
1 | 2 | {}
2 | 3 | {2}
3 | 4 | {3,2}
(3 rows)

SELECT * FROM pgr_transitiveclosure(
'SELECT id,source,target,cost,reverse_cost FROM edge_table where id=11'
);
seq | vid | target_array
-----+-----+--------------
1 | 6 | {11}
2 | 11 | {}
(2 rows)

-- q3
SELECT * FROM pgr_transitiveclosure(
'SELECT id,source,target,cost,reverse_cost FROM edge_table where cost=-1 or reverse_cost=-1'
);
seq | vid | target_array
-----+-----+---------------
1 | 2 | {}
2 | 3 | {11,12,6,2}
3 | 4 | {11,12,3,6,2}
4 | 6 | {11,12}
5 | 11 | {12}
6 | 10 | {11,12}
7 | 12 | {}
(7 rows)

-- q4
ROLLBACK;
ROLLBACK
45 changes: 45 additions & 0 deletions docqueries/transitiveClosure/doc-transitiveClosure.test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
CREATE TABLE edge_table1 (
id serial,
source integer,
target integer,
cost double precision,
reverse_cost double precision
);
INSERT INTO edge_table1 (source,target,cost,reverse_cost) VALUES (0,1,1,-1);
INSERT INTO edge_table1 (source,target,cost,reverse_cost) VALUES (0,3,1,-1);
INSERT INTO edge_table1 (source,target,cost,reverse_cost) VALUES (0,2,1,-1);
INSERT INTO edge_table1 (source,target,cost,reverse_cost) VALUES (1,3,1,-1);
INSERT INTO edge_table1 (source,target,cost,reverse_cost) VALUES (1,2,1,-1);
INSERT INTO edge_table1 (source,target,cost,reverse_cost) VALUES (3,2,1,-1);

\echo -- q1

SELECT * FROM pgr_transitiveclosure(
'SELECT id,source,target,cost,reverse_cost FROM edge_table1'
);

\echo -- q2

SELECT * FROM pgr_transitiveclosure(
'SELECT id,source,target,cost,reverse_cost FROM edge_table where id=2'
);
SELECT * FROM pgr_transitiveclosure(
'SELECT id,source,target,cost,reverse_cost FROM edge_table where id=3'
);

SELECT * FROM pgr_transitiveclosure(
'SELECT id,source,target,cost,reverse_cost FROM edge_table where id=2 or id=3'
);

SELECT * FROM pgr_transitiveclosure(
'SELECT id,source,target,cost,reverse_cost FROM edge_table where id=11'
);

\echo -- q3

SELECT * FROM pgr_transitiveclosure(
'SELECT id,source,target,cost,reverse_cost FROM edge_table where cost=-1 or reverse_cost=-1'
);


\echo -- q4
17 changes: 17 additions & 0 deletions docqueries/transitiveClosure/test.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/perl -w

%main::tests = (
'any' => {
'comment' => 'transitiveClosure algorithm tests.',
'data' => [ ],
'tests' => [qw(
doc-transitiveClosure
)],
'documentation' => [qw(
doc-transitiveClosure
)]
},

);

1;
7 changes: 4 additions & 3 deletions include/c_types/transitiveClosure_rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* return type for contraction
* ***********************************************************************/
typedef struct {
int64_t id;
int64_t *transitiveClosure_vertices;
int transitiveClosure_vertices_size;
int seq;
int64_t vid;
int64_t *target_array;
int target_array_size;
} transitiveClosure_rt;

#endif // INCLUDE_C_TYPES_TRANSITIVECLOSURE_RT_H_
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extern "C" {

********************************************************/
void
do_pgr_contractGraph(
do_pgr_transitiveClosure(
pgr_edge_t *data_edges,
size_t total_tuples,
transitiveClosure_rt **return_tuples,
Expand Down
Loading