Skip to content
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

Traversal doc refine #2283

Merged
merged 7 commits into from
May 5, 2022
Merged
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
4 changes: 2 additions & 2 deletions doc/breadthFirstSearch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

SET(LOCAL_FILES
pgr_breadthFirstSearch.rst
pgr_binaryBreadthFirstSearch.rst
pgr_binaryBreadthFirstSearch.rst
)

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

add_subdirectory("images")
set(PROJECT_DOC_FILES ${PROJECT_DOC_FILES} ${LOCAL_DOC_FILES} PARENT_SCOPE)

11 changes: 11 additions & 0 deletions doc/breadthFirstSearch/images/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SET(LOCAL_FILES
bfs-descending.png
bfs-ascending.png
)

foreach (f ${LOCAL_FILES})
configure_file(${f} "${PGR_DOCUMENTATION_SOURCE_DIR}/images/${f}" COPYONLY)
list(APPEND LOCAL_IMG_FILES "${PGR_DOCUMENTATION_SOURCE_DIR}/images/${f}")
endforeach()

set(PROJECT_IMG_FILES ${PROJECT_IMG_FILES} ${LOCAL_IMG_FILES} PARENT_SCOPE)
Binary file added doc/breadthFirstSearch/images/bfs-ascending.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/breadthFirstSearch/images/bfs-descending.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 39 additions & 65 deletions doc/breadthFirstSearch/pgr_binaryBreadthFirstSearch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
===============================================================================

``pgr_binaryBreadthFirstSearch`` — Returns the shortest path(s) in a binary graph.
Any graph whose edge-weights belongs to the set {0,X}, where 'X' is any
non-negative real integer, is termed as a 'binary graph'.

Any graph whose edge-weights belongs to the set {0,X}, where 'X' is any
non-negative integer, is termed as a 'binary graph'.

.. figure:: images/boost-inside.jpeg
:target: https://www.boost.org/libs/graph/doc/breadth_first_search.html
Expand All @@ -41,7 +42,7 @@ non-negative real integer, is termed as a 'binary graph'.
* Version 3.0.0

* New **experimental** signatures:

* pgr_binaryBreadthFirstSearch(`One to One`_)
* pgr_binaryBreadthFirstSearch(`One to Many`_)
* pgr_binaryBreadthFirstSearch(`Many to One`_)
Expand All @@ -50,24 +51,24 @@ non-negative real integer, is termed as a 'binary graph'.
Description
-------------------------------------------------------------------------------

It is well-known that the shortest paths between a single source and all other
vertices can be found using Breadth First Search in :math:`O(|E|)` in an
It is well-known that the shortest paths between a single source and all other
vertices can be found using Breadth First Search in :math:`O(|E|)` in an
unweighted graph, i.e. the distance is the minimal number of edges that you
need to traverse from the source to another vertex. We can interpret such a
graph also as a weighted graph, where every edge has the weight :math:`1`. If
need to traverse from the source to another vertex. We can interpret such a
graph also as a weighted graph, where every edge has the weight :math:`1`. If
not alledges in graph have the same weight, that we need a more general algorithm,
like Dijkstra's Algorithm which runs in :math:`O(|E|log|V|)` time.

However if the weights are more constrained, we can use a faster algorithm.
This algorithm, termed as 'Binary Breadth First Search' as well as '0-1 BFS',
is a variation of the standard Breadth First Search problem to solve the
is a variation of the standard Breadth First Search problem to solve the
SSSP (single-source shortest path) problem in :math:`O(|E|)`, if the weights
of each edge belongs to the set {0,X}, where 'X' is any non-negative real integer.


**The main Characteristics are:**

* Process is done only on 'binary graphs'. ('Binary Graph': Any graph whose
* Process is done only on 'binary graphs'. ('Binary Graph': Any graph whose
edge-weights belongs to the set {0,X}, where 'X' is any non-negative real integer.)
* For optimization purposes, any duplicated value in the `start_vids` or `end_vids`
are ignored.
Expand All @@ -83,7 +84,7 @@ Signatures

.. rubric:: Summary

.. parsed-literal::
.. parsed-literal::

pgr_binaryBreadthFirstSearch(`Edges SQL`_, **start vid**, **end vid** [, directed])
pgr_binaryBreadthFirstSearch(`Edges SQL`_, **start vid**, **end vids** [, directed])
Expand All @@ -101,17 +102,17 @@ Signatures
One to One
...............................................................................

.. parsed-literal::
.. parsed-literal::

pgr_binaryBreadthFirstSearch(`Edges SQL`_, **start vid**, **end vid** [, directed]);
RETURNS SET OF (seq, path_seq, node, edge, cost, agg_cost)
OR EMPTY SET

:Example: From vertex :math:`2` to vertex :math:`3` on an **directed** binary graph
:Example: From vertex :math:`2` to vertex :math:`3` on a **directed** graph

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

.. index::
single: binaryBreadthFirstSearch(One to Many) - Experimental on v3.0
Expand All @@ -125,74 +126,76 @@ One to many
RETURNS SET OF (seq, path_seq, end_vid, node, edge, cost, agg_cost)
OR EMPTY SET

:Example: From vertex :math:`2` to vertices :math:`\{3, 5\}` on an **undirected** binary graph
:Example: From vertex :math:`2` to vertices :math:`\{3, 12\}` on a **directed**
graph

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

.. index::
single: binaryBreadthFirstSearch(Many to One) - Experimental on v3.0

Many to One
...............................................................................

.. parsed-literal::
.. parsed-literal::

pgr_binaryBreadthFirstSearch(`Edges SQL`_, **start vids**, **end vid** [, directed]);
RETURNS SET OF (seq, path_seq, start_vid, node, edge, cost, agg_cost)
OR EMPTY SET

:Example: From vertices :math:`\{2, 11\}` to vertex :math:`5` on a **directed** binary graph
:Example: From vertices :math:`\{2, 7\}` to vertex :math:`12` on a **directed**
graph

.. literalinclude:: doc-pgr_binaryBreadthFirstSearch.queries
:start-after: -- q4
:end-before: -- q5
:start-after: -- q3
:end-before: -- q4

.. index::
single: binaryBreadthFirstSearch(Many to Many) - Experimental on v3.0

Many to Many
...............................................................................

.. parsed-literal::
.. parsed-literal::

pgr_binaryBreadthFirstSearch(`Edges SQL`_, **start vids**, **end vids** [, directed]);
RETURNS SET OF (seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
OR EMPTY SET

:Example: From vertices :math:`\{2, 11\}` to vertices :math:`\{3, 5\}` on an **undirected**
binary graph
:Example: From vertices :math:`\{2, 7\}` to vertices :math:`\{3, 12\}` on an
**undirected** graph

.. literalinclude:: doc-pgr_binaryBreadthFirstSearch.queries
:start-after: -- q5
:end-before: -- q51
:start-after: -- q4
:end-before: -- q5

.. index::
single: binaryBreadthFirstSearch(Combinations) - Experimental on v3.2

Combinations
...............................................................................

.. parsed-literal::
.. parsed-literal::

pgr_binaryBreadthFirstSearch(`Edges SQL`_, `Combinations SQL`_ [, directed]);
RETURNS SET OF (seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
OR EMPTY SET

:Example: Using a combinations table on an **undirected** binary graph.
:Example: Using a combinations table on an **undirected** graph

The combinations table:

.. literalinclude:: doc-pgr_bellmanFord.queries
:start-after: -- q51
:end-before: -- q6
.. literalinclude:: doc-pgr_binaryBreadthFirstSearch.queries
:start-after: -- q5
:end-before: -- q51

The query:

.. literalinclude:: doc-pgr_binaryBreadthFirstSearch.queries
:start-after: -- q6
:end-before: -- q7
:start-after: -- q51
:end-before: -- q6

Parameters
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -233,43 +236,14 @@ Return Columns
:end-before: return_path_end


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

Edwards-Moore Algorithm is best applied when trying to answer queries such as the following:
**“Find the path with the minimum number from Source to Destination”**
Here:
* *Source* = Source Vertex, *Destination* = Any arbitrary destination vertex
* *X* is an event/property
* Each edge in the graph is either “*X*” or “*Not X*” .

Example:
“Find the path with the minimum number of road works from Source to Destination”

Here, a road under work(aka **road works**) means that part of the road is occupied for
construction work/maintenance.

Here:
* Edge ( *u* , *v* ) has weight = 0 if no road work is ongoing on the road from *u* to *v*.
* Edge ( *u*, *v*) has weight = 1 if road work is ongoing on the road from *u* to *v*.

Then, upon running the algorithm, we obtain the path with the minimum number of road works
from the given source and destination.

Table Data
...............................................................................

The Additional Examples use the following tabel Data.

.. literalinclude:: doc-pgr_binaryBreadthFirstSearch.queries
:start-after: --data-start
:end-before: --data-end

:Examples:
:Example: Manually assigned vertex combinations.

.. literalinclude:: doc-pgr_binaryBreadthFirstSearch.queries
:start-after: -- q7
:end-before: -- q8
:start-after: -- q6
:end-before: -- q7

See Also
-------------------------------------------------------------------------------
Expand Down
Loading