Skip to content

New function pgr contraction linear #2794

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
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 NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* Contraction

* [#2790](https://github.com/pgRouting/pgrouting/issues/2790): pgr_contractionDeadEnd
* [#2791](https://github.com/pgRouting/pgrouting/issues/2791): pgr_contractionLinear

## pgRouting 3.7

Expand Down
2 changes: 1 addition & 1 deletion doc/_static/page_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var titles = [


var newpages = [
{v: '3.8', pages: ['pgr_contractionDeadEnd']},
{v: '3.8', pages: ['pgr_contractionDeadEnd', 'pgr_contractionLinear']},

{v: '3.7', pages: ['metrics-family', 'pgr_betweennessCentrality']},

Expand Down
1 change: 1 addition & 0 deletions doc/contraction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SET(LOCAL_FILES
contraction-family.rst
pgr_contraction.rst
pgr_contractionDeadEnd.rst
pgr_contractionLinear.rst
)

foreach (f ${LOCAL_FILES})
Expand Down
165 changes: 1 addition & 164 deletions doc/contraction/contraction-family.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Contraction - Family of functions

pgr_contraction
pgr_contractionDeadEnd
pgr_contractionLinear


Introduction
Expand All @@ -59,173 +60,9 @@ Allowing the user to:
- Decide the order of the contraction algorithms and set the maximum number of
times they are to be executed.

Linear contraction
-------------------------------------------------------------------------------
In the algorithm, linear contraction is represented by 2.

Linear
................................................................................

In case of an undirected graph, a node is considered a `linear` node when

* The number of adjacent vertices is 2.

In case of a directed graph, a node is considered a `linear` node when

* The number of adjacent vertices is 2.
* Linearity is symmetrical

Linear vertex on undirected graph
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

- The green nodes are `linear`_ nodes
- The blue nodes have an unlimited number of incoming and outgoing edges.


.. rubric:: Undirected

.. graphviz::

graph G {
u, w [shape=circle;style=filled;width=.4;color=deepskyblue];
v [style=filled; color=green];
G [shape=tripleoctagon;width=1.5;style=filled;
color=deepskyblue;label = "Rest of the Graph"];

rankdir=LR;
w -- G -- u [dir=none, weight=1, penwidth=3];
u -- v -- w;
}

.. list-table::
:width: 80
:widths: auto
:header-rows: 1

* - Node
- Adjacent nodes
- Number of adjacent nodes
* - :math:`v`
- :math:`\{u, w\}`
- 2

Linear vertex on directed graph
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

- The green nodes are `linear`_ nodes
- The blue nodes have an unlimited number of incoming and outgoing edges.
- The white node is not linear because the linearity is not symmetrical.

* It is possible to go :math:`y \rightarrow c \rightarrow z`
* It's not possible to go :math:`z \rightarrow c \rightarrow y`

.. graphviz::

digraph G {
u, v, w, x, y, z [shape=circle;style=filled;width=.4;color=deepskyblue];
a, b [style=filled; color=green];
G [shape=tripleoctagon;width=1.5;style=filled;
color=deepskyblue;label = "Rest of the Graph"];

rankdir=LR;
{u, v} -> G -> {x, w, y, z} [dir=none, weight=1, penwidth=3];
u -> a -> v;
w -> b -> x;
x -> b -> w [color=darkgray];
y -> c -> z -> c;
}

.. list-table::
:width: 80
:widths: auto
:header-rows: 1

* - Node
- Adjacent nodes
- Number of adjacent nodes
- Is symmetrical?
* - :math:`a`
- :math:`\{u, v\}`
- 2
- yes
* - :math:`b`
- :math:`\{w, x\}`
- 2
- yes
* - :math:`c`
- :math:`\{y, z\}`
- 2
- no

Operation: Linear Contraction
...............................................................................

The linear contraction will stop when there are no more linear nodes.
For example from the following graph where :math:`v` and :math:`w` are `linear`_
nodes:

.. graphviz::

digraph G {
u, z [shape=circle;style=filled;color=deepskyblue];
v, w [style=filled; color=green];
"G" [shape=tripleoctagon; style=filled;
color=deepskyblue;label = "Rest of the Graph"];

rankdir=LR;
G -> {u, z} [dir=none, weight=1, penwidth=3];
u -> v -> w -> z;
}

Contracting :math:`w`,

* The vertex :math:`w` is removed from the graph
* The edges :math:`v \rightarrow w` and :math:`w \rightarrow z` are removed
from the graph.
* A new edge :math:`v \rightarrow z` is inserted represented with red color.

.. graphviz::

digraph G {
u, z [shape=circle;style=filled;color=deepskyblue];
v [style=filled; color=green];
"G" [shape=tripleoctagon; style=filled;
color=deepskyblue;label = "Rest of the Graph"];

rankdir=LR;
G -> {u, z} [dir=none, weight=1, penwidth=3];
u -> v;
v -> z [label="{w}";color=red]
}

Contracting :math:`v`:

* The vertex :math:`v` is removed from the graph
* The edges :math:`u \rightarrow v` and :math:`v \rightarrow z` are removed
from the graph.
* A new edge :math:`u \rightarrow z` is inserted represented with red color.


.. graphviz::

digraph G {
u, z [shape=circle;style=filled;color=deepskyblue];
"G" [shape=tripleoctagon; style=filled;
color=deepskyblue;label = "Rest of the Graph"];

rankdir=LR;
G -> {u, z} [dir=none, weight=1, penwidth=3];
u -> z [label="{v, w}";color=red]
}

Edge :math:`u \rightarrow z` has the information of nodes that were contracted.


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

* :doc:`pgr_contraction`
* :doc:`sampledata`
* https://www.cs.cmu.edu/afs/cs/academic/class/15210-f12/www/lectures/lecture16.pdf
* https://algo2.iti.kit.edu/documents/routeplanning/geisberger_dipl.pdf

Expand Down
2 changes: 1 addition & 1 deletion doc/contraction/pgr_contraction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The main Characteristics are:
function:

- Dead End Contraction. See :doc:`pgr_contractionDeadEnd`.
- Linear Contraction. See :doc:`contraction-family`.
- Linear Contraction. See :doc:`pgr_contractionLinear`.

|Boost| Boost Graph Inside

Expand Down
Loading