Skip to content

Commit cfc8f92

Browse files
authored
Merge pull request #2956 from wifiBlack/new-function-king-ordering
New function king ordering
2 parents 4275f2c + e3097cd commit cfc8f92

29 files changed

+1377
-44
lines changed

NEWS.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ Summary of changes by function
138138
* pgr_edwardMoore
139139

140140
* Output columns standardized to ``(seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)``
141+
.. rubric:: Version 3.2.0
142+
* New experimental signature:
143+
* pgr_edwardMoore(Combinations)
144+
.. rubric:: Version 3.0.0
145+
* New experimental function.
146+
147+
* pgr_kingOrdering
148+
149+
* New experimental function.
141150

142151
* pgr_KSP
143152

@@ -298,6 +307,10 @@ New experimental functions
298307

299308
* [#2951](https://github.com/pgRouting/pgrouting/issues/2951): pgr_bandwidth
300309

310+
* Ordering
311+
312+
* [#2954](https://github.com/pgRouting/pgrouting/issues/2954): pgr_kingOrdering
313+
301314
SQL signatures and output standardization
302315

303316
[#2904](https://github.com/pgRouting/pgrouting/issues/2904): Standardize output columns of functions with different output

doc/_static/page_history.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ var titles = [
1515

1616

1717
var newpages = [
18-
{v: '4.0', pages: ['pgr_bandwidth']},
18+
{v: '4.0', pages: ['pgr_bandwidth', 'pgr_kingOrdering']},
19+
1920
{v: '3.8', pages: ['pgr_contractionDeadEnd', 'pgr_contractionLinear', 'pgr_separateCrossing',
2021
'pgr_separateTouching']},
2122

doc/ordering/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ SET(LOCAL_FILES
22
ordering-family.rst
33
pgr_cuthillMckeeOrdering.rst
44
pgr_topologicalSort.rst
5+
pgr_kingOrdering.rst
56
)
67

78
foreach (f ${LOCAL_FILES})

doc/ordering/ordering-family.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Ordering - Family of functions
2424
* :doc:`pgr_cuthillMckeeOrdering` - Return reverse Cuthill-McKee ordering of an undirected graph.
2525
* :doc:`pgr_topologicalSort` - Linear ordering of the vertices for directed
2626
acyclic graph.
27+
* :doc:`pgr_kingOrdering` - Returns the King ordering of an undirected graphs
28+
acyclic graph.
2729

2830
.. official-end
2931
@@ -32,6 +34,7 @@ Ordering - Family of functions
3234

3335
pgr_cuthillMckeeOrdering
3436
pgr_topologicalSort
37+
pgr_kingOrdering
3538

3639
See Also
3740
-------------------------------------------------------------------------------

doc/ordering/pgr_cuthillMckeeOrdering.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ Edges SQL
9494
Result columns
9595
-------------------------------------------------------------------------------
9696

97+
.. node_ordering_start
98+
9799
Returns set of ``(seq, node)``
98100

99101
=============== =========== ======================================
@@ -103,6 +105,8 @@ Column Type Description
103105
``node`` ``BIGINT`` New ordering in reverse order.
104106
=============== =========== ======================================
105107

108+
.. node_ordering_end
109+
106110
See Also
107111
-------------------------------------------------------------------------------
108112

doc/ordering/pgr_kingOrdering.rst

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
..
2+
****************************************************************************
3+
pgRouting Manual
4+
Copyright(c) pgRouting Contributors
5+
6+
This documentation is licensed under a Creative Commons Attribution-Share
7+
Alike 3.0 License: http://creativecommons.org/licenses/by-sa/3.0/
8+
****************************************************************************
9+
10+
.. index::
11+
single: Ordering Family ; pgr_kingOrdering
12+
single: kingOrdering - Experimental on v4.0
13+
14+
|
15+
16+
``pgr_kingOrdering`` - Experimental
17+
===============================================================================
18+
19+
``pgr_kingOrdering`` — Returns the King ordering of an undirected graphs
20+
21+
.. include:: experimental.rst
22+
:start-after: warning-begin
23+
:end-before: end-warning
24+
25+
.. rubric:: Version 4.0.0
26+
27+
* New experimental function.
28+
29+
Description
30+
-------------------------------------------------------------------------------
31+
32+
In numerical linear algebra and graph theory, the King ordering algorithm
33+
is a heuristic designed to reorder the vertices of a graph so as to reduce
34+
its bandwidth.
35+
36+
The method follows a breadth-first search (BFS) traversal,but with a refinement:
37+
at each step, the unvisited neighbors of the current vertex are inserted into
38+
the queue in ascending order of their pseudo-degree, where the pseudo-degree of
39+
a vertex is the number of edges connecting it to yet-unvisited vertices. This
40+
prioritization often yields a smaller bandwidth compared to simpler BFS orderings.
41+
42+
**The main characteristics are:**
43+
44+
- The implementation targets undirected graphs.
45+
- Bandwidth minimization is an NP-complete problem; King ordering provides a practical local minimization approach.
46+
- The time complexity is: :math:`O(m^2 \log(m)|E|)`
47+
48+
- where :math:`|E|` is the number of edges,
49+
- :math:`m` is the maximum degree among all vertices.
50+
51+
|Boost| Boost Graph Inside
52+
53+
Signatures
54+
------------------------------------------------------------------------------
55+
56+
.. index::
57+
single: kingOrdering - Experimental on v4.0
58+
59+
.. admonition:: \ \
60+
:class: signatures
61+
62+
| pgr_kingOrdering(`Edges SQL`_)
63+
64+
| Returns set of |result_node_order|
65+
| OR EMPTY SET
66+
67+
:Example: Graph ordering of pgRouting :doc:`sampledata`
68+
69+
.. literalinclude:: kingOrdering.queries
70+
:start-after: -- q1
71+
:end-before: -- q2
72+
73+
Parameters
74+
-------------------------------------------------------------------------------
75+
76+
.. include:: pgRouting-concepts.rst
77+
:start-after: only_edge_param_start
78+
:end-before: only_edge_param_end
79+
80+
Inner Queries
81+
-------------------------------------------------------------------------------
82+
83+
Edges SQL
84+
...............................................................................
85+
86+
.. include:: pgRouting-concepts.rst
87+
:start-after: basic_edges_sql_start
88+
:end-before: basic_edges_sql_end
89+
90+
Result columns
91+
-------------------------------------------------------------------------------
92+
93+
.. include:: pgr_cuthillMckeeOrdering.rst
94+
:start-after: node_ordering_start
95+
:end-before: node_ordering_end
96+
97+
Additional Examples
98+
-------------------------------------------------------------------------------
99+
100+
.. graphviz::
101+
102+
graph G {
103+
node [shape=circle, style=filled, fillcolor=white, color=black, fontcolor=black, fontsize=10];
104+
edge [color=black, penwidth=1];
105+
106+
4 -- 7;
107+
7 -- 9;
108+
7 -- 0;
109+
0 -- 2;
110+
2 -- 5;
111+
5 -- 9;
112+
9 -- 8;
113+
9 -- 1;
114+
5 -- 1;
115+
9 -- 6;
116+
6 -- 3;
117+
1 -- 3;
118+
119+
{rank=same; 4; 8; 6;}
120+
{rank=same; 7; 9; 3;}
121+
{rank=same; 0; 2; 5; 1;}
122+
}
123+
124+
.. literalinclude:: kingOrdering.queries
125+
:start-after: -- q2
126+
:end-before: -- q3
127+
128+
See Also
129+
-------------------------------------------------------------------------------
130+
131+
* :doc:`sampledata`
132+
* `Boost: King Ordering
133+
<https://www.boost.org/libs/graph/doc/king_ordering.html>`__
134+
135+
.. rubric:: Indices and tables
136+
137+
* :ref:`genindex`
138+
* :ref:`search`
139+

doc/src/pgRouting-introduction.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ This Release Contributors
6666
Individuals in this release v4.0.0 (in alphabetical order)
6767
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6868

69+
Fan Wu
6970
Regina Obe,
7071
Saloni kumari,
7172
Vicky Vergara
@@ -119,6 +120,7 @@ David Techer,
119120
Denis Rykov,
120121
Ema Miyawaki,
121122
Esteban Zimanyi,
123+
Fan Wu,
122124
Florian Thurkow,
123125
Frederic Junod,
124126
Gerald Fenoy,

doc/src/release_notes.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,13 @@ Summary of changes by function
212212

213213
.. include:: pgr_edwardMoore.rst
214214
:start-after: Version 4.0.0
215-
:end-before: .. rubric
215+
:end-before: Description
216+
217+
* pgr_kingOrdering
218+
219+
.. include:: pgr_kingOrdering.rst
220+
:start-after: Version 4.0.0
221+
:end-before: Description
216222

217223
* pgr_KSP
218224

@@ -354,6 +360,10 @@ New experimental functions
354360

355361
* :issue:`2951`: pgr_bandwidth
356362

363+
* Ordering
364+
365+
* :issue:`2954`: pgr_kingOrdering
366+
357367
SQL signatures and output standardization
358368
...............................................................................
359369

docqueries/ordering/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
SET(LOCAL_FILES
33
cuthillMckeeOrdering
44
topologicalSort
5+
kingOrdering
56
)
67

78
foreach (f ${LOCAL_FILES})
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
-- CopyRight(c) pgRouting developers
2+
-- Creative Commons Attribution-Share Alike 3.0 License : https://creativecommons.org/licenses/by-sa/3.0/
3+
/* -- q1 */
4+
SELECT * FROM pgr_kingOrdering(
5+
'SELECT id, source, target, cost, reverse_cost FROM edges'
6+
);
7+
8+
/* -- q2 */
9+
CREATE TABLE additional_sample_1(
10+
id SERIAL PRIMARY KEY,
11+
source INTEGER,
12+
target INTEGER,
13+
cost DOUBLE PRECISION,
14+
reverse_cost DOUBLE PRECISION
15+
);
16+
17+
INSERT INTO additional_sample_1 (source, target, cost, reverse_cost) VALUES
18+
(4, 7, 1, 1),
19+
(7, 4, 1, 1),
20+
(7, 9, 1, 1),
21+
(9, 7, 1, 1),
22+
(7, 0, 1, 1),
23+
(0, 7, 1, 1),
24+
(0, 2, 1, 1),
25+
(2, 0, 1, 1),
26+
(2, 5, 1, 1),
27+
(5, 2, 1, 1),
28+
(5, 9, 1, 1),
29+
(9, 5, 1, 1),
30+
(9, 8, 1, 1),
31+
(8, 9, 1, 1),
32+
(9, 1, 1, 1),
33+
(1, 9, 1, 1),
34+
(5, 1, 1, 1),
35+
(1, 5, 1, 1),
36+
(9, 6, 1, 1),
37+
(6, 9, 1, 1),
38+
(6, 3, 1, 1),
39+
(3, 6, 1, 1),
40+
(1, 3, 1, 1),
41+
(3, 1, 1, 1);
42+
43+
SELECT * FROM pgr_kingOrdering(
44+
'SELECT id, source, target, cost, reverse_cost FROM additional_sample_1'
45+
);
46+
47+
/* -- q3 */

0 commit comments

Comments
 (0)