Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions configuration.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ common | Y | Y | Y
# Has the command needed to link with prostgresl
#----------------------
dijkstra | Y | Y | Y
funnyDijkstra | Y | Y | Y
allpairs | Y | Y | Y
astar | Y | Y | Y
driving_distance | Y | Y | Y
Expand Down
13 changes: 13 additions & 0 deletions doc/funnyDijkstra/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

SET(LOCAL_FILES
pgr_funnyDijkstra.rst
doc-pgr_funnyDijkstra.queries
)

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)

32 changes: 32 additions & 0 deletions doc/funnyDijkstra/doc-pgr_funnyDijkstra.queries
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
BEGIN;
BEGIN
-- q1
SELECT * FROM pgr_funnyDijkstra(
'SELECT id, source, target, cost, reverse_cost FROM edge_table',
2, 3
);
seq | path_seq | node | edge | cost | agg_cost
-----+----------+------+------+------+----------
1 | 1 | 2 | 4 | 1 | 0
2 | 2 | 5 | 8 | 1 | 1
3 | 3 | 6 | 9 | 1 | 2
4 | 4 | 9 | 16 | 1 | 3
5 | 5 | 4 | 3 | 1 | 4
6 | 6 | 3 | -1 | 0 | 5
(6 rows)

-- q2
SELECT * FROM pgr_funnyDijkstra(
'SELECT id, source, target, cost, reverse_cost FROM edge_table',
2, 3,
FALSE
);
seq | path_seq | node | edge | cost | agg_cost
-----+----------+------+------+------+----------
1 | 1 | 2 | 2 | 1 | 0
2 | 2 | 3 | -1 | 0 | 1
(2 rows)

-- q3
ROLLBACK;
ROLLBACK
141 changes: 141 additions & 0 deletions doc/funnyDijkstra/pgr_funnyDijkstra.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
..
****************************************************************************
pgRouting Manual
Copyright(c) pgRouting Contributors

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

.. _pgr_funnyDijkstra:

pgr_funnyDijkstra
===============================================================================

``pgr_funnyDijkstra`` — Returns the shortest path(s) using Dijkstra algorithm.
In particular, the Dijkstra algorithm implemented by Boost.Graph.

.. figure:: images/boost-inside.jpeg
:target: http://www.boost.org/libs/graph/doc/dijkstra_shortest_paths.html

Boost Graph Inside


Synopsis
-------------------------------------------------------------------------------

Dijkstra's algorithm, conceived by Dutch computer scientist Edsger Dijkstra in 1956.
It is a graph search algorithm that solves the shortest path problem for
a graph with non-negative edge path costs, producing a shortest path from
a starting vertex (``start_vid``) to an ending vertex (``end_vid``).
This implementation can be used with a directed graph and an undirected graph.

Characteristics
-------------------------------------------------------------------------------

The main Characteristics are:
- Process is done only on edges with positive costs.
- Values are returned when there is a path.

- When the starting vertex and ending vertex are the same, there is no path.

- The `agg_cost` the non included values `(v, v)` is `0`

- When the starting vertex and ending vertex are the different and there is no path:

- The `agg_cost` the non included values `(u, v)` is :math:`\infty`

- For optimization purposes, any duplicated value in the `start_vids` or `end_vids` are ignored.

- The returned values are ordered:

- `start_vid` ascending
- `end_vid` ascending

- Running time: :math:`O(| start\_vids | * (V \log V + E))`


Signature Summary
-----------------

.. code-block:: none

pgr_dijkstra(edges_sql, start_vid, end_vid)

RETURNS SET OF (seq, path_seq, node, edge, cost, agg_cost)
OR EMPTY SET


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

.. index::
single: funnyDijkstra(Minimal Use)

Minimal signature
.......................................

.. code-block:: none

pgr_funnyDijkstra(edges_sql, start_vid, end_vid)
RETURNS SET OF (seq, path_seq, node, edge, cost, agg_cost) or EMPTY SET

The minimal signature is for a **directed** graph from one ``start_vid`` to one ``end_vid``:

:Example:

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


.. index::
single: funnyDijkstra(Complete signature)

Complete Signature
.......................................

.. code-block:: none

pgr_funnyDijkstra(edges_sql, start_vid, end_vid, directed);
RETURNS SET OF (seq, path_seq, node, edge, cost, agg_cost) or EMPTY SET

This signature finds the shortest path from one ``start_vid`` to one ``end_vid``:
- on a **directed** graph when ``directed`` flag is missing or is set to ``true``.
- on an **undirected** graph when ``directed`` flag is set to ``false``.

:Example:

.. literalinclude:: doc-pgr_funnyDijkstra.queries
:start-after: -- q2
:end-before: -- q3



Description of the Signatures
-------------------------------------------------------------------------------

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

.. include:: pgr_dijkstra.rst
:start-after: pgr_dijkstra_parameters_start
:end-before: pgr_dijkstra_parameters_end

.. include:: pgRouting-concepts.rst
:start-after: return_path_start
:end-before: return_path_end


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

* http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
* The queries use the :ref:`sampledata` network.

.. rubric:: Indices and tables

* :ref:`genindex`
* :ref:`search`

69 changes: 69 additions & 0 deletions include/drivers/funnyDijkstra/funnyDijkstra_driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*PGR-GNU*****************************************************************
File: funnyDijkstra_driver.h

Generated with Template by:
Copyright (c) 2015 pgRouting developers
Mail: [email protected]

Function's developer:
Copyright (c) 2015 Celia Virginia Vergara Castillo
Mail: [email protected]

------

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_FUNNYDIJKSTRA_FUNNYDIJKSTRA_DRIVER_H_
#define INCLUDE_DRIVERS_FUNNYDIJKSTRA_FUNNYDIJKSTRA_DRIVER_H_
#pragma once

#include "c_types/pgr_edge_t.h"
#include "c_types/general_path_element_t.h"

#ifdef __cplusplus
extern "C" {
#endif

/*********************************************************
TEXT,
BIGINT,
BIGINT,
directed BOOLEAN DEFAULT true,
only_cost BOOLEAN DEFAULT false,
********************************************************/


void
do_pgr_funnyDijkstra(
pgr_edge_t *data_edges,
size_t total_edges,
int64_t start_vid,
int64_t end_vid,
bool directed,
bool only_cost,
General_path_element_t **return_tuples,
size_t *return_count,
char ** log_msg,
char ** notice_msg,
char ** err_msg);


#ifdef __cplusplus
}
#endif

#endif // INCLUDE_DRIVERS_FUNNYDIJKSTRA_FUNNYDIJKSTRA_DRIVER_H_
73 changes: 73 additions & 0 deletions pgtap/funnyDijkstra/funnyDijkstra-compare-dijkstra.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
\i setup.sql

SELECT plan(1156);

SET client_min_messages TO ERROR;

UPDATE edge_table SET cost = cost + 0.001 * id * id, reverse_cost = reverse_cost + 0.001 * id * id;

CREATE or REPLACE FUNCTION funnydijkstra_compare_dijkstra(cant INTEGER default 17)
RETURNS SETOF TEXT AS
$BODY$
DECLARE
inner_sql TEXT;
dijkstra_sql TEXT;
funnydijkstra_sql TEXT;
BEGIN

FOR i IN 1.. cant LOOP
FOR j IN 1.. cant LOOP

-- DIRECTED
inner_sql := 'SELECT id, source, target, cost, reverse_cost FROM edge_table';
dijkstra_sql := 'SELECT * FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
|| ', true)';

funnydijkstra_sql := 'SELECT * FROM pgr_funnydijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
|| ', true)';
RETURN query SELECT set_eq(funnydijkstra_sql, dijkstra_sql, funnydijkstra_sql);


inner_sql := 'SELECT id, source, target, cost FROM edge_table';
dijkstra_sql := 'SELECT * FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
|| ', true)';

funnydijkstra_sql := 'SELECT * FROM pgr_funnydijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
|| ', true)';
RETURN query SELECT set_eq(funnydijkstra_sql, dijkstra_sql, funnydijkstra_sql);



-- UNDIRECTED
inner_sql := 'SELECT id, source, target, cost, reverse_cost FROM edge_table';
dijkstra_sql := 'SELECT * FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
|| ', false)';

funnydijkstra_sql := 'SELECT * FROM pgr_funnydijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
|| ', false)';
RETURN query SELECT set_eq(funnydijkstra_sql, dijkstra_sql, funnydijkstra_sql);


inner_sql := 'SELECT id, source, target, cost FROM edge_table';
dijkstra_sql := 'SELECT * FROM pgr_dijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
|| ', false)';

funnydijkstra_sql := 'SELECT * FROM pgr_funnydijkstra($$' || inner_sql || '$$, ' || i || ', ' || j
|| ', false)';
RETURN query SELECT set_eq(funnydijkstra_sql, dijkstra_sql, funnydijkstra_sql);


END LOOP;
END LOOP;

RETURN;
END
$BODY$
language plpgsql;

SELECT * from funnydijkstra_compare_dijkstra();


SELECT * FROM finish();
ROLLBACK;

21 changes: 21 additions & 0 deletions pgtap/funnyDijkstra/funnyDijkstra-innerQuery.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
\i setup.sql

SELECT plan(137);
SET client_min_messages TO ERROR;


SELECT has_function('pgr_funnydijkstra',
ARRAY['text', 'bigint', 'bigint', 'boolean','boolean']);

SELECT function_returns('pgr_funnydijkstra',
ARRAY['text', 'bigint', 'bigint', 'boolean','boolean'],
'setof record');

SELECT style_dijkstra('pgr_funnydijkstra', ', 2, 3)');
SELECT style_dijkstra('pgr_funnydijkstra', ', 2, 3, true)');
SELECT style_dijkstra('pgr_funnydijkstra', ', 2, 3, false)');



SELECT finish();
ROLLBACK;
15 changes: 15 additions & 0 deletions pgtap/funnyDijkstra/funnyDijkstra-typesCheck.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

SELECT plan(4);

SELECT has_function('pgr_funnydijkstra');

SELECT has_function('pgr_funnydijkstra', ARRAY[ 'text', 'bigint', 'bigint', 'boolean', 'boolean' ]);

SELECT function_returns('pgr_funnydijkstra', ARRAY[ 'text', 'bigint', 'bigint', 'boolean', 'boolean' ], 'setof record');

-- testing column names
SELECT bag_has(
$$SELECT proargnames from pg_proc where proname = 'pgr_funnydijkstra'$$,
$$SELECT '{"","","","directed","only_cost","seq","path_seq","node","edge","cost","agg_cost"}'::TEXT[] $$
);

13 changes: 13 additions & 0 deletions sql/funnyDijkstra/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

SET(LOCAL_FILES
funnyDijkstra.sql
)

# Do not modify bellow this line

foreach (f ${LOCAL_FILES})
configure_file(${f} ${f})
list(APPEND PACKAGE_SQL_FILES ${CMAKE_CURRENT_BINARY_DIR}/${f})
endforeach()

set(PgRouting_SQL_FILES ${PgRouting_SQL_FILES} ${PACKAGE_SQL_FILES} PARENT_SCOPE)
Loading